aacc5c3c0cd83cd6303acd1924630b34d132a399
galt
  Wed Aug 5 20:12:06 2015 -0700
adding db field to sqlProfile just in case it is useful.

diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c
index c7b9954..4135086 100644
--- src/hg/lib/jksql.c
+++ src/hg/lib/jksql.c
@@ -45,30 +45,31 @@
 
 /* statistics */
 static unsigned totalNumConnects = 0;
 static unsigned maxNumConnections = 0;
 
 struct sqlProfile
 /* a configuration profile for connecting to a server */
 {
     struct sqlProfile *next;
     char *name;         // name of profile
     char *host;         // host name for database server
     unsigned int port;  // port for database server
     char *socket;       // unix-domain socket path for database server
     char *user;         // database server user name
     char *password;     // database server password
+    char *db;           // database if specified in config
     struct slName *dbs; // database associated with profile, can be NULL.
     // ssl
     char *key;       // path to ssl client key.pem
     char *cert;      // path to ssl client cert.pem
     char *ca;        // path to ssl certificate authority ca.pem
     char *caPath;    // path to directory containing ssl .pem certs (only OpenSSL)
     char *cipher;    // list of permissible ciphers to use
     char *crl;       // path to file containing certificate revocation lists in PEM format
     char *crlPath;   // path to directory containing crl files (only OpenSSL)
     char *verifyServerCert;  // Client will check server cert Subject CN={host}
                              //  Boolean connection flag, if NON-NULL and != "0" then it is on.
     };
 
 struct sqlConnection
 /* This is an item on a list of sql open connections. */
