d77912f2c1142e295dacfffb3fa1d36ff45e95b5
chmalee
  Mon May 11 10:10:53 2020 -0700
Fix sqlDescribe to still find table description if a table does not exist in the table cache, refs #25536

diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c
index 53a020b..1ad9a7a 100644
--- src/hg/lib/jksql.c
+++ src/hg/lib/jksql.c
@@ -964,46 +964,50 @@
     slSortMergeUniq(&list, failoverList, slNameCmp, slNameFree);
     }
 
 return list;
 }
 
 struct slName *sqlListTables(struct sqlConnection *sc)
 /* Return list of tables in database associated with conn. */
 {
 return sqlListTablesLike(sc, NULL);
 }
 
 struct sqlResult *sqlDescribe(struct sqlConnection *conn, char *table)
 /* run the sql DESCRIBE command or get a cached table description and return the sql result */
 {
-char query[1024];
+char query[1024], cacheQuery[1024];
+struct sqlResult *sr;
 
 struct sqlConnection *cacheConn = sqlTableCacheFindConn(conn);
+sqlSafef(query, sizeof(query), "DESCRIBE %s", table);
 
 if (cacheConn)
     {
     char *tableListTable = cfgVal("showTableCache");
-    sqlSafef(query, sizeof(query), "SELECT Field, Type, NullAllowed, isKey, hasDefault, Extra FROM %s WHERE tableName='%s'", \
+    sqlSafef(cacheQuery, sizeof(cacheQuery), "SELECT Field, Type, NullAllowed, isKey, hasDefault, Extra FROM %s WHERE tableName='%s'", \
         tableListTable, table);
     conn = cacheConn;
+    // check that entries actually exist in the cached table descriptions, otherwise
+    // use the default query
+    if (sqlQuickString(conn, cacheQuery) != NULL)
+        {
+        sr = sqlGetResult(conn, cacheQuery);
+        return sr;
+        }
     }
-
-else
-    sqlSafef(query, sizeof(query), "DESCRIBE %s", table);
-
-struct sqlResult *sr;
 sr = sqlGetResult(conn, query);
 return sr;
 }
 
 struct slName *sqlListFields(struct sqlConnection *conn, char *table)
 /* Return list of fields in table. */
 {
 char **row;
 struct slName *list = NULL, *el;
 struct sqlResult *sr = NULL;
 sr = sqlDescribe(conn, table);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     el = slNameNew(row[0]);
     slAddHead(&list, el);