Changeset 32560 for main/trunk


Ignore:
Timestamp:
2018-10-31T19:57:20+13:00 (5 years ago)
Author:
ak19
Message:

gssql constructor accepts a verbosity parameter

Location:
main/trunk/greenstone2/perllib
Files:
3 edited

Legend:

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

    r32559 r32560  
    6767    my $self = {
    6868    'collection_name' => $params_map->{'collection_name'},
     69    'verbosity' => $params_map->{'verbosity'} || 1
    6970    };
    7071
     
    132133    my $connect_str = "dbi:$db_driver:host=$db_host"; # don't provide db - allows checking the db exists later when loading the db
    133134
    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    }
    138141   
    139142    my $dbh = DBI->connect("$connect_str", $db_user, $db_pwd,
     
    195198    my $dbh = $self->{'db_handle'};
    196199   
    197     print STDERR "Attempting to use database $db_name\n";
     200    print STDERR "Attempting to use database $db_name\n" if($self->{'verbosity'});
    198201   
    199202    # perl DBI switch database: https://www.perlmonks.org/?node_id=995434
     
    204207    if(!$success && $dbh->err == 1049) { # "Unknown database" error has code 1049 (mysql only?) meaning db doesn't exist yet
    205208
    206     print STDERR "Database $db_name didn't exist, creating it and tables 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'});
    207210   
    208211    # attempt to create the db and its tables
    209212    $self->create_db($db_name) || return 0;
    210213
    211     print STDERR "   Created database $db_name\n";
     214    print STDERR "   Created database $db_name\n" if($self->{'verbosity'} > 1);
    212215   
    213216    # once more attempt to use db, now that it exists
     
    224227    # before proceeding check that the current collection's tables exist
    225228
    226     print STDERR "@@@ DATABASE $db_name EXISTED\n";
     229    print STDERR "@@@ DATABASE $db_name EXISTED\n" if($self->{'verbosity'} > 2);
    227230   
    228231
     
    230233    # deleting the existing tables for this collection and recreating empty ones
    231234    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'});
    233236        $self->delete_collection_tables();
    234237    }
     
    239242        $self->create_metadata_table() || return 0;
    240243    } else {
    241         print STDERR "@@@ Meta table exists\n";
     244        print STDERR "@@@ Meta table exists\n" if($self->{'verbosity'} > 2);
    242245    }
    243246    if($build_mode eq "removeold" || !$self->table_exists($self->get_fulltext_table_name())) {
    244247        $self->create_fulltext_table() || return 0;
    245248    } else {
    246         print STDERR "@@@ Fulltxt table exists\n";
     249        print STDERR "@@@ Fulltxt table exists\n" if($self->{'verbosity'} > 2);
    247250    }
    248251   
     
    263266    my $dbh = $self->{'db_handle'};
    264267
    265     print STDERR "Loading database $db_name\n";
     268    print STDERR "Loading database $db_name\n" if($self->{'verbosity'} > 1);
    266269   
    267270    # perl DBI switch database: https://www.perlmonks.org/?node_id=995434
     
    286289    #$txt_sth->finish() if($txt_sth);
    287290
    288     print STDERR "Disconnecting from database\n";
     291    print STDERR "Disconnecting from database\n" if($self->{'verbosity'} > 1);
    289292   
    290293    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?
     
    307310   
    308311    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);
    310313   
    311314    # If using an auto incremented primary key:
     
    323326   
    324327    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);
    326329   
    327330    # If using an auto incremented primary key:
     
    356359    my $dbh = $self->{'db_handle'};
    357360
    358     print STDERR "!!! Deleting database $db_name\n";
     361    print STDERR "!!! Deleting database $db_name\n" if($self->{'verbosity'});
    359362   
    360363    # "drop database dbname"
     
    394397    my $sth = $dbh->prepare(qq{INSERT INTO $tablename (did, sid, metaname, metavalue) VALUES (?, ?, ?, ?)}) || warn("Could not prepare insert statement for metadata table\n");
    395398
    396     print STDERR "@@@@ Prepared meta insert statement: ".$sth->{'Statement'}."\n";
     399    print STDERR "@@@@ Prepared meta insert statement: ".$sth->{'Statement'}."\n" if($self->{'verbosity'} > 2);
    397400   
    398401    return $sth;
     
    412415    my $sth = $dbh->prepare(qq{INSERT INTO $tablename (did, sid, fulltxt) VALUES (?, ?, ?)}) || warn("Could not prepare insert statement for fulltxt table\n");
    413416   
    414     print STDERR "@@@@ Prepared fulltext insert statement: ".$sth->{'Statement'}."\n";
     417    print STDERR "@@@@ Prepared fulltext insert statement: ".$sth->{'Statement'}."\n" if($self->{'verbosity'} > 2);
    415418   
    416419    return $sth;
  • main/trunk/greenstone2/perllib/plugins/GreenstoneSQLPlugin.pm

    r32559 r32560  
    374374    # collection name will be used for naming tables (site name will be used for naming database)
    375375    my $gs_sql = new gssql({
    376     'collection_name' => $ENV{'GSDLCOLLECTION'}
     376    'collection_name' => $ENV{'GSDLCOLLECTION'},
     377    'verbosity' => $self->{'verbosity'}
    377378               });
    378379
  • main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm

    r32559 r32560  
    141141
    142142    my $db_params = {
    143     'collection_name' => $ENV{'GSDLCOLLECTION'}
     143    'collection_name' => $ENV{'GSDLCOLLECTION'},
     144    'verbosity' => 1   
    144145    };
    145146
Note: See TracChangeset for help on using the changeset viewer.