7b4468f19b6214ffa76aa422ad1ab028750d4e1c galt Tue Jun 5 21:25:38 2012 -0700 fix fix4009 to suport All Tables diff --git src/hg/hgTables/joining.c src/hg/hgTables/joining.c index 6c14dcf..6f95efd 100644 --- src/hg/hgTables/joining.c +++ src/hg/hgTables/joining.c @@ -947,46 +947,66 @@ char *primaryDb, /* The primary database. */ char *primaryTable, /* The primary table. */ FILE *f, /* file for output, null for stdout */ struct slName *fieldList) /* List of db.table.field */ /* Do tab-separated output on selected fields, which may * or may not include multiple tables. */ { struct joinerDtf *dtfList = NULL; struct joinerDtf *filterTables = NULL; boolean doJoin = joinRequired(primaryDb, primaryTable, fieldList, &dtfList, &filterTables); boolean hasIdentifiers = (identifierFileName() != NULL); if (hasIdentifiers) { - boolean hasPrimary = FALSE; + boolean hasTable = FALSE; + char *dtfDb, *dtfTable; + char split[1024]; + /* Choosing the All Tables group and then choosing a db like hgFixed or go + * causes it to inserts a $db. in front of the table name while leaving the primaryDb as the assembly. + * In effect, the table field is sometimes overloaded to carry this extra database for all tables support. */ + char *sep = strchr(primaryTable, '.'); + if (sep) + { + safecpy(split, sizeof split, primaryTable); + sep = strchr(split, '.'); + *sep++ = 0; + dtfDb = split; + dtfTable = sep; + } + else + { + dtfDb = primaryDb; + dtfTable = primaryTable; + } + /* see if we already have the primary table in output fields or filter */ struct joinerDtf *temp; for (temp = dtfList; temp; temp = temp->next) - if (sameString(temp->database, primaryDb) && sameString(temp->table, primaryTable)) - hasPrimary = TRUE; + if (sameString(temp->database, dtfDb) && sameString(temp->table, dtfTable)) + hasTable = TRUE; for (temp = filterTables; temp; temp = temp->next) - if (sameString(temp->database, primaryDb) && sameString(temp->table, primaryTable)) - hasPrimary = TRUE; + if (sameString(temp->database, dtfDb) && sameString(temp->table, dtfTable)) + hasTable = TRUE; /* if primary table is not in output or filter, * add it to the filterTables list to trigger joining and identifier filtering */ - if (!hasPrimary) + if (!hasTable) { struct joinerDtf *dtf; AllocVar(dtf); - dtf->database = cloneString(primaryDb); - dtf->table = cloneString(primaryTable); + dtf->database = cloneString(dtfDb); + dtf->table = cloneString(dtfTable); slAddTail(&filterTables, dtf); doJoin = TRUE; } } if (! doJoin) { struct sqlConnection *conn = hAllocConn(dtfList->database); struct dyString *dy = dyStringNew(0); if (isBigBed(database, dtfList->table, NULL, ctLookupName)) makeBigBedOrderedCommaFieldList(dtfList, dy); else if (isBamTable(dtfList->table)) makeBamOrderedCommaFieldList(dtfList, dy);