7c459941c1e589297e0014bf7957599f70836096
hiram
  Thu Apr 4 11:08:18 2019 -0700
moving some SQL functions to jksql.c from hgTables refs #18869 #23233

diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c
index cb94973..b9b3dee 100644
--- src/hg/lib/jksql.c
+++ src/hg/lib/jksql.c
@@ -4368,15 +4368,87 @@
     }
 
 if (sameString(noSqlInjLevel, "warn"))
     {
     vaWarn(format, args);
     }
 
 if (sameString(noSqlInjLevel, "abort"))
     {
     vaErrAbort(format, args);
     }
 
 va_end(args);
 
 }
+
+/* functions moved here from hgTables.c 2019-04-04 - Hiram */
+struct sqlFieldType *sqlFieldTypeNew(char *name, char *type)
+/* Create a new sqlFieldType */
+{
+struct sqlFieldType *ft;
+AllocVar(ft);
+ft->name = cloneString(name);
+ft->type = cloneString(type);
+return ft;
+}
+
+void sqlFieldTypeFree(struct sqlFieldType **pFt)
+/* Free resources used by sqlFieldType */
+{
+struct sqlFieldType *ft = *pFt;
+if (ft != NULL)
+    {
+    freeMem(ft->name);
+    freeMem(ft->type);
+    freez(pFt);
+    }
+}
+
+void sqlFieldTypeFreeList(struct sqlFieldType **pList)
+/* Free a list of dynamically allocated sqlFieldType's */
+{
+struct sqlFieldType *el, *next;
+
+for (el = *pList; el != NULL; el = next)
+    {
+    next = el->next;
+    sqlFieldTypeFree(&el);
+    }
+*pList = NULL;
+}
+
+struct sqlFieldType *sqlFieldTypesFromAs(struct asObject *as)
+/* Convert asObject to list of sqlFieldTypes */
+{
+struct sqlFieldType *ft, *list = NULL;
+struct asColumn *col;
+for (col = as->columnList; col != NULL; col = col->next)
+    {
+    struct dyString *type = asColumnToSqlType(col);
+    ft = sqlFieldTypeNew(col->name, type->string);
+    slAddHead(&list, ft);
+    dyStringFree(&type);
+    }
+slReverse(&list);
+return list;
+}
+
+struct sqlFieldType *sqlListFieldsAndTypes(struct sqlConnection *conn, char *table)
+/* Get list of fields including their names and types.  The type currently is
+ * just a MySQL type string. */
+{
+struct sqlFieldType *ft, *list = NULL;
+char query[512];
+struct sqlResult *sr;
+char **row;
+sqlSafef(query, sizeof(query), "describe %s", table);
+sr = sqlGetResult(conn, query);
+while ((row = sqlNextRow(sr)) != NULL)
+    {
+    ft = sqlFieldTypeNew(row[0], row[1]);
+    slAddHead(&list, ft);
+    }
+sqlFreeResult(&sr);
+slReverse(&list);
+return list;
+}