3e6c9b3323a9875d9163e6f4fc28c35c92717985 kent Fri Sep 6 14:07:07 2019 -0700 Making it optionally tolerate missing files in the command line without complaint. diff --git src/hg/sqlUpdateRelated/sqlUpdateRelated.c src/hg/sqlUpdateRelated/sqlUpdateRelated.c index c7d20e9..84adbd0 100644 --- src/hg/sqlUpdateRelated/sqlUpdateRelated.c +++ src/hg/sqlUpdateRelated/sqlUpdateRelated.c @@ -7,36 +7,37 @@ #include "options.h" #include "fieldedTable.h" #include "csv.h" #include "jksql.h" void usage() /* Explain usage and exit. */ { errAbort( "sqlUpdateRelated - Update a bunch of tables in a kind of careful way based out of tab \n" "separated files. Handles foreign key and many-to-many relationships with a multitude\n" "of @ signs. Currently only works with mysql cause going through jksql\n" "usage:\n" " sqlUpdateRelated database tableFiles\n" "options:\n" - " -xxx=XXX\n" + " -missOk - if set, tableFiles mentioned that don't exist are skipped rather than erroring\n" ); } /* Command line validation table. */ static struct optionSpec options[] = { + {"missOk", TRUE}, {NULL, 0}, }; struct foreignRef /* What we need to handle a foreign key reference */ { struct foreignRef *next; // Next in list char *nativeFieldName; // Name in the current table char *foreignTable; // Foreign table name char *foreignFindName; // Name to search in the destination table char *foreignKeyName; // Name of key we are fetching, usually just "id" char *outputVal; // Used as a place to hold the row value for later processing int nativeFieldIx; // Field index in native table char *foreignKey; // Actual foreign key - computed each row }; @@ -342,33 +343,36 @@ for (fRef = foreignRefList; fRef != NULL; fRef = fRef->next) freez(&fRef->foreignKey); } dyStringFree(&sql); dyStringFree(&csvScratch); fieldedTableFree(&inTable); } void sqlUpdateRelated(char *database, char **inFiles, int inCount) /* sqlUpdateRelated - Update a bunch of tables in a kind of careful way based out of tab * separated files. Handles foreign key and many-to-many relationships with a multitude * of @ signs.. */ { struct sqlConnection *conn = sqlConnect(database); int fileIx; +boolean missOk = optionExists("missOk"); for (fileIx = 0; fileIx < inCount; ++fileIx) { char *inFile = inFiles[fileIx]; + if (missOk && !fileExists(inFile)) + continue; char *tableName = cloneString(inFile); chopSuffix(tableName); verbose(1, "Processing %s into %s table \n", inFile, tableName); sqlUpdateViaTabFile(conn, inFile, tableName); } sqlDisconnect(&conn); } int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); if (argc < 3) usage(); sqlUpdateRelated(argv[1], argv+2, argc-2);