void tagStormQueryMain(char *query) /* tagStormQuery - Find stanzas in tag storm based on SQL-like query.. */ { /* Get parsed out query */ struct lineFile *lf = lineFileOnString("query", TRUE, cloneString(query)); struct rqlStatement *rql = rqlStatementParse(lf); int stormCount = slCount(rql->tableList); if (stormCount != 1) errAbort("Can only handle one tag storm file in query, got %d", stormCount); char *tagsFileName = rql->tableList->name; /* Read in tags */ struct tagStorm *tags = tagStormFromFile(tagsFileName); /* Expand any field names with wildcards. */ struct slName *allFieldList = tagStormFieldList(tags); rql->fieldList = wildExpandList(allFieldList, rql->fieldList, TRUE); /* Traverse tree applying query */ struct lm *lm = lmInit(0); doSelect = sameWord(rql->command, "select"); traverse(tags, tags->forest, rql, lm); tagStormFree(&tags); if (sameWord(rql->command, "count")) printf("%d\n", matchCount); }
void cdwQuery(char *rqlQuery) /* cdwQuery - Get list of tagged files.. */ { /* Turn rqlQuery string into a parsed out rqlStatement. */ struct rqlStatement *rql = rqlStatementParseString(rqlQuery); /* Load tags from database */ struct sqlConnection *conn = cdwConnect(); struct tagStorm *tags = cdwTagStorm(conn); /* Get list of all tag types in tree and use it to expand wildcards in the query * field list. */ struct slName *allFieldList = tagStormFieldList(tags); slSort(&allFieldList, slNameCmp); rql->fieldList = wildExpandList(allFieldList, rql->fieldList, TRUE); /* Output header row in tab case */ if (sameString(clOut, "tab")) { char before = '#'; struct slName *field; for (field = rql->fieldList; field != NULL; field = field->next) { printf("%c%s", before, field->name); before = '\t'; } printf("\n"); } /* Traverse tag tree outputting when rql statement matches in select case, just * updateing count in count case. */ doSelect = sameWord(rql->command, "select"); struct lm *lm = lmInit(0); traverse(0, tags, tags->forest, rql, lm); if (sameWord(rql->command, "count")) printf("%d\n", matchCount); /* Clean up and go home. */ tagStormFree(&tags); }