d6864c715f90b3ec37e81db09597adc478efd942 max Fri Sep 21 11:28:04 2012 -0700 changes after code review, #9122 diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c index 01d7be5..f30d0be 100644 --- src/hg/hgc/hgc.c +++ src/hg/hgc/hgc.c @@ -874,61 +874,53 @@ { int i; struct dyString *s = newDyString(256), *d = NULL; dyStringAppend(s, orig); for (i=0; istring, in[i], out[i]); dyStringFree(&s); s = d; d = NULL; } return s; } -bool columnExists(struct sqlConnection *conn, char *tableName, char *column) -/* checks if column exists in table */ -{ - char query[1024]; - safef(query, 1024, "SHOW COLUMNS FROM `%s` LIKE '%s'", tableName, column); - char buf[1024]; - char *ret = sqlQuickQuery(conn, query, buf, 1024); - return (ret!=NULL); -} - void printItemDetailsHtml(struct trackDb *tdb, char *itemName) /* if track has an itemDetailsHtml, retrieve and print the HTML */ { char *tableName = trackDbSetting(tdb, "itemDetailsHtmlTable"); if (tableName != NULL) { struct sqlConnection *conn = hAllocConn(database); struct itemDetailsHtml *html, *htmls; - if (columnExists(conn, tableName, "chrom")) + // if the details table has chrom/start/end columns, then use these to lookup html + if (sqlColumnExists(conn, tableName, "chrom")) { char *chrom = cgiString("c"); int start = cgiInt("o"); int end = cgiInt("t"); htmls = sqlQueryObjs(conn, (sqlLoadFunc)itemDetailsHtmlLoad, sqlQueryMulti, "select name, html from %s where \ name = '%s' and \ chrom = '%s' and \ start = '%d' and \ end = '%d'", tableName, itemName, chrom, start, end); } + // otherwise, assume that the itemName is unique else htmls = sqlQueryObjs(conn, (sqlLoadFunc)itemDetailsHtmlLoad, sqlQueryMulti, "select name, html from %s where name = '%s'", tableName, itemName); for (html = htmls; html != NULL; html = html->next) printf("
\n%s\n", html->html); itemDetailsHtmlFreeList(&htmls); hFreeConn(&conn); } } char *getIdInUrl(struct trackDb *tdb, char *itemName) /* If we have an idInUrlSql tag, look up itemName in that, else just * return itemName. */ {