8cb246c12905b1fa1cf17b96c0539cdb936d24e9 tdreszer Tue Nov 15 12:19:08 2011 -0800 Since hgTables sometimes displays a schema for a table that is not a track, I had to bring back the earlier code that does not require a tdb. This fixes redmine 5990. diff --git src/hg/hgTables/schema.c src/hg/hgTables/schema.c index 810b350..f4e3513 100644 --- src/hg/hgTables/schema.c +++ src/hg/hgTables/schema.c @@ -12,30 +12,31 @@ #include "hdb.h" #include "web.h" #include "trackDb.h" #include "joiner.h" #include "tableDescriptions.h" #include "asParse.h" #include "customTrack.h" #include "bedCart.h" #include "hgMaf.h" #include "hgTables.h" #include "wikiTrack.h" #include "makeItemsItem.h" #include "bedDetail.h" #include "pgSnp.h" #include "hubConnect.h" +#include "errCatch.h" static char const rcsid[] = "$Id: schema.c,v 1.66 2010/06/07 16:53:10 angie Exp $"; static char *nbForNothing(char *val) /* substitute   for empty strings to keep table formating sane */ { char *s = skipLeadingSpaces(val); if ((s == NULL) || (s[0] == '\0')) return " "; else return val; } static char *abbreviateInPlace(char *val, int len) /* Abbreviate a string to len characters. */ @@ -673,55 +674,88 @@ for (tdbRef = tdbRefList; tdbRef != NULL; tdbRef = tdbRef->next) { struct trackDb *sTdb = tdbRef->val; if (sameString(sTdb->table, curTable)) return TRUE; } } return FALSE; } void doSchema(struct sqlConnection *conn) /* Show schema around current track. */ { if (curTrackDescribesCurTable()) { - struct trackDb *track = curTrack; - if (!hashFindVal(fullTrackAndSubtrackHash, track->table)) - hashAdd(fullTrackAndSubtrackHash, track->table, track); char *table = connectingTableForTrack(curTable); - htmlOpen("Schema for %s - %s", track->shortLabel, track->longLabel); + if (!isCustomTrack(table) && !hashFindVal(fullTrackAndSubtrackHash, table)) + hashAdd(fullTrackAndSubtrackHash, table, curTrack); + htmlOpen("Schema for %s - %s", curTrack->shortLabel, curTrack->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); + tdb = hashFindVal(fullTrackAndSubtrackHash, table); +if (tdb != NULL) return asForTdb(conn,tdb); + +// Some cases are for tables with no tdb! +struct asObject *asObj = NULL; +if (sqlTableExists(conn, "tableDescriptions")) + { + struct errCatch *errCatch = errCatchNew(); + if (errCatchStart(errCatch)) + { + char query[256]; + + safef(query, sizeof(query), + "select autoSqlDef from tableDescriptions where tableName='%s'", + table); + char *asText = asText = sqlQuickString(conn, query); + + // If no result try split table. (not likely) + if (asText == NULL) + { + safef(query, sizeof(query), + "select autoSqlDef from tableDescriptions where tableName='chrN_%s'", + table); + asText = sqlQuickString(conn, query); + } + if (asText != NULL && asText[0] != 0) + { + asObj = asParseText(asText); + } + freez(&asText); + } + errCatchEnd(errCatch); + errCatchFree(&errCatch); + } +return asObj; } 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);