| 1 | # | ||
| 2 | # Copyright (c) 2005, Presicient Corp., USA | ||
| 3 | # | ||
| 4 | # Permission is granted to use this software according to the terms of the | ||
| 5 | # Artistic License, as specified in the Perl README file, | ||
| 6 | # with the exception that commercial redistribution, either | ||
| 7 | # electronic or via physical media, as either a standalone package, | ||
| 8 | # or incorporated into a third party product, requires prior | ||
| 9 | # written approval of the author. | ||
| 10 | # | ||
| 11 | # This software is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| 14 | # | ||
| 15 | # Presicient Corp. reserves the right to provide support for this software | ||
| 16 | # to individual sites under a separate (possibly fee-based) | ||
| 17 | # agreement. | ||
| 18 | # | ||
| 19 | # History: | ||
| 20 | # | ||
| 21 | # 2005-Jan-27 D. Arnold | ||
| 22 | # Coded. | ||
| 23 | # | ||
| 24 | package SQL::Amazon::Spool; | ||
| 25 | |||
| 26 | use base qw(SQL::Eval::Table); | ||
| 27 | use strict; | ||
| 28 | |||
| 29 | our $engine; | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | my ($class, $table, $reqids) = @_; | ||
| 33 | my $keys = $table->fetch_all($reqids); | ||
| 34 | my $metadata = $table->get_metadata(); | ||
| 35 | my $timeout = time() + $table->get_time_limit(); | ||
| 36 | my $obj = { | ||
| 37 | _keys => $keys, | ||
| 38 | _timeout => $timeout, | ||
| 39 | _table => $table, | ||
| 40 | _reqids => $reqids, | ||
| 41 | NAME => $table->name, | ||
| 42 | TYPE => $metadata->{TYPE}, | ||
| 43 | PRECISION => $metadata->{PRECISION}, | ||
| 44 | SCALE => $metadata->{SCALE}, | ||
| 45 | NULLABLE => $metadata->{NULLABLE}, | ||
| 46 | col_names => $metadata->{NAME}, | ||
| 47 | }; | ||
| 48 | |||
| 49 | my %colnums = (); | ||
| 50 | $colnums{$obj->{col_names}[$_]} = $_ | ||
| 51 | foreach (0..$#{$obj->{col_names}}); | ||
| 52 | |||
| 53 | $obj->{col_nums} = \%colnums; | ||
| 54 | |||
| 55 | return $class->SUPER::new($obj); | ||
| 56 | } | ||
| 57 | |||
| 58 | sub is_readonly { return 1; } | ||
| 59 | |||
| 60 | sub trim { | ||
| 61 | my $x = shift; | ||
| 62 | $x =~ s/^\s+//; | ||
| 63 | $x =~ s/\s+$//; | ||
| 64 | $x; | ||
| 65 | } | ||
| 66 | sub get_metadata { | ||
| 67 | my $obj = shift; | ||
| 68 | |||
| 69 | return ($obj->{NAME}, | ||
| 70 | $obj->{TYPE}, | ||
| 71 | $obj->{PRECISION}, | ||
| 72 | $obj->{SCALE}, | ||
| 73 | $obj->{NULLABLE}); | ||
| 74 | } | ||
| 75 | sub row { | ||
| 76 | my $obj = shift; | ||
| 77 | return $obj->{_currkey} ? | ||
| 78 | $obj->{_table}->fetch($obj->{_currkey}) : | ||
| 79 | undef; | ||
| 80 | } | ||
| 81 | |||
| 82 | sub fetch_row ($$) { | ||
| 83 | my($obj, $handle) = @_; | ||
| 84 | $obj->{errstr} = 'Resultset timeout has expired.', | ||
| 85 | $obj->{_keys} = undef, | ||
| 86 | return undef | ||
| 87 | if (time() > $obj->{_timeout}); | ||
| 88 | |||
| 89 | my $cursor = defined($obj->{_cursor}) ? $obj->{_cursor} : -1; | ||
| 90 | my $keys = $obj->{_keys}; | ||
| 91 | return undef | ||
| 92 | if ($cursor >= $#$keys); | ||
| 93 | my $row; | ||
| 94 | $cursor++; | ||
| 95 | while ($cursor <= $#$keys) { | ||
| 96 | $row = $obj->{_table}->fetch($keys->[$cursor]); | ||
| 97 | $obj->{_currkey} = $keys->[$cursor]; | ||
| 98 | last if $row; | ||
| 99 | $cursor++; | ||
| 100 | } | ||
| 101 | |||
| 102 | $obj->{_cursor} = $cursor; | ||
| 103 | $obj->{errstr} = $row, | ||
| 104 | $obj->{row} = undef, | ||
| 105 | $obj->{_currkey} = undef, | ||
| 106 | return undef | ||
| 107 | unless ref $row; | ||
| 108 | |||
| 109 | $obj->{row} = undef, | ||
| 110 | $obj->{_currkey} = undef, | ||
| 111 | return undef | ||
| 112 | unless $row; | ||
| 113 | |||
| 114 | @$row = map( $_ = &trim($_), @$row) | ||
| 115 | if $handle->{Database}{ChopBlanks}; | ||
| 116 | |||
| 117 | $obj->{row} = [ @$row ]; | ||
| 118 | return $obj->{row}; | ||
| 119 | } | ||
| 120 | |||
| 121 | sub push_names ($$$) { | ||
| 122 | my($obj, $data, $names) = @_; | ||
| 123 | |||
| 124 | return undef; | ||
| 125 | } | ||
| 126 | |||
| 127 | sub push_row ($$$) { | ||
| 128 | my($obj, $data, $fields) = @_; | ||
| 129 | |||
| 130 | return undef; | ||
| 131 | } | ||
| 132 | |||
| 133 | sub seek ($$$$) { | ||
| 134 | my($obj, $data, $pos, $whence) = @_; | ||
| 135 | return 1; | ||
| 136 | } | ||
| 137 | |||
| 138 | sub drop ($$) { | ||
| 139 | my($obj, $data) = @_; | ||
| 140 | return undef; | ||
| 141 | } | ||
| 142 | |||
| 143 | sub truncate ($$) { | ||
| 144 | my ($obj, $data) = @_; | ||
| 145 | |||
| 146 | return undef; | ||
| 147 | } | ||
| 148 | sub DESTROY { | ||
| 149 | my $obj = shift; | ||
| 150 | |||
| 151 | undef; | ||
| 152 | } | ||
| 153 | |||
| 154 | 1; | ||
| 155 |