060ada2535fca719656219c1214a3e1c16490693
tdreszer
  Wed Nov 9 16:06:41 2011 -0800
Moved as code in hgTables down to lib and access it from hgc and hgTrackUi.  This is to remove 'extraFields' support as per Jim's request in redmine 5883 and 5582
diff --git src/hg/hgTables/schema.c src/hg/hgTables/schema.c
index 8afbb25..c72b5bf 100644
--- src/hg/hgTables/schema.c
+++ src/hg/hgTables/schema.c
@@ -528,34 +528,33 @@
     webNewSection("Sample Rows");
     printSampleRows(10, conn, ct->dbTableName);
     printTrackHtml(ct->tdb);
     hFreeConn(&conn);
     }
 else
     {
     webNewSection("Sample Rows");
     hPrintf("<TT><PRE>");
     for(bed = ct->bedList;bed != NULL && count < 10;bed = bed->next,++count)
 	bedTabOutN(bed, ct->fieldCount, stdout);
     hPrintf("</PRE></TT>\n");
     }
 }
 
-static void showSchemaWithAutoSqlString(char *db, char *trackId, struct customTrack *ct, char *autoSqlString)
+static void showSchemaWithAsObj(char *db, char *trackId, struct customTrack *ct, struct asObject *asObj)
 /* Show schema on custom track using autoSqlString defined for this track type. */
 {
-struct asObject *asObj = asParseText(autoSqlString);
 struct sqlConnection *conn = hAllocConn(CUSTOM_TRASH);
 char *table = ct->dbTableName;
 
 hPrintf("<B>Genome Database:</B> %s ", db);
 hPrintf("<B>Track ID:</B> %s ", trackId);
 hPrintf("<B>MySQL table:</B> %s", table);
 hPrintf("&nbsp;&nbsp;&nbsp;&nbsp;<B>Row Count:</B> ");
 printLongWithCommas(stdout, sqlTableSize(conn, table));
 hPrintf("<BR>\n");
 if (asObj != NULL)
     hPrintf("<B>Format description:</B> %s<BR>", asObj->comment);
 describeFields(CUSTOM_TRASH, table, asObj, conn);
 
 webNewSection("Sample Rows");
 printSampleRows(10, conn, ct->dbTableName);
@@ -567,35 +566,47 @@
 /* Show schema on custom track. */
 {
 struct customTrack *ct = ctLookupName(table);
 char *type = ct->tdb->type;
 if (startsWithWord("wig", type) || startsWithWord("bigWig", type))
     showSchemaCtWiggle(table, ct);
 else if (startsWithWord("chromGraph", type))
     showSchemaCtChromGraph(table, ct);
 else if (startsWithWord("bed", type) || startsWithWord("bedGraph", type))
     showSchemaCtBed(table, ct);
 else if (startsWithWord("maf", type))
     showSchemaCtMaf(table, ct);
 else if (startsWithWord("array", type))
     showSchemaCtArray(table, ct);
 else if (startsWithWord("makeItems", type))
-    showSchemaWithAutoSqlString(db, table, ct, makeItemsItemAutoSqlString);
+    {
+    struct asObject *asObj = makeItemsItemAsObj();
+    showSchemaWithAsObj(db, table, ct, asObj);
+    asObjectFree(&asObj);
+    }
 else if (sameWord("bedDetail", type))
-    showSchemaWithAutoSqlString(db, table, ct, bedDetailAutoSqlString);
+    {
+    struct asObject *asObj = bedDetailAsObj();
+    showSchemaWithAsObj(db, table, ct, asObj);
+    asObjectFree(&asObj);
+    }
 else if (sameWord("pgSnp", type))
-    showSchemaWithAutoSqlString(db, table, ct, pgSnpAutoSqlString);
+    {
+    struct asObject *asObj = pgSnpAsObj();
+    showSchemaWithAsObj(db, table, ct, asObj);
+    asObjectFree(&asObj);
+    }
 else
     errAbort("Unrecognized customTrack type %s", type);
 }
 
 static void showSchemaHub(char *db, char *table)
 /* Show schema on a hub track. */
 {
 struct trackDb *tdb = hashMustFindVal(fullTrackAndSubtrackHash, table);
 char *type = cloneFirstWord(tdb->type);
 hPrintf("Binary file of type %s stored at %s<BR>\n",
 	type, trackDbSetting(tdb, "bigDataUrl"));
 if (sameString(type, "bigBed"))
     showSchemaBigBed(table);
 else if (sameString(type, "bam"))
     showSchemaBam(table);
@@ -672,15 +683,45 @@
 void doSchema(struct sqlConnection *conn)
 /* Show schema around current track. */
 {
 if (curTrackDescribesCurTable())
     {
     struct trackDb *track = curTrack;
     char *table = connectingTableForTrack(curTable);
     htmlOpen("Schema for %s - %s", track->shortLabel, track->longLabel);
     showSchema(database, curTrack, table);
     htmlClose();
     }
 else
     doTableSchema(database, curTable, conn);
 }
 
+struct asObject *asForTable(struct sqlConnection *conn, char *table)
+/* Get autoSQL description if any associated with table. */
+/* Wrap some error catching around asForTable. */
+{
+struct trackDb *tdb = NULL;
+if (isCustomTrack(table))  // Why isn't custom track in fullTrackAndSubtrackHash?
+    {
+    struct customTrack *ct = ctLookupName(table);
+    tdb = ct->tdb;
+    }
+else
+    tdb = hashMustFindVal(fullTrackAndSubtrackHash, table);
+return asForTdb(conn,tdb);
+}
+
+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;
+}