- Timestamp:
- 2018-10-31T19:57:20+13:00 (5 years ago)
- Location:
- main/trunk/greenstone2/perllib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/gssql.pm
r32559 r32560 67 67 my $self = { 68 68 'collection_name' => $params_map->{'collection_name'}, 69 'verbosity' => $params_map->{'verbosity'} || 1 69 70 }; 70 71 … … 132 133 my $connect_str = "dbi:$db_driver:host=$db_host"; # don't provide db - allows checking the db exists later when loading the db 133 134 134 print STDERR "Away to make connection to $db_driver database with:\n"; 135 print STDERR " - hostname $db_host; username: $db_user"; 136 print STDERR "; and the password provided" if $db_pwd; 137 print STDERR "\nAssuming the mysql server has been started with: --character_set_server=utf8mb4\n" if $db_driver eq "mysql"; 135 if($self->{'verbosity'}) { 136 print STDERR "Away to make connection to $db_driver database with:\n"; 137 print STDERR " - hostname $db_host; username: $db_user"; 138 print STDERR "; and the password provided" if $db_pwd; 139 print STDERR "\nAssuming the mysql server has been started with: --character_set_server=utf8mb4\n" if $db_driver eq "mysql"; 140 } 138 141 139 142 my $dbh = DBI->connect("$connect_str", $db_user, $db_pwd, … … 195 198 my $dbh = $self->{'db_handle'}; 196 199 197 print STDERR "Attempting to use database $db_name\n" ;200 print STDERR "Attempting to use database $db_name\n" if($self->{'verbosity'}); 198 201 199 202 # perl DBI switch database: https://www.perlmonks.org/?node_id=995434 … … 204 207 if(!$success && $dbh->err == 1049) { # "Unknown database" error has code 1049 (mysql only?) meaning db doesn't exist yet 205 208 206 print STDERR "Database $db_name didn't exist, creating it and t ables for the current collection...\n";209 print STDERR "Database $db_name didn't exist, creating it and the tables for the current collection...\n" if($self->{'verbosity'}); 207 210 208 211 # attempt to create the db and its tables 209 212 $self->create_db($db_name) || return 0; 210 213 211 print STDERR " Created database $db_name\n" ;214 print STDERR " Created database $db_name\n" if($self->{'verbosity'} > 1); 212 215 213 216 # once more attempt to use db, now that it exists … … 224 227 # before proceeding check that the current collection's tables exist 225 228 226 print STDERR "@@@ DATABASE $db_name EXISTED\n" ;229 print STDERR "@@@ DATABASE $db_name EXISTED\n" if($self->{'verbosity'} > 2); 227 230 228 231 … … 230 233 # deleting the existing tables for this collection and recreating empty ones 231 234 if($build_mode eq "removeold") { 232 print STDERR " Building with removeold option set, so deleting current collection's tables if they exist\n" ;235 print STDERR " Building with removeold option set, so deleting current collection's tables if they exist\n" if($self->{'verbosity'}); 233 236 $self->delete_collection_tables(); 234 237 } … … 239 242 $self->create_metadata_table() || return 0; 240 243 } else { 241 print STDERR "@@@ Meta table exists\n" ;244 print STDERR "@@@ Meta table exists\n" if($self->{'verbosity'} > 2); 242 245 } 243 246 if($build_mode eq "removeold" || !$self->table_exists($self->get_fulltext_table_name())) { 244 247 $self->create_fulltext_table() || return 0; 245 248 } else { 246 print STDERR "@@@ Fulltxt table exists\n" ;249 print STDERR "@@@ Fulltxt table exists\n" if($self->{'verbosity'} > 2); 247 250 } 248 251 … … 263 266 my $dbh = $self->{'db_handle'}; 264 267 265 print STDERR "Loading database $db_name\n" ;268 print STDERR "Loading database $db_name\n" if($self->{'verbosity'} > 1); 266 269 267 270 # perl DBI switch database: https://www.perlmonks.org/?node_id=995434 … … 286 289 #$txt_sth->finish() if($txt_sth); 287 290 288 print STDERR "Disconnecting from database\n" ;291 print STDERR "Disconnecting from database\n" if($self->{'verbosity'} > 1); 289 292 290 293 my $rc = $dbh->disconnect or warn $dbh->errstr; # The handle is of little use after disconnecting. Possibly PrintError already prints a warning and this duplicates it? … … 307 310 308 311 my $table_name = $self->get_metadata_table_name(); 309 print STDERR " Creating table $table_name\n" ;312 print STDERR " Creating table $table_name\n" if($self->{'verbosity'} > 1); 310 313 311 314 # If using an auto incremented primary key: … … 323 326 324 327 my $table_name = $self->get_fulltext_table_name(); 325 print STDERR " Creating table $table_name\n" ;328 print STDERR " Creating table $table_name\n" if($self->{'verbosity'} > 1); 326 329 327 330 # If using an auto incremented primary key: … … 356 359 my $dbh = $self->{'db_handle'}; 357 360 358 print STDERR "!!! Deleting database $db_name\n" ;361 print STDERR "!!! Deleting database $db_name\n" if($self->{'verbosity'}); 359 362 360 363 # "drop database dbname" … … 394 397 my $sth = $dbh->prepare(qq{INSERT INTO $tablename (did, sid, metaname, metavalue) VALUES (?, ?, ?, ?)}) || warn("Could not prepare insert statement for metadata table\n"); 395 398 396 print STDERR "@@@@ Prepared meta insert statement: ".$sth->{'Statement'}."\n" ;399 print STDERR "@@@@ Prepared meta insert statement: ".$sth->{'Statement'}."\n" if($self->{'verbosity'} > 2); 397 400 398 401 return $sth; … … 412 415 my $sth = $dbh->prepare(qq{INSERT INTO $tablename (did, sid, fulltxt) VALUES (?, ?, ?)}) || warn("Could not prepare insert statement for fulltxt table\n"); 413 416 414 print STDERR "@@@@ Prepared fulltext insert statement: ".$sth->{'Statement'}."\n" ;417 print STDERR "@@@@ Prepared fulltext insert statement: ".$sth->{'Statement'}."\n" if($self->{'verbosity'} > 2); 415 418 416 419 return $sth; -
main/trunk/greenstone2/perllib/plugins/GreenstoneSQLPlugin.pm
r32559 r32560 374 374 # collection name will be used for naming tables (site name will be used for naming database) 375 375 my $gs_sql = new gssql({ 376 'collection_name' => $ENV{'GSDLCOLLECTION'} 376 'collection_name' => $ENV{'GSDLCOLLECTION'}, 377 'verbosity' => $self->{'verbosity'} 377 378 }); 378 379 -
main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm
r32559 r32560 141 141 142 142 my $db_params = { 143 'collection_name' => $ENV{'GSDLCOLLECTION'} 143 'collection_name' => $ENV{'GSDLCOLLECTION'}, 144 'verbosity' => 1 144 145 }; 145 146
Note:
See TracChangeset
for help on using the changeset viewer.