-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathRAM.pm
executable file
·303 lines (216 loc) · 5.9 KB
/
RAM.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
############################
package SQL::Statement::RAM;
############################
######################################################################
#
# This module is copyright (c), 2001,2005 by Jeff Zucker.
# This module is copyright (c), 2007-2020 by Jens Rehsack.
# All rights reserved.
#
# It may be freely distributed under the same terms as Perl itself.
# See below for help and copyright information (search for SYNOPSIS).
#
######################################################################
use strict;
use warnings FATAL => "all";
use vars qw($VERSION);
$VERSION = '1.414';
####################################
package SQL::Statement::RAM::Table;
####################################
use strict;
use warnings FATAL => "all";
use SQL::Eval ();
use vars qw(@ISA);
@ISA = qw(SQL::Eval::Table);
use Carp qw(croak);
sub new
{
my ( $class, $tname, $col_names, $data_tbl ) = @_;
my %table = (
NAME => $tname,
index => 0,
records => $data_tbl,
col_names => $col_names,
capabilities => {
inplace_update => 1,
inplace_delete => 1,
},
);
my $self = $class->SUPER::new( \%table );
}
##################################
# fetch_row()
##################################
sub fetch_row
{
my ( $self, $data ) = @_;
return $self->{row} =
( $self->{records} and ( $self->{index} < scalar( @{ $self->{records} } ) ) )
? [ @{ $self->{records}->[ $self->{index}++ ] } ]
: undef;
}
####################################
# insert_new_row()
####################################
sub insert_new_row
{
my ( $self, $data, $fields ) = @_;
push @{ $self->{records} }, [ @{$fields} ];
return 1;
}
##################################
# delete_current_row()
##################################
sub delete_current_row
{
my ( $self, $data, $fields ) = @_;
my $currentRow = $self->{index} - 1;
croak "No current row" unless ( $currentRow >= 0 );
splice @{ $self->{records} }, $currentRow, 1;
--$self->{index};
return 1;
}
##################################
# update_current_row()
##################################
sub update_current_row
{
my ( $self, $data, $fields ) = @_;
my $currentRow = $self->{index} - 1;
croak "No current row" unless ( $currentRow >= 0 );
$self->{records}->[$currentRow] = [ @{$fields} ];
return 1;
}
##################################
# truncate()
##################################
sub truncate
{
return splice @{ $_[0]->{records} }, $_[0]->{index};
}
#####################################
# push_names()
#####################################
sub push_names
{
my ( $self, $data, $names ) = @_;
$self->{col_names} = $names;
$self->{org_col_names} = [ @{$names} ];
$self->{col_nums} = SQL::Eval::Table::_map_colnums($names);
}
#####################################
# drop()
#####################################
sub drop
{
my ( $self, $data ) = @_;
my $tname = $self->{NAME};
delete $data->{Database}->{sql_ram_tables}->{$tname};
return 1;
}
#####################################
# seek()
#####################################
sub seek
{
my ( $self, $data, $pos, $whence ) = @_;
return unless defined $self->{records};
my ($currentRow) = $self->{index};
if ( $whence == 0 )
{
$currentRow = $pos;
}
elsif ( $whence == 1 )
{
$currentRow += $pos;
}
elsif ( $whence == 2 )
{
$currentRow = @{ $self->{records} } + $pos;
}
else
{
croak $self . "->seek: Illegal whence argument ($whence)";
}
if ( $currentRow < 0 )
{
croak "Illegal row number: $currentRow";
}
$self->{index} = $currentRow;
}
1;
=pod
=head1 NAME
SQL::Statement::RAM
=head1 SYNOPSIS
SQL::Statement::RAM
=head1 DESCRIPTION
This package contains support for the internally used
SQL::Statement::RAM::Table.
=head1 INHERITANCE
SQL::Statement::RAM
SQL::Statement::RAM::Table
ISA SQL::Eval::Table
=head1 SQL::Statement::RAM::Table
=head2 METHODS
=over 8
=item new
Instantiates a new C<SQL::Statement::RAM::Table> object, used for temporary
tables.
CREATE TEMP TABLE foo ....
=item fetch_row
Fetches the next row
=item push_row
As fetch_row except for writing
=item delete_current_row
Deletes the last fetched/pushed row
=item update_current_row
Updates the last fetched/pushed row
=item truncate
Truncates the table at the current position
=item push_names
Set the column names of the table
=item drop
Discards the table
=item seek
Seek the row pointer
=back
=head2 CAPABILITIES
This table has following capabilities:
=over 8
=item update_current_row
Using provided method C<update_current_row> and capability C<inplace_update>.
=item rowwise_update
By providing capability C<update_current_row>.
=item inplace_update
By definition (appropriate flag set in constructor).
=item delete_current_row
Using provided method C<delete_current_row> and capability C<inplace_delete>.
=item rowwise_delete
By providing capability C<delete_current_row>.
=item inplace_delete
By definition (appropriate flag set in constructor).
=back
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc SQL::Statement
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SQL-Statement>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/SQL-Statement>
=item * CPAN Ratings
L<http://cpanratings.perl.org/s/SQL-Statement>
=item * Search CPAN
L<http://search.cpan.org/dist/SQL-Statement/>
=back
=head1 AUTHOR AND COPYRIGHT
Copyright (c) 2001,2005 by Jeff Zucker: jzuckerATcpan.org
Copyright (c) 2007-2020 by Jens Rehsack: rehsackATcpan.org
All rights reserved.
You may distribute this module under the terms of either the GNU
General Public License or the Artistic License, as specified in
the Perl README file.
=cut