Index: /main/trunk/greenstone2/perllib/gssql.pm
===================================================================
--- /main/trunk/greenstone2/perllib/gssql.pm	(revision 32529)
+++ /main/trunk/greenstone2/perllib/gssql.pm	(revision 32530)
@@ -1,6 +1,6 @@
 ###########################################################################
 #
-# gssql.pm -- DBI for SQL related utility functions used by GreenstoneSQL
-# Plugin and Plugout.
+# gssql.pm -- DBI for SQL related utility functions used by
+# GreenstoneSQLPlugout and hereafter by GreenstoneSQLPlugin too.
 # A component of the Greenstone digital library software
 # from the New Zealand Digital Library Project at the 
@@ -38,9 +38,16 @@
 # Need params_map keys:
 # - collection_name
-# X parameterise: - build_mode
-# For MySQL:
-#  - db_encoding, 
+# - db_encoding (db content encoding) - MySQL can set this at server, db, table levels. For MySQL
+# we set the enc during connect at server level. Not sure whether other DB's support it at the
+# same levels.
+
+# For connection to MySQL, need:
 #  - db_driver, db_client_user, db_client_pwd, db_host, (db_port not used at present)
-# X parameterise: - db_name (which is the GS3 sitename), 
+# So these will be parameterised, but in a hashmap, for just the connect method.
+
+# Parameterise (one or more methods may use them):
+# - build_mode (like removeold)
+# - db_name (which is the GS3 sitename)
+
 # TODO: add infrastructure for db_port, AutoCommit etc
 # For port, see https://stackoverflow.com/questions/2248665/perl-script-to-connect-to-mysql-server-port-3307
@@ -94,15 +101,13 @@
 sub connect_to_db {
     my $self= shift (@_);
-    #my ($db_name) = @_;
-    my $db_driver = $self->{'db_driver'} || "mysql";
-    my $db_user = $self->{'db_client_user'} || "root";
-    my $db_pwd = $self->{'db_client_pwd'}; # even if undef, we'll see a sensible error message
+    my ($params_map) = @_;
+    my $db_enc = $self->{'db_encoding'} || "utf8";
+
+    # these are the params for connecting to MySQL
+    my $db_driver = $params_map->{'db_driver'} || "mysql";
+    my $db_user = $params_map->{'db_client_user'} || "root";
+    my $db_pwd = $params_map->{'db_client_pwd'}; # even if undef, we'll see a sensible error message
                                            # when connect fails
-    my $db_host = $self->{'db_host'} || "127.0.0.1";
-    my $db_enc = $self->{'db_encoding'} || "utf8";
-    
-    # try connecting to the mysql db, if that fails it will die
-    # so don't bother preparing GreenstoneXMLPlugout by calling superclass' begin()
-
+    my $db_host = $params_map->{'db_host'} || "127.0.0.1";
     # localhost doesn't work for us, but 127.0.0.1 works
     # https://metacpan.org/pod/DBD::mysql
@@ -111,5 +116,5 @@
     # on the local machine via TCP, you must specify the loopback IP address (127.0.0.1) as the host."
     #my $connect_str = "dbi:$db_driver:database=$db_name;host=$db_host";
-    my $connect_str = "dbi:$db_driver:host=$db_host"; # don't provide db, so we can check the db is there
+    my $connect_str = "dbi:$db_driver:host=$db_host"; # don't provide db - allows checking the db exists
     my $dbh = DBI->connect("$connect_str", $db_user, $db_pwd,
 			   {
@@ -194,4 +199,5 @@
 # this will terminate if the db does not exist
 # it will not attempt to create the requested db (nor its tables)
+# The upcoming GreenstoneSQLPlugin can use this.
 sub use_db {
     my $self= shift (@_);
Index: /main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm	(revision 32529)
+++ /main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm	(revision 32530)
@@ -119,9 +119,5 @@
 
     my $db_params = {
-	'collection_name' => $ENV{'GSDLCOLLECTION'},
-	'db_driver' => $self->{'db_driver'},
-	'db_client_user' => $self->{'db_client_user'},
-	'db_client_pwd' => $self->{'db_client_pwd'},
-	'db_host' => $self->{'db_host'},
+	'collection_name' => $ENV{'GSDLCOLLECTION'},	
 	'db_encoding' => $self->{'db_encoding'}
 	#'db_name' => $self->{'site_name'},
@@ -131,5 +127,14 @@
     my $gs_sql = new gssql($db_params);
     
-    if(!$gs_sql->connect_to_db()) {
+    # try connecting to the mysql db, if that fails it will die
+    # so don't bother preparing GreenstoneXMLPlugout by calling superclass' begin()
+    if(!$gs_sql->connect_to_db({
+	'db_driver' => $self->{'db_driver'},
+	'db_client_user' => $self->{'db_client_user'},
+	'db_client_pwd' => $self->{'db_client_pwd'},
+	'db_host' => $self->{'db_host'}
+			       })
+	)
+    {
 	# This is fatal for the plugout, let's terminate here
 	# PrintError would already have displayed the warning message on connection fail	
