d6690c5c304e3b0cf43f8199abb8fd08ad32a6e6
kent
  Fri Feb 20 15:30:52 2015 -0800
Added functions to get all fields associated with a sqlResult as a slName list or as an array of char *'s.

diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c
index e4a341c..60f0039 100644
--- src/hg/lib/jksql.c
+++ src/hg/lib/jksql.c
@@ -1830,30 +1830,56 @@
     sqlAbort(sr->conn, "nextRow failed");
 return row;
 }
 
 char* sqlFieldName(struct sqlResult *sr)
 /* repeated calls to this function returns the names of the fields
  * the given result */
 {
 MYSQL_FIELD *field;
 field = mysql_fetch_field(sr->result);
 if(field == NULL)
     return NULL;
 return field->name;
 }
 
+struct slName *sqlResultFieldList(struct sqlResult *sr)
+/* Return slName list of all fields in query.  Can just be done once per query. */
+{
+struct slName *list = NULL;
+char *field;
+while ((field = sqlFieldName(sr)) != NULL)
+    slNameAddHead(&list, field);
+slReverse(&list);
+return list;
+}
+
+int sqlResultFieldArray(struct sqlResult *sr, char ***retArray)
+/* Get the fields of sqlResult,  returning count, and the results
+ * themselves in *retArray. */
+{
+struct slName *el, *list = sqlResultFieldList(sr);
+int count = slCount(list);
+char **array;
+AllocArray(array, count);
+int i;
+for (el=list,i=0; el != NULL; el = el->next, ++i)
+    array[i] = cloneString(el->name);
+*retArray = array;
+return count;
+}
+
 int sqlFieldColumn(struct sqlResult *sr, char *colName)
 /* get the column number of the specified field in the result, or
  * -1 if the result doesn't contailed the field.*/
 {
 int numFields = mysql_num_fields(sr->result);
 int i;
 for (i = 0; i < numFields; i++)
     {
     MYSQL_FIELD *field = mysql_fetch_field_direct(sr->result, i);
     if (sameString(field->name, colName))
         return i;
     }
 return -1;
 }