/* testTableExists - Experiments with ways to test for table existence ... */ #include #include #include "common.h" #include "options.h" #include "jksql.h" #include "hgConfig.h" #include "obscure.h" #include "portable.h" char *database = NULL; char *host = NULL; char *user = NULL; char *password = NULL; struct sqlConnection *conn = NULL; char *existingMyIsamDb = NULL; char *existingMyIsamTable = NULL; char *existingInnodbDb = NULL; char *existingInnodbTable = NULL; char *nonExistingTableDb = NULL; char *nonExistingTable = NULL; int numReps=1000; void usage() /* Explain usage and exit. */ { errAbort( "testTableExists - Experiments with various ways to test for table existence.\n" "usage:\n" " testTableExists loginProfile existingMyIsamTable existingInnodbTable nonExistingTable\n" "options:\n" " -xxx=XXX\n" ); } static struct optionSpec options[] = { {NULL, 0}, }; void testSqlTableExists(struct sqlConnection *sc, char *sql, char *table, int *resultRows, unsigned int *errorNo) /* Use sql to test if a table exists. Return number of rows in resultset and whether it had an error. */ { char query[256]; struct sqlResult *sr; int count=0; safef(query, sizeof(query), sql, table); sr=sqlGetResultExt(sc,query, errorNo, NULL); if (sr) { while (sqlNextRow(sr)) count++; sqlFreeResult(&sr); } *resultRows=count; } void useDb(char *db) /* Use db changes default db. */ { char query[256]; safef(query, sizeof(query), "use %s", db); sqlUpdate(conn,query); } char *getCfgOption(char *config, char *setting) /* get setting for specified config */ { char temp[256]; safef(temp, sizeof(temp), "%s.%s", config, setting); char *value = cfgOption(temp); if (!value) errAbort("setting %s not found!",temp); return value; } void testTableExistsRepeatedly(char *sql, int kind) /* testTableExistsRepeatedly - Experiments with ways to test for table existence ... */ { int i=0; int rows=0; unsigned int errorNo=0; //verbose(1, "got here 2 %s\n", existingMyIsamDb); //debug verbose(1, "\nQuery: [%s]\n", sql); useDb(existingMyIsamDb); //verbose(1, "got here 3\n"); //debug long time = clock1000(); for(i=0; i