Changeset 32575 for main/trunk/greenstone2/perllib/gssql.pm
- Timestamp:
- 2018-11-05T20:51:24+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/gssql.pm
r32574 r32575 424 424 ## The 2 select statements used by GreenstoneSQLPlugin 425 425 426 #https://metacpan.org/pod/release/TIMB/DBI-1.634_50/DBI.pm#selectall_arrayref 426 # Using fetchall_arrayref on statement handle, to run on prepared and executed stmt 427 # https://metacpan.org/pod/release/TIMB/DBI-1.634_50/DBI.pm#fetchall_arrayref 428 # instead of selectall_arrayref on database handle which will prepare, execute and fetch 429 # https://metacpan.org/pod/release/TIMB/DBI-1.634_50/DBI.pm#selectall_arrayref 430 # 427 431 # Returns the statement handle that prepared and executed 428 432 # a "SELECT * FROM <COLL>_metadata WHERE did = $oid" SQL statement. … … 433 437 sub select_from_metatable_matching_docid { 434 438 my $self= shift (@_); 435 my ($oid ) = @_;436 437 my $dbh = $self->{'db_handle'}; 438 my $ meta_table = $self->get_metadata_table_name();439 440 my $sth = $dbh->prepare_cached(qq{SELECT * FROM $ meta_table WHERE did = ?});439 my ($oid, $outhandle) = @_; 440 441 my $dbh = $self->{'db_handle'}; 442 my $tablename = $self->get_metadata_table_name(); 443 444 my $sth = $dbh->prepare_cached(qq{SELECT * FROM $tablename WHERE did = ?}); 441 445 $sth->execute( $oid ); # will print msg on fail 442 443 return $sth; # caller can call fetchrow_array() on returned statement handle, sth 444 } 445 446 447 #https://metacpan.org/pod/release/TIMB/DBI-1.634_50/DBI.pm#selectall_arrayref 446 447 print $outhandle "### SQL select stmt: ".$sth->{'Statement'}."\n" 448 if ($self->{'verbosity'} > 2); 449 450 my $rows_ref = $sth->fetchall_arrayref(); 451 # "If an error occurs, fetchall_arrayref returns the data fetched thus far, which may be none. 452 # You should check $sth->err afterwards (or use the RaiseError attribute) to discover if the 453 # data is complete or was truncated due to an error." 454 # https://metacpan.org/pod/release/TIMB/DBI-1.634_50/DBI.pm#fetchall_arrayref 455 # https://www.oreilly.com/library/view/programming-the-perl/1565926994/ch04s05.html 456 warn("Data fetching from $tablename terminated early by error: " . $dbh->err) if $dbh->err; 457 return $rows_ref; 458 } 459 460 461 # See select_from_metatable_matching_docid() above. 448 462 # Returns the statement handle that prepared and executed 449 463 # a "SELECT * FROM <COLL>_metadata WHERE did = $oid" SQL statement. … … 451 465 sub select_from_texttable_matching_docid { 452 466 my $self= shift (@_); 453 my ($oid ) = @_;454 455 my $dbh = $self->{'db_handle'}; 456 my $ fulltxt_table = $self->get_fulltext_table_name();457 458 my $sth = $dbh->prepare_cached(qq{SELECT * FROM $ fulltxt_table WHERE did = ?});467 my ($oid, $outhandle) = @_; 468 469 my $dbh = $self->{'db_handle'}; 470 my $tablename = $self->get_fulltext_table_name(); 471 472 my $sth = $dbh->prepare_cached(qq{SELECT * FROM $tablename WHERE did = ?}); 459 473 $sth->execute( $oid ); # will print msg on fail 460 474 461 return $sth; # caller can call fetchrow_array() on returned statement handle, sth 475 print $outhandle "### SQL select stmt: ".$sth->{'Statement'}."\n" 476 if ($self->{'verbosity'} > 2); 477 478 my $rows_ref = $sth->fetchall_arrayref(); 479 # Need explicit warning: 480 warn("Data fetching from $tablename terminated early by error: " . $dbh->err) if $dbh->err; 481 return $rows_ref; 482 462 483 } 463 484
Note:
See TracChangeset
for help on using the changeset viewer.