Exemplo n.º 1
0
struct machSpec *machSpecLoadWhere(struct sqlConnection *conn, char *table, char *where)
/* Load all machSpec from table that satisfy where clause. The
 * where clause may be NULL in which case whole table is loaded
 * Dispose of this with machSpecFreeList(). */
{
struct machSpec *list = NULL, *el;
struct dyString *query = dyStringNew(256);
struct sqlResult *sr;
char **row;

// should be changed to sqlDyStringPrintf for NOSQLINJ
// but that would perhaps require moving this code to someplace under hg/ ?
dyStringPrintf(query, "select * from %s", table); 
if (where != NULL)
    dyStringPrintf(query, " where %s", where);
sr = sqlGetResult(conn, query->string);
while ((row = sqlNextRow(sr)) != NULL)
    {
    el = machSpecLoad(row);
    slAddHead(&list, el);
    }
slReverse(&list);
sqlFreeResult(&sr);
dyStringFree(&query);
return list;
}
struct machSpec *machSpecLoadAll(char *fileName) 
/* Load all machSpec from a tab-separated file.
 * Dispose of this with machSpecFreeList(). */
{
struct machSpec *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[7];

while (lineFileRow(lf, row))
    {
    el = machSpecLoad(row);
    slAddHead(&list, el);
    }
lineFileClose(&lf);
slReverse(&list);
return list;
}