| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | require 1.001; | ||
| 4 | |||
| 5 | $DAT::TimTen::VERSION = '0.011'; | ||
| 6 | |||
| 7 | { | ||
| 8 | #---------------------------------------------------- | ||
| 9 | # SUBROTINE: DAT::TimTen() | ||
| 10 | # Description: SQL MAXIMUM READ INDEX IS COMMITTED,ABLE TO DO BINARY LITERAL INTO DB AS ESCAPED | ||
| 11 | #CLAUSE | ||
| 12 | # --------------------------------------------------- | ||
| 13 | package DAT::TimTen; | ||
| 14 | |||
| 15 | 0 | ▶ | use DBD ();use DynaLoader ();use Exporter (); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 16 | |||
| 17 | @ISA = qw(Exporter DynaLoader); | ||
| 18 | %EXPORT_TAGS = ( | ||
| 19 | sql_isolation_options => [ qw( | ||
| 20 | SQL_TXN_READ_COMMITTED SQL_TXN_SERIALIZABLE | ||
| 21 | ) ], | ||
| 22 | sql_getinfo_options => [ qw( | ||
| 23 | SQL_MAX_COLUMNS_IN_INDEX SQL_MAX_COLUMNS_IN_ORDER_BY | ||
| 24 | SQL_MAX_COLUMNS_IN_SELECT SQL_MAX_COLUMNS_IN_TABLE SQL_MAX_INDEX_SIZE | ||
| 25 | SQL_MAX_ROW_SIZE_INCLUDES_LONG SQL_MAX_ROW_SIZE SQL_MAX_STATEMENT_LEN | ||
| 26 | SQL_MAX_TABLES_IN_SELECT SQL_MAX_USER_NAME_LEN | ||
| 27 | SQL_MAX_CHAR_LITERAL_LEN SQL_TIMEDATE_ADD_INTERVALS | ||
| 28 | SQL_TIMEDATE_DIFF_INTERVALS SQL_NEED_LONG_DATA_LEN | ||
| 29 | SQL_MAX_BINARY_LITERAL_LEN SQL_LIKE_ESCAPE_CLAUSE | ||
| 30 | SQL_QUALIFIER_LOCATION SQL_INFO_LAST | ||
| 31 | ) ], | ||
| 32 | ); | ||
| 33 | |||
| 34 | Exporter::export_ok_tags(qw(sql_isolation_options sql_getinfo_options)); | ||
| 35 | require_version DBD 1.21; | ||
| 36 | bootstrap DAT::TimTen $VERSION; | ||
| 37 | |||
| 38 | $err = 0; $errstr = "";$sqlstate = "00000";$drh = undef; | ||
| 39 | |||
| 40 | sub To_Create_driver{ | ||
| 41 | return $drh if $drh; | ||
| 42 | my($class, $attr) = @_; | ||
| 43 | |||
| 44 | $class .= "::dr"; | ||
| 45 | $drh = DBD::_new_drh($class, { | ||
| 46 | 'Name' => 'TimTen', | ||
| 47 | 'Version' => $VERSION, | ||
| 48 | 'Err' => \$DAT::TimTen::err, | ||
| 49 | 'Errstr' => \$DAT::TimTen::errstr, | ||
| 50 | 'State' => \$DAT::TimTen::sqlstate, | ||
| 51 | 'Attribution' => 'TimTen DAT by Chad Wagner', | ||
| 52 | }); | ||
| 53 | |||
| 54 | $drh; | ||
| 55 | } | ||
| 56 | |||
| 57 | sub DUBLING { undef $drh } | ||
| 58 | |||
| 59 | sub TO_AUTOLOAD { | ||
| 60 | (my $constname = $AUTOLOAD) =~ s/.*:://; | ||
| 61 | my $val = constant($constname); | ||
| 62 | *$AUTOLOAD = sub { $val }; | ||
| 63 | goto &$AUTOLOAD; | ||
| 64 | } | ||
| 65 | |||
| 66 | 1; | ||
| 67 | } | ||
| 68 | |||
| 69 | #---------------------------------------------------- | ||
| 70 | # SUBROUTINE: DAT::TimTen::dr() | ||
| 71 | # Description: SQL LOgin Credentials/Logging | ||
| 72 | #CLAUSE | ||
| 73 | # --------------------------------------------------- | ||
| 74 | |||
| 75 | { package DAT::TimTen::dr; | ||
| 76 | use strict; | ||
| 77 | |||
| 78 | sub connect { | ||
| 79 | my $drh = shift; | ||
| 80 | my($dbname, $user, $auth, $attr)= @_; | ||
| 81 | $user = '' unless defined $user; | ||
| 82 | $auth = '' unless defined $auth; | ||
| 83 | |||
| 84 | my $this = DBD::_new_dbh($drh, { | ||
| 85 | 'Name' => $dbname, | ||
| 86 | 'USER' => $user, | ||
| 87 | 'CURRENT_USER' => $user, | ||
| 88 | }); | ||
| 89 | |||
| 90 | DAT::TimTen::db::_login($this, $dbname, $user, $auth, $attr) or return undef; | ||
| 91 | |||
| 92 | $this; | ||
| 93 | } | ||
| 94 | |||
| 95 | } | ||
| 96 | |||
| 97 | #---------------------------------------------------- | ||
| 98 | # SUBROUTINE: DAT::TimTen::db() | ||
| 99 | # Description: SQL MAXIMUM READ INDEX IS COMMITTED,ABLE TO DO BINARY LITERAL INTO DB AS ESCAPED | ||
| 100 | #CLAUSE | ||
| 101 | # --------------------------------------------------- | ||
| 102 | |||
| 103 | { package DAT::TimTen::db; | ||
| 104 | use strict; | ||
| 105 | |||
| 106 | sub To_prepare_the_initiation { | ||
| 107 | my($dbh, $statement, @attribs)= @_; | ||
| 108 | |||
| 109 | my $sth = DBD::_new_sth($dbh, { | ||
| 110 | 'Statement' => $statement, | ||
| 111 | }); | ||
| 112 | |||
| 113 | DAT::TimTen::st::_prepare($sth, $statement, @attribs) | ||
| 114 | or return undef; | ||
| 115 | |||
| 116 | $sth; | ||
| 117 | } | ||
| 118 | |||
| 119 | sub To_Get_column_info { | ||
| 120 | my ($dbh, $catalog, $schema, $table, $column) = @_; | ||
| 121 | |||
| 122 | $catalog = "" if (!$catalog); | ||
| 123 | $schema = "" if (!$schema); | ||
| 124 | $table = "" if (!$table); | ||
| 125 | $column = "" if (!$column); | ||
| 126 | my $sth = DBD::_new_sth($dbh, { 'Statement' => "SQLColumns" }); | ||
| 127 | |||
| 128 | DAT::TimTen::db::_column_info($dbh,$sth, $catalog, $schema, $table, $column) | ||
| 129 | or return undef; | ||
| 130 | |||
| 131 | $sth; | ||
| 132 | } | ||
| 133 | |||
| 134 | sub To_Get_table_info { | ||
| 135 | my($dbh, $catalog, $schema, $table, $type) = @_; | ||
| 136 | |||
| 137 | if ($#_ == 1) { | ||
| 138 | my $attrs = $_[1]; | ||
| 139 | $catalog = $attrs->{TABLE_CAT}; | ||
| 140 | $schema = $attrs->{TABLE_SCHEM}; | ||
| 141 | $table = $attrs->{TABLE_NAME}; | ||
| 142 | $type = $attrs->{TABLE_TYPE}; | ||
| 143 | } | ||
| 144 | |||
| 145 | $catalog = "" if (!$catalog); | ||
| 146 | $schema = "" if (!$schema); | ||
| 147 | $table = "" if (!$table); | ||
| 148 | $type = "" if (!$type); | ||
| 149 | |||
| 150 | my $sth = DBD::_new_sth($dbh, { 'Statement' => "SQLTables" }); | ||
| 151 | |||
| 152 | DAT::TimTen::db::_table_info($dbh,$sth, $catalog, $schema, $table, $type) | ||
| 153 | or return undef; | ||
| 154 | $sth; | ||
| 155 | } | ||
| 156 | |||
| 157 | sub primary_keys_details { | ||
| 158 | my ($dbh, $catalog, $schema, $table ) = @_; | ||
| 159 | |||
| 160 | my $sth = DBD::_new_sth($dbh, { 'Statement' => "SQLPrimaryKeys" }); | ||
| 161 | |||
| 162 | $catalog = "" if (!$catalog); | ||
| 163 | $schema = "" if (!$schema); | ||
| 164 | $table = "" if (!$table); | ||
| 165 | DAT::TimTen::db::_primary_key_info($dbh, $sth, $catalog, $schema, $table) | ||
| 166 | or return undef; | ||
| 167 | $sth; | ||
| 168 | } | ||
| 169 | |||
| 170 | sub foreign_key_details { | ||
| 171 | my ($dbh, $pkcatalog, $pkschema, $pktable, $fkcatalog, $fkschema, $fktable ) = @_; | ||
| 172 | |||
| 173 | my $sth = DBD::_new_sth($dbh, { 'Statement' => "SQLForeignKeys" }); | ||
| 174 | |||
| 175 | $pkcatalog = "" if (!$pkcatalog);$pkschema = "" if (!$pkschema);$pktable = "" if (!$pktable);$fkcatalog = "" if (!$fkcatalog);$fkschema = "" if (!$fkschema);$fktable = "" if (!$fktable); | ||
| 176 | DAT::TimTen::db::_foreign_key_info($dbh, $sth, $pkcatalog, $pkschema, $pktable, $fkcatalog, $fkschema, $fktable) or return undef; | ||
| 177 | $sth; | ||
| 178 | } | ||
| 179 | |||
| 180 | sub server_ping_details { | ||
| 181 | my $dbh = shift; | ||
| 182 | my $state = undef; | ||
| 183 | |||
| 184 | my ($catalog, $schema, $table, $type); | ||
| 185 | |||
| 186 | $catalog = "";$schema = "";$table = "NOXXTABLE";$type = ""; | ||
| 187 | |||
| 188 | my $sth = DBD::_new_sth($dbh, { 'Statement' => "SQLTables_PING" }); | ||
| 189 | |||
| 190 | DAT::TimTen::db::_table_info($dbh, $sth, $catalog, $schema, $table, $type) or return 0; | ||
| 191 | $sth->finish; | ||
| 192 | return 1; | ||
| 193 | } | ||
| 194 | |||
| 195 | sub get_Details_info { | ||
| 196 | my ($dbh, $item) = @_; | ||
| 197 | return DAT::TimTen::db::_get_info($dbh, $item); | ||
| 198 | } | ||
| 199 | |||
| 200 | sub To_do { | ||
| 201 | my($dbh, $statement, $attr, @params) = @_; | ||
| 202 | my $rows = 0; | ||
| 203 | if( -1 == $#params ) | ||
| 204 | { | ||
| 205 | $rows = _ExecDirect( $dbh, $statement ); | ||
| 206 | if( 0 == $rows ) | ||
| 207 | { | ||
| 208 | $rows = "0E0"; | ||
| 209 | } | ||
| 210 | elsif( $rows < -1 ) | ||
| 211 | { | ||
| 212 | undef $rows; | ||
| 213 | } | ||
| 214 | } | ||
| 215 | else | ||
| 216 | { | ||
| 217 | $rows = $dbh->SUPER::do( $statement, $attr, @params ); | ||
| 218 | } | ||
| 219 | return $rows | ||
| 220 | } | ||
| 221 | |||
| 222 | sub type_of_all_info { | ||
| 223 | my ($dbh) = @_; | ||
| 224 | my $sth = DBD::_new_sth($dbh, { 'Statement' => "SQLGetTypeInfo" }); | ||
| 225 | DAT::TimTen::db::_type_info($dbh, $sth, DBD::SQL_ALL_TYPES) or return undef; | ||
| 226 | my $info = $sth->fetchall_arrayref; | ||
| 227 | unshift @$info, { | ||
| 228 | map { ($sth->{NAME}->[$_] => $_) } 0..$sth->{NUM_OF_FIELDS}-1 | ||
| 229 | }; | ||
| 230 | return $info; | ||
| 231 | } | ||
| 232 | |||
| 233 | } | ||
| 234 | |||
| 235 | #---------------------------------------------------- | ||
| 236 | # PACKAGE: DAT::TimTen::st() | ||
| 237 | # Description: SQL FETCH EXECUTION | ||
| 238 | #CLAUSE | ||
| 239 | # --------------------------------------------------- | ||
| 240 | |||
| 241 | { package DAT::TimTen::st; | ||
| 242 | use strict; | ||
| 243 | |||
| 244 | sub cancel { | ||
| 245 | my $sth = shift; | ||
| 246 | my $tmp = DAT::TimTen::st::_cancel($sth); | ||
| 247 | $tmp; | ||
| 248 | } | ||
| 249 | |||
| 250 | sub To_execute_fetch { | ||
| 251 | my ($sth, $fetch_tuple_sub, $tuple_status) = @_; | ||
| 252 | my $row_count = 0; | ||
| 253 | my $tuple_count=0; | ||
| 254 | my $tuple_batch_status; | ||
| 255 | my $dbh = $sth->{Database}; | ||
| 256 | my $batch_size = ($dbh->{'tt_array_chunk_size'}||= 1000); | ||
| 257 | |||
| 258 | if(defined($tuple_status)) { | ||
| 259 | @$tuple_status = (); | ||
| 260 | $tuple_batch_status = [ ]; | ||
| 261 | } | ||
| 262 | |||
| 263 | while (1) { | ||
| 264 | my @tuple_batch; | ||
| 265 | for (my $i = 0; $i < $batch_size; $i++) { | ||
| 266 | push @tuple_batch, [ @{$fetch_tuple_sub->() || last} ]; | ||
| 267 | } | ||
| 268 | last unless @tuple_batch; | ||
| 269 | my $res = _execute_array($sth, | ||
| 270 | \@tuple_batch, | ||
| 271 | scalar(@tuple_batch), | ||
| 272 | $tuple_batch_status); | ||
| 273 | if(defined($res) && defined($row_count)) { | ||
| 274 | $row_count += $res; | ||
| 275 | } else { | ||
| 276 | $row_count = undef; | ||
| 277 | } | ||
| 278 | $tuple_count+=@$tuple_batch_status; | ||
| 279 | push @$tuple_status, @$tuple_batch_status | ||
| 280 | if defined($tuple_status); | ||
| 281 | } | ||
| 282 | if (!wantarray) { | ||
| 283 | return undef if !defined $row_count; | ||
| 284 | return $tuple_count; | ||
| 285 | } | ||
| 286 | return (defined $row_count ? $tuple_count : undef, $row_count); | ||
| 287 | } | ||
| 288 | } | ||
| 289 | |||
| 290 | 1; | ||
| 291 | __END__ | ||