Changeset 32592 for main/trunk
- Timestamp:
- 2018-11-09T19:13:32+13:00 (5 years ago)
- Location:
- main/trunk/greenstone2/perllib
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/gsmysql.pm
r32591 r32592 1 1 ########################################################################### 2 2 # 3 # gs sql.pm -- DBI forSQL related utility functions used by3 # gsmysql.pm -- Uses DBI for MySQL related utility functions used by 4 4 # GreenstoneSQLPlugout and GreenstoneSQLPlugin too. 5 5 # A component of the Greenstone digital library software … … 25 25 ########################################################################### 26 26 27 package gs sql;27 package gsmysql; 28 28 29 29 use strict; … … 43 43 # TODO Q: If disconnect is automatically called when object destroyed, what does that mean 44 44 # for our file-global handle object, is disconnect only called at end of perl process? 45 # Does that mean we don't need to explicitly call disconnect in gs sql object's destroy during45 # Does that mean we don't need to explicitly call disconnect in gsmysql object's destroy during 46 46 # the GLOBAL destruction phase? 47 47 # https://perldoc.perl.org/perlobj.html#Destructors … … 345 345 } 346 346 347 # Will disconnect if this instance of gs sql holds the last reference to the db connection347 # Will disconnect if this instance of gsmysql holds the last reference to the db connection 348 348 # If disconnecting and autocommit is off, then this will commit before disconnecting 349 349 sub finished { … … 385 385 # 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." 386 386 387 print STDERR " GS SQL disconnecting from database\n" if $self->{'verbosity'};387 print STDERR " GSMySQL disconnecting from database\n" if $self->{'verbosity'}; 388 388 # Just go through the singleton db handle to disconnect 389 389 $_dbh_instance->disconnect or warn $_dbh_instance->errstr; 390 390 $_dbh_instance = undef; 391 391 } 392 # Number of gs sql objects that share a live connection is now 0, as the connection's dead393 # either because the last gs sql object finished() or because connection was killed (force)392 # Number of gsmysql objects that share a live connection is now 0, as the connection's dead 393 # either because the last gsmysql object finished() or because connection was killed (force) 394 394 $ref_count = 0; 395 395 } -
main/trunk/greenstone2/perllib/plugins/GreenstoneSQLPlugin.pm
r32591 r32592 35 35 use docprint; # for new unescape_text() subroutine 36 36 use GreenstoneXMLPlugin; 37 use gs sql;37 use gsmysql; 38 38 39 39 40 40 # TODO: 41 # - Run TODOs here, in Plugout and in gs sql.pm by Dr Bainbridge.41 # - Run TODOs here, in Plugout and in gsmysql.pm by Dr Bainbridge. 42 42 # - Have not yet tested writing out just meta or just fulltxt to sql db and reading just that 43 43 # back in from the sql db while the remainder is to be read back in from the docsql .xml files. … … 71 71 # Test doc with meta and text like macron in Maori text. 72 72 # + TODO Q: During import, the GS SQL Plugin is called before the GS SQL Plugout with undesirable side 73 # effect that if the db doesn't exist, gs sql::use_db() fails, as it won't create db.73 # effect that if the db doesn't exist, gsmysql::use_db() fails, as it won't create db. 74 74 # This got fixed when GSSQLPlugin stopped connecting on init(). 75 75 # … … 89 89 # Overriding plugins' remove_one() method is all I needed to do for reindex and deletion 90 90 # (incremental and non-incremental) to work. 91 # but doing all this needed an overhaul of gs sql.pm and its use by the GS SQL plugin and plugout.91 # but doing all this needed an overhaul of gsmysql.pm and its use by the GS SQL plugin and plugout. 92 92 # - needed to correct plugin.pm::remove_some() to process all files 93 93 # - and needed to correct GreenstoneSQLPlugin::close_document() to setOID() after all … … 145 145 'desc' => "{GreenstoneSQLPlug.rollbacl_on_cancel}" } ]; 146 146 147 # TODO: If subclassing gs sql for other supporting databases and if they have different required147 # TODO: If subclassing gsmysql for other supporting databases and if they have different required 148 148 # connection parameters, we can check how WordPlugin, upon detecting Word is installed, 149 149 # dynamically loads Word specific configuration options. … … 229 229 # as removeold, which should drop the collection tables, happens during the import phase, 230 230 # calling GreenstoneSQLPlugin::and therefore also requires a db connection. 231 # + TODO: Eventually can try moving get_gssql_instance into gs sql.pm? That way both GS SQL Plugin231 # + TODO: Eventually can try moving get_gssql_instance into gsmysql.pm? That way both GS SQL Plugin 232 232 # and Plugout would be using one connection during import.pl phase when both plugs exist. 233 233 … … 252 252 #################### 253 253 254 # create gs sql object.254 # create gsmysql object. 255 255 # collection name will be used for naming tables (site name will be used for naming database) 256 my $gs_sql = new gs sql({256 my $gs_sql = new gsmysql({ 257 257 'collection_name' => $ENV{'GSDLCOLLECTION'}, 258 258 'verbosity' => $self->{'verbosity'} || 0 … … 286 286 # This is fatal for the plugout, let's terminate here after disconnecting again 287 287 # PrintError would already have displayed the warning message on load fail 288 # And on die() perl will call gs sql destroy which will ensure a disconnect() from db288 # And on die() perl will call gsmysql destroy which will ensure a disconnect() from db 289 289 #$gs_sql->force_disconnect_from_db(); 290 290 die("Could not use db $db_name. Can't proceed.\n"); … … 310 310 311 311 # Important to call finished(): 312 # it will disconnect from db if this is the last gs sql instance,312 # it will disconnect from db if this is the last gsmysql instance, 313 313 # and it will commit to db before disconnecting if rollbback_on_cancel turned on 314 314 $self->{'gs_sql'}->finished(); -
main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm
r32591 r32592 34 34 use GreenstoneXMLPlugout; 35 35 use docprint; 36 use gs sql;36 use gsmysql; 37 37 38 38 use DBI; # the central package for this plugout … … 170 170 }; 171 171 172 my $gs_sql = new gs sql($db_params);172 my $gs_sql = new gsmysql($db_params); 173 173 174 174 # if autocommit is set, there's no rollback support … … 192 192 } 193 193 194 #die("@@@@ TEST. Connected successfully. Testing gs sql::destructor.\n"); # WORKS194 #die("@@@@ TEST. Connected successfully. Testing gsmysql::destructor.\n"); # WORKS 195 195 196 196 my $db_name = $self->{'site'} || "greenstone2"; # one database per GS3 site, for GS2 the db is called greenstone2 … … 212 212 # This is fatal for the plugout, let's terminate here after disconnecting again 213 213 # PrintError would already have displayed the warning message on load fail 214 # And on die() perl will call gs sql destroy which will ensure a disconnect() from db214 # And on die() perl will call gsmysql destroy which will ensure a disconnect() from db 215 215 #$gs_sql->force_disconnect_from_db(); # disconnect_from_db() will issue a warning on error 216 216 die("Could not use db $db_name and/or prepare its tables. Can't proceed.\n"); … … 237 237 238 238 # Important to call finished(): 239 # it will disconnect from db if this is the last gs sql instance,239 # it will disconnect from db if this is the last gsmysql instance, 240 240 # and it will commit to db before disconnecting if rollbback_on_cancel turned on 241 241 $self->{'gs_sql'}->finished();
Note:
See TracChangeset
for help on using the changeset viewer.