Ignore:
Timestamp:
2018-10-31T18:58:56+13:00 (5 years ago)
Author:
ak19
Message:

Breadcrumbs on connection and some further helpful messages.

File:
1 edited

Legend:

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

    r32557 r32558  
    125125    # on the local machine via TCP, you must specify the loopback IP address (127.0.0.1) as the host."
    126126    #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   
    128134    my $dbh = DBI->connect("$connect_str", $db_user, $db_pwd,
    129135               {
     
    184190    my $dbh = $self->{'db_handle'};
    185191   
     192    print STDERR "Attempting to use database $db_name\n";
     193   
    186194    # perl DBI switch database: https://www.perlmonks.org/?node_id=995434
    187195    # do() returns undef on error.
     
    190198   
    191199    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   
    192203    # attempt to create the db and its tables
    193204    $self->create_db($db_name) || return 0;
    194205
    195     print STDERR "@@@ CREATED DATABASE $db_name\n";
     206    print STDERR "   Created database $db_name\n";
    196207   
    197208    # once more attempt to use db, now that it exists
     
    214225    # deleting the existing tables for this collection and recreating empty ones
    215226    if($build_mode eq "removeold") {
     227        print STDERR "   Building with removeold option set, so deleting current collection's tables if they exist\n";
    216228        $self->delete_collection_tables();
    217229    }
     
    245257    my ($db_name) = @_;
    246258    my $dbh = $self->{'db_handle'};
     259
     260    print STDERR "Loading database $db_name\n";
    247261   
    248262    # perl DBI switch database: https://www.perlmonks.org/?node_id=995434
     
    266280    #$meta_sth->finish() if($meta_sth);
    267281    #$txt_sth->finish() if($txt_sth);
     282
     283    print STDERR "Disconnecting from database\n";
    268284   
    269285    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?
     
    286302   
    287303    my $table_name = $self->get_metadata_table_name();
    288 
     304    print STDERR "   Creating table $table_name\n";
     305   
    289306    # If using an auto incremented primary key:
    290307    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));";
     
    301318   
    302319    my $table_name = $self->get_fulltext_table_name();
    303 
     320    print STDERR "   Creating table $table_name\n";
     321   
    304322    # If using an auto incremented primary key:
    305323    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));";
     
    314332    my $self= shift (@_);
    315333    my $dbh = $self->{'db_handle'};
    316    
    317     print STDERR "### Build mode is removeold, so deleting tables for current collection\n";
    318334   
    319335    # drop table <tablename>
     
    334350    my ($db_name) = @_;
    335351    my $dbh = $self->{'db_handle'};
     352
     353    print STDERR "!!! Deleting database $db_name\n";
    336354   
    337355    # "drop database dbname"
Note: See TracChangeset for help on using the changeset viewer.