Changeset 32530 for main/trunk
- Timestamp:
- 2018-10-19T20:54:17+13:00 (6 years ago)
- Location:
- main/trunk/greenstone2/perllib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/gssql.pm
r32529 r32530 1 1 ########################################################################### 2 2 # 3 # gssql.pm -- DBI for SQL related utility functions used by GreenstoneSQL4 # Plugin and Plugout.3 # gssql.pm -- DBI for SQL related utility functions used by 4 # GreenstoneSQLPlugout and hereafter by GreenstoneSQLPlugin too. 5 5 # A component of the Greenstone digital library software 6 6 # from the New Zealand Digital Library Project at the … … 38 38 # Need params_map keys: 39 39 # - collection_name 40 # X parameterise: - build_mode 41 # For MySQL: 42 # - db_encoding, 40 # - db_encoding (db content encoding) - MySQL can set this at server, db, table levels. For MySQL 41 # we set the enc during connect at server level. Not sure whether other DB's support it at the 42 # same levels. 43 44 # For connection to MySQL, need: 43 45 # - db_driver, db_client_user, db_client_pwd, db_host, (db_port not used at present) 44 # X parameterise: - db_name (which is the GS3 sitename), 46 # So these will be parameterised, but in a hashmap, for just the connect method. 47 48 # Parameterise (one or more methods may use them): 49 # - build_mode (like removeold) 50 # - db_name (which is the GS3 sitename) 51 45 52 # TODO: add infrastructure for db_port, AutoCommit etc 46 53 # For port, see https://stackoverflow.com/questions/2248665/perl-script-to-connect-to-mysql-server-port-3307 … … 94 101 sub connect_to_db { 95 102 my $self= shift (@_); 96 #my ($db_name) = @_; 97 my $db_driver = $self->{'db_driver'} || "mysql"; 98 my $db_user = $self->{'db_client_user'} || "root"; 99 my $db_pwd = $self->{'db_client_pwd'}; # even if undef, we'll see a sensible error message 103 my ($params_map) = @_; 104 my $db_enc = $self->{'db_encoding'} || "utf8"; 105 106 # these are the params for connecting to MySQL 107 my $db_driver = $params_map->{'db_driver'} || "mysql"; 108 my $db_user = $params_map->{'db_client_user'} || "root"; 109 my $db_pwd = $params_map->{'db_client_pwd'}; # even if undef, we'll see a sensible error message 100 110 # when connect fails 101 my $db_host = $self->{'db_host'} || "127.0.0.1"; 102 my $db_enc = $self->{'db_encoding'} || "utf8"; 103 104 # try connecting to the mysql db, if that fails it will die 105 # so don't bother preparing GreenstoneXMLPlugout by calling superclass' begin() 106 111 my $db_host = $params_map->{'db_host'} || "127.0.0.1"; 107 112 # localhost doesn't work for us, but 127.0.0.1 works 108 113 # https://metacpan.org/pod/DBD::mysql … … 111 116 # on the local machine via TCP, you must specify the loopback IP address (127.0.0.1) as the host." 112 117 #my $connect_str = "dbi:$db_driver:database=$db_name;host=$db_host"; 113 my $connect_str = "dbi:$db_driver:host=$db_host"; # don't provide db , so we can check the db is there118 my $connect_str = "dbi:$db_driver:host=$db_host"; # don't provide db - allows checking the db exists 114 119 my $dbh = DBI->connect("$connect_str", $db_user, $db_pwd, 115 120 { … … 194 199 # this will terminate if the db does not exist 195 200 # it will not attempt to create the requested db (nor its tables) 201 # The upcoming GreenstoneSQLPlugin can use this. 196 202 sub use_db { 197 203 my $self= shift (@_); -
main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm
r32529 r32530 119 119 120 120 my $db_params = { 121 'collection_name' => $ENV{'GSDLCOLLECTION'}, 122 'db_driver' => $self->{'db_driver'}, 123 'db_client_user' => $self->{'db_client_user'}, 124 'db_client_pwd' => $self->{'db_client_pwd'}, 125 'db_host' => $self->{'db_host'}, 121 'collection_name' => $ENV{'GSDLCOLLECTION'}, 126 122 'db_encoding' => $self->{'db_encoding'} 127 123 #'db_name' => $self->{'site_name'}, … … 131 127 my $gs_sql = new gssql($db_params); 132 128 133 if(!$gs_sql->connect_to_db()) { 129 # try connecting to the mysql db, if that fails it will die 130 # so don't bother preparing GreenstoneXMLPlugout by calling superclass' begin() 131 if(!$gs_sql->connect_to_db({ 132 'db_driver' => $self->{'db_driver'}, 133 'db_client_user' => $self->{'db_client_user'}, 134 'db_client_pwd' => $self->{'db_client_pwd'}, 135 'db_host' => $self->{'db_host'} 136 }) 137 ) 138 { 134 139 # This is fatal for the plugout, let's terminate here 135 140 # PrintError would already have displayed the warning message on connection fail
Note:
See TracChangeset
for help on using the changeset viewer.