ee577cf4b9e53dad528b79377c679bff5f2f937d
max
  Fri Mar 18 15:34:42 2016 -0700
use local error message if database does not exist on mysql failover
connection. No redmine, bug report received from Jim.

diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c
index 269c6ce..9d7eb90 100644
--- src/hg/lib/jksql.c
+++ src/hg/lib/jksql.c
@@ -1378,30 +1378,31 @@
 }
 
 static struct sqlResult *sqlUseOrStore(struct sqlConnection *sc,
 	char *query, ResGetter *getter, boolean abort)
 /* Returns NULL if result was empty and getter==mysql_use_result.
  * Otherwise returns a structure that you can do sqlRow() on.
  * Watch out for subtle differences between mysql_store_result and mysql_use_result.
  * We seem to be only using mysql_use_result these days,
  * but mysql_store_result has left a big footprint in the code/comments.
  * In particular, mysql_store_result can return NULL indicating an empty resultset.
  * But mysql_use_result cannot do that. Instead NULL return means error
  * and the user must call next_row to see if there's anything in the resultset.
  */
 {
 struct sqlResult *res = NULL;
+struct sqlConnection *scMain = sc;
 long deltaTime;
 boolean fixedMultipleNOSQLINJ = FALSE;
 
 ++sqlTotalQueries;
 
 if (monitorFlags & JKSQL_TRACE)
     monitorPrintQuery(sc, query);
 
 if (startsWith(NOSQLINJ "", query))
     {
     query += strlen(NOSQLINJ ""); // We know this query has been vetted for sql injection, skip over this tag.
     }
 else
     {
     sqlCheckError("Unvetted query: %s", query);
@@ -1420,32 +1421,37 @@
 
 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, TRUE);
+    sqlConnectIfUnconnected(sc, FALSE);
+    if (sc->conn)
         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);
         }
     }
 else
     {
     MYSQL_RES *resSet;