Changeset 32573 for main/trunk/greenstone2/perllib/gssql.pm
- Timestamp:
- 2018-11-05T19:24:47+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/gssql.pm
r32571 r32573 270 270 # NO: "When all the data has been fetched from a SELECT statement, the driver will automatically call finish for you. So you should not call it explicitly except when you know that you've not fetched all the data from a statement handle and the handle won't be destroyed soon." 271 271 272 #$meta_sth = $self->{'metadata_prepared_insert_statement_handle'};273 #$txt_sth = $self->{'fulltxt_prepared_insert_statement_handle'};274 #$meta_sth->finish() if($meta_sth);275 #$txt_sth->finish() if($txt_sth);276 277 272 print STDERR "Disconnecting from database\n" if($self->{'verbosity'} > 1); 278 273 … … 372 367 # https://metacpan.org/pod/DBI#performance 373 368 # 'The q{...} style quoting used in this example avoids clashing with quotes that may be used in the SQL statement. Use the double-quote like qq{...} operator if you want to interpolate variables into the string. See "Quote and Quote-like Operators" in perlop for more details.' 374 sub prepare_insert_metadata_row_stmthandle { 375 my $self = shift (@_); 369 # 370 # This method uses lazy loading to prepare the SQL insert stmt once for a table and store it, 371 # then execute the (stored) statement each time it's needed for that table. 372 sub insert_row_into_metadata_table { 373 my $self = shift (@_); 374 my ($doc_oid, $section_name, $meta_name, $escaped_meta_value, $debug_only, $debug_out) = @_; 375 376 376 #my ($did, $sid, $metaname, $metavalue) = @_; 377 377 my $dbh = $self->{'db_handle'}; 378 379 my $tablename = $self->get_metadata_table_name(); 380 381 #my $stmt = "INSERT INTO $tablename (did, sid, metaname, metavalue) VALUES ('$did', '$sid', '$metaname', '$metavalue');"; # ?, ?, ?, ? 382 383 # using qq{} since we want $tablename placeholder to be filled in 384 # returns Statement Handle object! 385 my $sth = $dbh->prepare(qq{INSERT INTO $tablename (did, sid, metaname, metavalue) VALUES (?, ?, ?, ?)}) || warn("Could not prepare insert statement for metadata table\n"); 386 387 print STDERR "@@@@ Prepared meta insert statement: ".$sth->{'Statement'}."\n" if($self->{'verbosity'} > 2); 388 389 return $sth; 390 } 391 392 sub prepare_insert_fulltxt_row_stmthandle { 378 379 my $sth = $self->{"sth_insert_into_meta_table"}; 380 if(!$sth) { 381 my $tablename = $self->get_metadata_table_name(); 382 383 #my $stmt = "INSERT INTO $tablename (did, sid, metaname, metavalue) VALUES ('$did', '$sid', '$metaname', '$metavalue');"; # ?, ?, ?, ? 384 385 # using qq{} since we want $tablename placeholder to be filled in 386 # returns Statement Handle object! 387 $sth = $dbh->prepare(qq{INSERT INTO $tablename (did, sid, metaname, metavalue) VALUES (?, ?, ?, ?)}) || warn("Could not prepare insert statement for metadata table\n"); 388 389 print STDERR "@@@@ Prepared meta insert statement: ".$sth->{'Statement'}."\n" if($self->{'verbosity'} > 2); 390 391 $self->{"sth_insert_into_meta_table"} = $sth; # store it for future use 392 } 393 394 # Now we're ready to execute the command, unless we're only debugging 395 396 if($debug_only) { 397 # just print the statement we were going to execute 398 399 print $debug_out $sth->{'Statement'} . "($doc_oid, $section_name, $meta_name, $escaped_meta_value)\n"; 400 } else { 401 $sth->execute($doc_oid, $section_name, $meta_name, $escaped_meta_value) 402 || warn ("Unable to write metadata row to db:\n\tOID $doc_oid, section $section_name,\n\tmeta name: $meta_name, val: $escaped_meta_value"); 403 # Execution failure will print out info anyway: since db connection sets PrintError 404 } 405 } 406 407 # As above. Likewise uses lazy loading to prepare the SQL insert stmt once for a table and store it, 408 # then execute the (stored) statement each time it's needed for that table. 409 sub insert_row_into_fulltxt_table { 393 410 my $self = shift (@_); 394 411 #my ($did, $sid, $fulltext) = @_; 395 my $dbh = $self->{'db_handle'}; 396 397 my $tablename = $self->get_fulltext_table_name(); 398 399 #my $stmt = "INSERT INTO $tablename (did, sid, fulltxt) VALUES ('$did', '$sid', '$fulltext');"; ?, ?, ? 400 401 # using qq{} since we want $tablename placeholder to be filled in 402 # returns Statement Handle object! 403 my $sth = $dbh->prepare(qq{INSERT INTO $tablename (did, sid, fulltxt) VALUES (?, ?, ?)}) || warn("Could not prepare insert statement for fulltxt table\n"); 404 405 print STDERR "@@@@ Prepared fulltext insert statement: ".$sth->{'Statement'}."\n" if($self->{'verbosity'} > 2); 406 407 return $sth; 412 my ($doc_oid, $section_name, $section_textref, $debug_only, $debug_out) = @_; 413 414 my $dbh = $self->{'db_handle'}; 415 416 my $sth = $self->{"sth_insert_into_fulltxt_table"}; 417 if(!$sth) { 418 my $tablename = $self->get_fulltext_table_name(); 419 420 #my $stmt = "INSERT INTO $tablename (did, sid, fulltxt) VALUES ('$did', '$sid', '$fulltext');"; ?, ?, ? 421 422 # using qq{} since we want $tablename placeholder to be filled in 423 # returns Statement Handle object! 424 $sth = $dbh->prepare(qq{INSERT INTO $tablename (did, sid, fulltxt) VALUES (?, ?, ?)}) || warn("Could not prepare insert statement for fulltxt table\n"); 425 426 print STDERR "@@@@ Prepared fulltext insert statement: ".$sth->{'Statement'}."\n" if($self->{'verbosity'} > 2); 427 428 $self->{"sth_insert_into_fulltxt_table"} = $sth; # store it for future use 429 } 430 431 # Now we're ready to execute the command, unless we're only debugging 432 433 if($debug_only) { 434 # just print the statement we were going to execute, minus the fulltxt value 435 my $txt_repr = $$section_textref ? "<TXT>" : "NULL"; 436 print $debug_out $sth->{'Statement'} . "($doc_oid, $section_name, $txt_repr)\n"; 437 } else { 438 $sth->execute($doc_oid, $section_name, $$section_textref) 439 || warn ("Unable to write fulltxt row to db for row:\n\tOID $doc_oid, section $section_name"); 440 } 408 441 } 409 442
Note:
See TracChangeset
for help on using the changeset viewer.