Ignore:
Timestamp:
2018-11-09T19:01:04+13:00 (5 years ago)
Author:
ak19
Message:
  1. gssql destructor DESTROY doesn't really do anything now, as DBI's destructor will ensure disconnection if not already disconnected. So we don't disconnect in gssql DESTROY, which we used to do but which would only happen on Cancel specifically as other gssql code would already disconnect on natural termination. 2. gssql no longer sets connection parameter fallbacks for those that have fallbacks, since the defaults for these parameters are set by the GS SQL Plugs' configuration options. 3. No need to (html) escape meta/full text when storing in DB or unescape when reading it out of DB, since DB is like a regular text file: can just put text in there. It's only html/xml files where text needs to be stored escaped. 4. Having committed doc.pm::add_utf8_textREF() method in previous commit, GreenstoneSQLPlugin can now pass the fulltxt by reference using this method when constructing the doc_obj from what's read in from the DB.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/gssql.pm

    r32588 r32591  
    5252# + TODO: remove unnecessary warn() since PrintError is active
    5353
    54 # TODO: drop table if exists and create table if exists are available in MySQL. Use those cmds
     54# + TODO: drop table if exists and create table if exists are available in MySQL. Use those cmds
    5555# instead of always first checking for existence ourselves? Only when subclassing to specific
    5656# mysql class?
     
    157157#
    158158# https://metacpan.org/pod/release/TIMB/DBI-1.634_50/DBI.pm#disconnect
    159 # "Disconnects the database from the database handle. disconnect is typically only used before exitin# g the program. The handle is of little use after disconnecting.
     159# "Disconnects the database from the database handle. disconnect is typically only used before exiting the program. The handle is of little use after disconnecting.
    160160#
    161161# The transaction behaviour of the disconnect method is, sadly, undefined. Some database systems (such as Oracle and Ingres) will automatically commit any outstanding changes, but others (such as Informix) will rollback any outstanding changes. Applications not using AutoCommit should explicitly call commit or rollback before calling disconnect.
     
    166166#
    167167# If you disconnect from a database while you still have active statement handles (e.g., SELECT statement handles that may have more data to fetch), you will get a warning. The warning may indicate that a fetch loop terminated early, perhaps due to an uncaught error. To avoid the warning call the finish method on the active handles."
     168#
    168169#
    169170sub DESTROY {
     
    171172   
    172173    if (${^GLOBAL_PHASE} eq 'DESTRUCT') {
    173    
     174
    174175    if ($_dbh_instance) { # database handle still active. Use singleton handle!
    175 
    176         # rollback code has moved to finish_signal_handler() where it belongs?
    177        
    178         # NOTE: if RaiseError is set on dbi connection, then on any error, perl process will die()
    179         # which will end up calling this DESTROY. If it was a die() that called DESTROY
    180         # then need to rollback the db here. However, if it was not a die() but natural termination
    181         # of the perl process, destroy() will also get called. In that case we don't want to rollback
    182         # but do a commit() to the DB instead.
    183         # Perhaps detecting the difference may be accomplished by checking ref_count:
    184         # - If ref_count not 0 it may require a rollback?
    185         # - If ref_count 0 it may be a natural termination and require a commit? Except that ref_count
    186         # is set back to 0 in finished(), which will do the commit when ref_count becomes 0. So shouldn't
    187         # (have to) do that here.
     176                          # dbh instance being active implies build was cancelled
     177
     178        # rollback code has moved to finish_signal_handler() where it belongs
     179        # as rollback() should only happen on cancel/unnatural termination
     180        # vs commit() happening in finished() before disconnect, which is natural termination.
     181
    188182       
    189183        # We're now finally ready to disconnect, as is required for both natural and premature termination
    190         print STDERR "XXXXXXXX Global Destruct: Disconnecting from database\n";
    191         $_dbh_instance->disconnect or warn $_dbh_instance->errstr;
    192         $_dbh_instance = undef;
    193         $ref_count = 0;
     184        # (Though natural termination would have disconnected already)
     185        # We now leave DBI's own destructor to do the disconnection when perl calls its DESTROY()
     186        # We'll just print a message to stop anyone from worrying whether cancelling build
     187        # will ensure disconnection still happens. It happens, but silently.
     188        print STDERR "   Global Destruct Phase: DBI's own destructor will disconnect database\n";
     189        #$_dbh_instance->disconnect or warn $_dbh_instance->errstr;
     190        #$_dbh_instance = undef;
     191        #$ref_count = 0;
    194192    }
    195193    return;
     
    246244    }
    247245    if($params_map->{'autocommit'}) {
    248         print STDERR "   SQL DB CANCEL SUPPORT OFF.\n";
     246        print STDERR "   SQL DB CANCEL SUPPORT OFF.\n" if($params_map->{'verbosity'} > 2);
    249247    } else {
    250248        print STDERR "   SQL DB CANCEL SUPPORT ON.\n";
     
    259257    my $db_enc = "utf8mb4" if $params_map->{'db_encoding'} eq "utf8";
    260258
    261     # these are the params for connecting to MySQL
    262     my $db_driver = $params_map->{'db_driver'} || "mysql";
    263     my $db_user = $params_map->{'db_client_user'} || "root";
     259    # Params for connecting to MySQL
     260    # These params are ensured default/fallback values by the GS SQL Plugs
     261    # so no need to set it here
     262    my $db_driver = $params_map->{'db_driver'};
     263    my $db_host = $params_map->{'db_host'};
     264    my $db_user = $params_map->{'db_client_user'};
     265
     266    # params that can be undef are db_client_pwd and db_port
    264267    my $db_pwd = $params_map->{'db_client_pwd'}; # even if undef and password was necessary,
    265268                                     # we'll see a sensible error message when connect fails
    266     my $db_host = $params_map->{'db_host'} || "127.0.0.1";
    267269        # localhost doesn't work for us, but 127.0.0.1 works
    268270        # https://metacpan.org/pod/DBD::mysql
     
    355357    if($ref_count == 0) { # Only commit transaction when we're about to actually disconnect, not before
    356358   
    357     # TODO: If AutoCommit was off, meaning transactions were on/enabled,
     359    # + TODO: If AutoCommit was off, meaning transactions were on/enabled,
    358360    # then here is where we commit our one long transaction.
    359361    # https://metacpan.org/pod/release/TIMB/DBI-1.634_50/DBI.pm#commit
     
    521523    }
    522524
    523     # TODO Q: commit here, so that future select statements work?
     525    # + TODO Q: commit here, so that future select statements work?
    524526    # See https://metacpan.org/pod/release/TIMB/DBI-1.634_50/DBI.pm#Transactions
    525527}
Note: See TracChangeset for help on using the changeset viewer.