Changeset 32591 for main/trunk/greenstone2/perllib/gssql.pm
- Timestamp:
- 2018-11-09T19:01:04+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/gssql.pm
r32588 r32591 52 52 # + TODO: remove unnecessary warn() since PrintError is active 53 53 54 # TODO: drop table if exists and create table if exists are available in MySQL. Use those cmds54 # + TODO: drop table if exists and create table if exists are available in MySQL. Use those cmds 55 55 # instead of always first checking for existence ourselves? Only when subclassing to specific 56 56 # mysql class? … … 157 157 # 158 158 # 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. 160 160 # 161 161 # 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. … … 166 166 # 167 167 # 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 # 168 169 # 169 170 sub DESTROY { … … 171 172 172 173 if (${^GLOBAL_PHASE} eq 'DESTRUCT') { 173 174 174 175 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 188 182 189 183 # 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; 194 192 } 195 193 return; … … 246 244 } 247 245 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); 249 247 } else { 250 248 print STDERR " SQL DB CANCEL SUPPORT ON.\n"; … … 259 257 my $db_enc = "utf8mb4" if $params_map->{'db_encoding'} eq "utf8"; 260 258 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 264 267 my $db_pwd = $params_map->{'db_client_pwd'}; # even if undef and password was necessary, 265 268 # we'll see a sensible error message when connect fails 266 my $db_host = $params_map->{'db_host'} || "127.0.0.1";267 269 # localhost doesn't work for us, but 127.0.0.1 works 268 270 # https://metacpan.org/pod/DBD::mysql … … 355 357 if($ref_count == 0) { # Only commit transaction when we're about to actually disconnect, not before 356 358 357 # TODO: If AutoCommit was off, meaning transactions were on/enabled,359 # + TODO: If AutoCommit was off, meaning transactions were on/enabled, 358 360 # then here is where we commit our one long transaction. 359 361 # https://metacpan.org/pod/release/TIMB/DBI-1.634_50/DBI.pm#commit … … 521 523 } 522 524 523 # TODO Q: commit here, so that future select statements work?525 # + TODO Q: commit here, so that future select statements work? 524 526 # See https://metacpan.org/pod/release/TIMB/DBI-1.634_50/DBI.pm#Transactions 525 527 }
Note:
See TracChangeset
for help on using the changeset viewer.