- Timestamp:
- 2018-10-31T18:58:56+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/gssql.pm
r32557 r32558 125 125 # on the local machine via TCP, you must specify the loopback IP address (127.0.0.1) as the host." 126 126 #my $connect_str = "dbi:$db_driver:database=$db_name;host=$db_host"; 127 my $connect_str = "dbi:$db_driver:host=$db_host"; # don't provide db - allows checking the db exists 127 my $connect_str = "dbi:$db_driver:host=$db_host"; # don't provide db - allows checking the db exists later when loading the db 128 129 print STDERR "Away to make connection to $db_driver database with:\n"; 130 print STDERR " - hostname $db_host; username: $db_user"; 131 print STDERR "; and the password provided" if $db_pwd; 132 print STDERR "Assuming the mysql server has been started with --character_set_server=utf8mb4" if $db_driver eq "mysql"; 133 128 134 my $dbh = DBI->connect("$connect_str", $db_user, $db_pwd, 129 135 { … … 184 190 my $dbh = $self->{'db_handle'}; 185 191 192 print STDERR "Attempting to use database $db_name\n"; 193 186 194 # perl DBI switch database: https://www.perlmonks.org/?node_id=995434 187 195 # do() returns undef on error. … … 190 198 191 199 if(!$success && $dbh->err == 1049) { # "Unknown database" error has code 1049 (mysql only?) meaning db doesn't exist yet 200 201 print STDERR "Database $db_name didn't exist, creating it and tables for the current collection...\n"; 202 192 203 # attempt to create the db and its tables 193 204 $self->create_db($db_name) || return 0; 194 205 195 print STDERR " @@@ CREATED DATABASE$db_name\n";206 print STDERR " Created database $db_name\n"; 196 207 197 208 # once more attempt to use db, now that it exists … … 214 225 # deleting the existing tables for this collection and recreating empty ones 215 226 if($build_mode eq "removeold") { 227 print STDERR " Building with removeold option set, so deleting current collection's tables if they exist\n"; 216 228 $self->delete_collection_tables(); 217 229 } … … 245 257 my ($db_name) = @_; 246 258 my $dbh = $self->{'db_handle'}; 259 260 print STDERR "Loading database $db_name\n"; 247 261 248 262 # perl DBI switch database: https://www.perlmonks.org/?node_id=995434 … … 266 280 #$meta_sth->finish() if($meta_sth); 267 281 #$txt_sth->finish() if($txt_sth); 282 283 print STDERR "Disconnecting from database\n"; 268 284 269 285 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? … … 286 302 287 303 my $table_name = $self->get_metadata_table_name(); 288 304 print STDERR " Creating table $table_name\n"; 305 289 306 # If using an auto incremented primary key: 290 307 my $stmt = "CREATE TABLE $table_name (id INT NOT NULL AUTO_INCREMENT, did VARCHAR(63) NOT NULL, sid VARCHAR(63) NOT NULL, metaname VARCHAR(127) NOT NULL, metavalue VARCHAR(1023) NOT NULL, PRIMARY KEY(id));"; … … 301 318 302 319 my $table_name = $self->get_fulltext_table_name(); 303 320 print STDERR " Creating table $table_name\n"; 321 304 322 # If using an auto incremented primary key: 305 323 my $stmt = "CREATE TABLE $table_name (id INT NOT NULL AUTO_INCREMENT, did VARCHAR(63) NOT NULL, sid VARCHAR(63) NOT NULL, fulltxt LONGTEXT, PRIMARY KEY(id));"; … … 314 332 my $self= shift (@_); 315 333 my $dbh = $self->{'db_handle'}; 316 317 print STDERR "### Build mode is removeold, so deleting tables for current collection\n";318 334 319 335 # drop table <tablename> … … 334 350 my ($db_name) = @_; 335 351 my $dbh = $self->{'db_handle'}; 352 353 print STDERR "!!! Deleting database $db_name\n"; 336 354 337 355 # "drop database dbname"
Note:
See TracChangeset
for help on using the changeset viewer.