d911b3e5f6efef0a6e8d210581bbd974beb0dafd
max
  Fri Mar 18 16:11:05 2016 -0700
small modification of previous commit to make sure the correct mysql error message
appears, no redmine

diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c
index 9d7eb90..ea4400e 100644
--- src/hg/lib/jksql.c
+++ src/hg/lib/jksql.c
@@ -99,31 +99,31 @@
     long fetchTime;                     /* cummulative time taken by row fetches for this result */
     };
 
 static struct dlList *sqlOpenConnections = NULL;
 static unsigned sqlNumOpenConnections = 0;
 
 
 char *failoverProfPrefix = "slow-";               // prefix for failover profile of main profile (="slow-db")
 static struct hash *profiles = NULL;              // profiles parsed from hg.conf, by name
 static struct sqlProfile *defaultProfile = NULL;  // default profile, also in profiles list
 static struct hash* dbToProfile = NULL;           // db to sqlProfile
 
 // forward declarations to keep the git diffs clean
 static struct sqlResult *sqlUseOrStore(struct sqlConnection *sc,
 	char *query, ResGetter *getter, boolean abort);
-static void sqlConnectIfUnconnected(struct sqlConnection *sc, bool abort);
+static boolean sqlConnectIfUnconnected(struct sqlConnection *sc, bool abort);
 bool sqlConnMustUseFailover(struct sqlConnection *sc);
 
 static char *envOverride(char *envName, char *defaultVal)
 /* look up envName in environment, if it exists and is non-empty, return its
  * value, otherwise return defaultVal */
 {
 char *val = getenv(envName);
 if (isEmpty(val))
     return defaultVal;
 else
     return val;
 }
 
 char *getDefaultProfileName()
 /* Return default profile name, handling initialization if needed */
@@ -1265,40 +1265,41 @@
 
 sc->profile = sp; // remember the profile
 
 // don't connect the failOver connection yet: lazily connect later when needed
 sc->failoverConn = sqlUnconnectedConn(failoverProf, database);
 return sc;
 }
 
 struct sqlConnection *sqlMayConnect(char *database)
 /* Connect to database on default host as default user.
  * Return NULL (don't abort) on failure. */
 {
 return sqlConnProfile(sqlProfileMustGet(NULL, database), database, FALSE);
 }
 
-static void sqlConnectIfUnconnected(struct sqlConnection *sc, bool abort)
-/* Take a yet unconnected sqlConnection object and connect it to the sql server. */
+static boolean sqlConnectIfUnconnected(struct sqlConnection *sc, bool abort)
+/* Take a yet unconnected sqlConnection object and connect it to the sql server. 
+ * returns TRUE on success, FALSE otherwise. */
 {
 if (sc->conn!=NULL)
-    return;
+    return TRUE;
 char *profName = NULL;
 if (sc->profile)
     profName = sc->profile->name;
 struct sqlProfile *sp = sqlProfileMustGet(profName, sc->db);
-sqlConnRemoteFillIn(sc, sp, sc->db, abort, FALSE);
+return (sqlConnRemoteFillIn(sc, sp, sc->db, abort, FALSE) != NULL);
 }
 
 struct sqlConnection *sqlConnect(char *database)
 /* Connect to database on default host as default user. */
 {
 struct sqlProfile *defProf = sqlProfileMustGet(NULL, database);
 return sqlConnProfile(defProf, database, TRUE);
 }
 
 struct sqlConnection *sqlConnectProfile(char *profileName, char *database)
 /* Connect to profile or database using the specified profile.  Can specify
  * profileName, database, or both. The profile is the prefix to the host,
  * user, and password variables in .hg.conf.  For the default profile of "db",
  * the environment variables HGDB_HOST, HGDB_USER, and HGDB_PASSWORD can
  * override.
@@ -1421,32 +1422,31 @@
 
 sqlConnectIfUnconnected(sc, abort);
 assert(!sc->isFree);
 
 monitorEnter();
 int mysqlError = mysql_real_query(sc->conn, query, strlen(query));
 
 // if the query fails on the main connection, connect the failover connection and try there
 if (mysqlError != 0 && sc->failoverConn && sameWord(sqlGetDatabase(sc), sqlGetDatabase(sc->failoverConn)))
     {
     if (monitorFlags & JKSQL_TRACE)
         monitorPrint(sc, "SQL_FAILOVER", "%s -> %s | %s", scConnProfile(sc),
             scConnProfile(sc->failoverConn), query);
 
     sc = sc->failoverConn;
-    sqlConnectIfUnconnected(sc, FALSE);
-    if (sc->conn)
+    if (sqlConnectIfUnconnected(sc, FALSE))
         mysqlError = mysql_real_query(sc->conn, query, strlen(query));
     else
         // This database does not exist on the (slow-db) failover mysql server
         // It makes more sense to the show the error message we got from our main db
         sc = scMain;
     }
 
 if (mysqlError != 0)
     {
     if (abort)
         {
         monitorLeave();
 	if (sameOk(cfgOption("noSqlInj.dumpStack"), "on"))
     	    dumpStack("DEBUG Can't start query"); // Extra debugging info. DEBUG REMOVE
 	sqlAbort(sc, "Can't start query:\n%s\n", query);
@@ -2518,32 +2518,31 @@
 {
 return (sameOk(database, sqlGetDatabase(scce->conn)));
 }
 
 static int sqlConnChangeDb(struct sqlConnection *sc, char *database, bool mustConnect)
 /* change the db variable of an sqlConnection, try to change the mysql db and
  * return the result code. */
 {
 // update the db variable
 monitorPrint(sc, "SQL_SET_DB", "%s", database);
 freeMem(sc->db);
 sc->db = cloneString(database);
 
 if (mustConnect)
     {
-    sqlConnectIfUnconnected(sc, FALSE);
-    if (sc->conn==NULL)
+    if (!sqlConnectIfUnconnected(sc, FALSE))
         {
         monitorPrint(sc, "SQL_SET_DB_FAILED", "%s", database);
         return -1;
         }
     }
 
 // change the db
 int resCode = 0;
 if (sc->conn)
     {
     resCode = mysql_select_db(sc->conn, database);
     if (resCode!=0)
         monitorPrint(sc, "SQL_SET_DB_ERROR", "%d", resCode);
     }