@@ -123,30 +124,31 @@
 else
     return val;
 }
 
 static struct sqlProfile *sqlProfileClone(struct sqlProfile *o)
 /* clone profile object (does not include ->dbs) */
 {
 struct sqlProfile *sp;
 AllocVar(sp);
 sp->name     = cloneString(o->name);
 sp->host     = cloneString(o->host);
 sp->port     = o->port;
 sp->socket   = cloneString(o->socket);
 sp->user     = cloneString(o->user);
 sp->password = cloneString(o->password);
+sp->db       = cloneString(o->db);
 sp->key      = cloneString(o->key);
 sp->cert     = cloneString(o->cert);
 sp->ca       = cloneString(o->ca);
 sp->caPath   = cloneString(o->caPath);
 sp->cipher   = cloneString(o->cipher);
 sp->crl      = cloneString(o->crl);
 sp->crlPath  = cloneString(o->crlPath);
 sp->verifyServerCert = cloneString(o->verifyServerCert);
 return sp;
 }
 
 struct sqlProfile *sqlProfileFromPairs(struct slPair *pairs)
 /* create a new profile object (does not include ->dbs) */
 {
 struct sqlProfile *sp;
@@ -155,30 +157,32 @@
 for(p=pairs; p; p=p->next)
     {
     char *value = (char *)p->val;
     if (sameString(p->name,"name"))
 	sp->name = cloneString(value);
     if (sameString(p->name,"host"))
 	sp->host = cloneString(value);
     if (sameString(p->name,"port"))
 	sp->port = atoi(value);
     if (sameString(p->name,"socket"))
 	sp->socket = cloneString(value);
     if (sameString(p->name,"user"))
 	sp->user = cloneString(value);
     if (sameString(p->name,"password"))
 	sp->password = cloneString(value);
+    if (sameString(p->name,"db"))
+	sp->db = cloneString(value);
     if (sameString(p->name,"key"))
 	sp->key = cloneString(value);
     if (sameString(p->name,"cert"))
 	sp->cert = cloneString(value);
     if (sameString(p->name,"ca"))
 	sp->ca = cloneString(value);
     if (sameString(p->name,"caPath"))
 	sp->caPath = cloneString(value);
     if (sameString(p->name,"cipher"))
 	sp->cipher = cloneString(value);
     if (sameString(p->name,"crl"))
 	sp->crl = cloneString(value);
     if (sameString(p->name,"crlPath"))
 	sp->crlPath = cloneString(value);
     if (sameString(p->name,"verifyServerCert"))
@@ -208,74 +212,77 @@
 {
 hashAdd(profiles, sp->name, sp);
 if (sameString(sp->name, defaultProfileName))
     defaultProfile = sp;  // save default
 }
 
 static void sqlProfileAddProfIf(char *profileName)
 /* check if a config prefix is a profile, and if so, add a
  * sqlProfile object for it if doesn't already exist. */
 {
 char *host = cfgOption2(profileName, "host");
 char *portstr = cfgOption2(profileName, "port");
 char *socket = cfgOption2(profileName, "socket");
 char *user = cfgOption2(profileName, "user");
 char *password = cfgOption2(profileName, "password");
+char *db = cfgOption2(profileName, "db");
 // ssl
 char *key = cfgOption2(profileName, "key");
 char *cert = cfgOption2(profileName, "cert");
 char *ca = cfgOption2(profileName, "ca");
 char *caPath = cfgOption2(profileName, "caPath");
 char *cipher = cfgOption2(profileName, "cipher");
 char *crl = cfgOption2(profileName, "crl");
 char *crlPath = cfgOption2(profileName, "crlPath");
 char *verifyServerCert = cfgOption2(profileName, "verifyServerCert");
 
 unsigned int port = 0;
 
 if ((host != NULL) && (user != NULL) && (password != NULL) && (hashLookup(profiles, profileName) == NULL))
     {
     /* for the default profile, allow environment variable override */
     if (sameString(profileName, defaultProfileName))
         {
         host     = envOverride("HGDB_HOST", host);
         portstr  = envOverride("HGDB_PORT", portstr);
         socket   = envOverride("HGDB_SOCKET", socket);
         user     = envOverride("HGDB_USER", user);
         password = envOverride("HGDB_PASSWORD", password);
+        db       = envOverride("HGDB_DB", db);
 	// ssl
 	key      = envOverride("HGDB_KEY", key);
 	cert     = envOverride("HGDB_CERT", cert);
 	ca       = envOverride("HGDB_CA", ca);
 	caPath   = envOverride("HGDB_CAPATH", caPath);
 	cipher   = envOverride("HGDB_CIPHER", cipher);
 	crl      = envOverride("HGDB_CRL", crl);
 	crlPath  = envOverride("HGDB_CRLPATH", crlPath);
 	verifyServerCert = envOverride("HGDB_VERIFY_SERVER_CERT", verifyServerCert);
         }
 
     if (portstr != NULL)
 	port = atoi(portstr);
 
     struct sqlProfile *sp;
     AllocVar(sp);
     sp->name     = cloneString(profileName);
     sp->host     = cloneString(host);
     sp->port     = port;
     sp->socket   = cloneString(socket);
     sp->user     = cloneString(user);
     sp->password = cloneString(password);
+    sp->db       = cloneString(db);
     sp->key      = cloneString(key);
     sp->cert     = cloneString(cert);
     sp->ca       = cloneString(ca);
     sp->caPath   = cloneString(caPath);
     sp->cipher   = cloneString(cipher);
     sp->crl      = cloneString(crl);
     sp->crlPath  = cloneString(crlPath);
     sp->verifyServerCert = cloneString(verifyServerCert);
     sqlProfileCreate(sp);
     }
 }
 
 static void sqlProfileAddProfs(struct slName *cnames)
 /* load the profiles from list of config names */
 {
@@ -435,30 +442,31 @@
 
 void sqlProfileConfig(struct slPair *pairs)
 /* Set configuration for the profile.  This overrides an existing profile in
  * hg.conf or defines a new one.  Results are unpredictable if a connect cache
  * has been established for this profile. */
 {
 struct sqlProfile *spIn = sqlProfileFromPairs(pairs);
 struct sqlProfile *sp = sqlProfileGet(spIn->name, NULL);
 if (sp == NULL)
     return sqlProfileCreate(spIn);
 replaceStr(&sp->host,     spIn->host);
 replaceStr(&sp->socket,   spIn->socket);
 sp->port = spIn->port;
 replaceStr(&sp->user,     spIn->user);
 replaceStr(&sp->password, spIn->password);
+replaceStr(&sp->db,       spIn->db);
 replaceStr(&sp->key,      spIn->key);
 replaceStr(&sp->cert,     spIn->cert);
 replaceStr(&sp->ca,       spIn->ca);
 replaceStr(&sp->caPath,   spIn->caPath);
 replaceStr(&sp->cipher,   spIn->cipher);
 replaceStr(&sp->crl,      spIn->crl);
 replaceStr(&sp->crlPath,  spIn->crlPath);
 replaceStr(&sp->verifyServerCert, spIn->verifyServerCert);
 }
 
 void sqlProfileConfigDefault(struct slPair *pairs)
 /* Set configuration for the default profile.  This overrides an existing
  * profile in hg.conf or defines a new one.  Results are unpredictable if a
  * connect cache has been established for this profile. */
 {
@@ -473,30 +481,32 @@
 char *sqlProfileToMyCnf(char *profileName)
 /* Read in profile named, 
  * and create a multi-line setting string usable in my.cnf files.  
  * Return Null if profile not found. */
 {
 struct sqlProfile *sp = sqlProfileGet(profileName, NULL);
 if (!sp)
     return NULL;
 struct dyString *dy = dyStringNew(256);
 if (sp->host)
     dyStringPrintf(dy, "host=%s\n", sp->host);
 if (sp->user)
     dyStringPrintf(dy, "user=%s\n", sp->user);
 if (sp->password)
     dyStringPrintf(dy, "password=%s\n", sp->password);
+if (sp->password)
+    dyStringPrintf(dy, "database=%s\n", sp->db);
 if (sp->port)
     dyStringPrintf(dy, "port=%d\n", sp->port);
 if (sp->socket)
     dyStringPrintf(dy, "socket=%s\n", sp->socket);
 if (sp->key)
     dyStringPrintf(dy, "ssl-key=%s\n", sp->key);
 if (sp->cert)
     dyStringPrintf(dy, "ssl-cert=%s\n", sp->cert);
 if (sp->ca)
     dyStringPrintf(dy, "ssl-ca=%s\n", sp->ca);
 if (sp->caPath)
     dyStringPrintf(dy, "ssl-capath=%s\n", sp->caPath);
 if (sp->cipher)
     dyStringPrintf(dy, "ssl-cipher=%s\n", sp->cipher);
 if (mysql_get_client_version() >= 50603) // mysql version "5.6.3"