Example #1
0
void describeFields(char *db, char *table,
                    struct asObject *asObj, struct sqlConnection *conn)
/* Print out an HTML table showing table fields and types, and optionally
 * offering histograms for the text/enum fields. */
{
struct sqlResult *sr;
char **row;
#define TOO_BIG_FOR_HISTO 500000
boolean tooBig = (sqlTableSize(conn, table) > TOO_BIG_FOR_HISTO);
char query[256];
struct slName *exampleList, *example;
boolean showItemRgb = FALSE;

showItemRgb=bedItemRgb(findTdbForTable(db, curTrack, table, ctLookupName));
// should we expect itemRgb instead of "reserved"

sqlSafef(query, sizeof(query), "select * from %s limit 1", table);
exampleList = storeRow(conn, query);
sqlSafef(query, sizeof(query), "describe %s", table);
sr = sqlGetResult(conn, query);

hTableStart();
hPrintf("<TR><TH>field</TH>");
if (exampleList != NULL)
    hPrintf("<TH>example</TH>");
hPrintf("<TH>SQL type</TH> ");
if (!tooBig)
    hPrintf("<TH>info</TH> ");
if (asObj != NULL)
    hPrintf("<TH>description</TH> ");
puts("</TR>\n");
example = exampleList;
while ((row = sqlNextRow(sr)) != NULL)
    {
    if (showItemRgb && (sameWord(row[0],"reserved")))
	hPrintf("<TR><TD><TT>itemRgb</TT></TD> ");
    else
	hPrintf("<TR><TD><TT>%s</TT></TD> ", row[0]);
    if (exampleList != NULL)
        {
	hPrintf("<TD>");
	if (example != NULL)
	     hPrintf("%s", cleanExample(example->name));
	else
	     hPrintf("n/a");
	hPrintf("</TD>");
	}
    // enums/sets with many items can make for painfully wide rows in the table --
    // add spaces between quoted list values:
    if (stringIn("','", row[1]))
	{
	struct dyString *spaced = dyStringSub(row[1], "','", "', '");
	hPrintf("<TD><TT>%s</TT></TD>", spaced->string);
	}
    else
	hPrintf("<TD><TT>%s</TT></TD>", row[1]);
    if (!tooBig)
	{
	hPrintf(" <TD>");
	if ((isSqlStringType(row[1]) && !sameString(row[1], "longblob")) ||
	    isSqlEnumType(row[1]) || isSqlSetType(row[1]))
	    {
	    hPrintf("<A HREF=\"%s", getScriptName());
	    hPrintf("?%s", cartSidUrlString(cart));
	    hPrintf("&%s=%s", hgtaDatabase, db);
	    hPrintf("&%s=%s", hgtaHistoTable, table);
	    hPrintf("&%s=%s", hgtaDoValueHistogram, row[0]);
	    hPrintf("\">");
	    hPrintf("values");
	    hPrintf("</A>");
	    }
	else if (isSqlNumType(row[1]))
	    {
	    hPrintf("<A HREF=\"%s", getScriptName());
	    hPrintf("?%s", cartSidUrlString(cart));
	    hPrintf("&%s=%s", hgtaDatabase, db);
	    hPrintf("&%s=%s", hgtaHistoTable, table);
	    hPrintf("&%s=%s", hgtaDoValueRange, row[0]);
	    hPrintf("\">");
	    hPrintf("range");
	    hPrintf("</A>");
	    }
	else
	    {
	    hPrintf("&nbsp;");
	    }
	hPrintf("</TD>");
	}
    if (asObj != NULL)
        {
	struct asColumn *asCol = asColumnFind(asObj, row[0]);
	hPrintf(" <TD>");
	if (asCol != NULL)
	    hPrintf("%s", asCol->comment);
	else
	    {
	    if (sameString("bin", row[0]))
	       hPrintf("Indexing field to speed chromosome range queries.");
	    else
		hPrintf("&nbsp;");
	    }
	hPrintf("</TD>");
	}
    puts("</TR>");
    if (example != NULL)
	example = example->next;
    }
hTableEnd();
sqlFreeResult(&sr);
}
Example #2
0
static void printSqlFieldListAsControlTable(struct sqlFieldType *ftList, char *db,
	char *rootTable, struct trackDb *tdb, boolean isBedGr)
/* Print out table of controls for fields. */
{
int fieldNum = 0;
int bedGraphColumn = 5;		/*	default score column	*/
int noBinBedGraphColumn = bedGraphColumn;
boolean gotFirst = FALSE;
struct sqlFieldType *ft;
hPrintf("<TABLE BORDER=0>\n");
for (ft = ftList; ft != NULL; ft = ft->next)
    {
    char *field = ft->name;
    char *type = ft->type;
    char *logic = "";

    if ((0 == fieldNum) && (!sameWord(field,"bin")))
	noBinBedGraphColumn -= 1;
    if (!sameWord(type, "longblob"))
	{
	if (!gotFirst)
	    gotFirst = TRUE;
	else if (!isBedGr)
	    logic = " AND ";
	}
    if (!isBedGr || (noBinBedGraphColumn == fieldNum))
	{
	if (isSqlEnumType(type) || isSqlSetType(type))
	    {
	    enumFilterOption(db, rootTable, field, type, logic);
	    }
	else if(isSqlIntType(type))
	    {
	    integerFilter(db, rootTable, field, field, logic);
	    }
	else if(isSqlNumType(type))
	    {
	    if(isBedGr)
		{
		double min, max;
		double tDbMin, tDbMax;

		wigFetchMinMaxLimits(tdb, &min, &max, &tDbMin, &tDbMax);
		if (tDbMin < min)
		    min = tDbMin;
		if (tDbMax > max)
		    max = tDbMax;
		numericFilterWithLimits(db, rootTable, field, field, min, max, logic);
		hPrintf("<TR><TD COLSPAN=3 ALIGN=RIGHT> (%s range: [%g:%g]) "
		    "</TD></TR>\n", field, min, max);
		}
	    else
		{
		numericFilter(db, rootTable, field, field, logic);
		}
	    }
	else //if (isSqlStringType(type))
	    {
	    stringFilterOption(db, rootTable, field, logic);
	    }
	}
    ++fieldNum;
    }
hPrintf("</TABLE>\n");
}