56cb547b6ac789f20c187d6c3067609a669fe4cb larrym Thu May 19 13:23:20 2011 -0700 errAbort if showTableCache config is set but table does not exist diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c index 279f6b7..be10b8a 100644 --- src/hg/lib/jksql.c +++ src/hg/lib/jksql.c @@ -567,51 +567,55 @@ while ((row = sqlNextRow(sr)) != NULL) { if (!startsWith("mysql", row[0])) /* Avoid internal databases. */ slSafeAddHead(&databases, slNameNew(row[0])); } sqlFreeResult(&sr); return databases; } struct slName *sqlListTables(struct sqlConnection *conn) /* Return list of tables in database associated with conn. */ { struct sqlResult *sr; char **row; struct slName *list = NULL, *el; -char *tableList = cfgOption("showTableCache"); +char *cfgName = "showTableCache"; +char *tableList = cfgOption(cfgName); -if (tableList != NULL && sqlTableExists(conn, tableList)) +if (tableList != NULL) + { + // mysql does not cache "show tables", so use a cached run of show tables which is stored in the showTableCache table. + // See redmine 3780 for details. + if(sqlTableExists(conn, tableList)) { - // mysql does not cache "show tables", so use a cached run of show tables in the tableList table (if it exists). - // Table should be loaded thus: - // - // hgsql hg18 -e 'show tables' > tables.txt - // CREATE TABLE tableList (name varchar(255) NOT NULL, INDEX(name)); - // load data local infile 'tables.txt' into table tableList; char query[256]; safef(query, sizeof(query), "select * from %s order by name desc", tableList); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { el = slNameNew(row[0]); slAddHead(&list, el); } } else { + errAbort("%s option is misconfigured in hg.conf: table '%s' does not exist", cfgName, tableList); + } + } +else + { sr = sqlGetResult(conn, "show tables"); while ((row = sqlNextRow(sr)) != NULL) { el = slNameNew(row[0]); slAddHead(&list, el); } slReverse(&list); } sqlFreeResult(&sr); return list; } struct slName *sqlListFields(struct sqlConnection *conn, char *table) /* Return list of fields in table. */ {