src/hg/lib/jksql.c 1.127
1.127 2009/02/23 23:38:08 angie
sc->conn->db can be NULL -- when printing out monitor messages, use 'db=?' instead of NULL.
Index: src/hg/lib/jksql.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/jksql.c,v
retrieving revision 1.126
retrieving revision 1.127
diff -b -B -U 4 -r1.126 -r1.127
--- src/hg/lib/jksql.c 20 Feb 2009 23:21:25 -0000 1.126
+++ src/hg/lib/jksql.c 23 Feb 2009 23:38:08 -0000 1.127
@@ -332,13 +332,20 @@
}
return deltaTime;
}
+static char *scConnDb(struct sqlConnection *sc)
+/* Return sc->conn->db, unless it is NULL -- if NULL, return a string for
+ * fprint'd messages. */
+{
+return (sc->conn->db ? sc->conn->db : "db=?");
+}
+
static void monitorPrintInfo(struct sqlConnection *sc, char *name)
/* print a monitor message, with connection id and databases. */
{
fprintf(stderr, "%.*s%s %ld %s\n", traceIndent, indentStr, name,
- sc->conn->thread_id, sc->conn->db);
+ sc->conn->thread_id, scConnDb(sc));
}
static void monitorPrint(struct sqlConnection *sc, char *name,
char *format, ...)
@@ -346,9 +353,9 @@
* printf style message.*/
{
va_list args;
fprintf(stderr, "%.*s%s %ld %s ", traceIndent, indentStr, name,
- sc->conn->thread_id, sc->conn->db);
+ sc->conn->thread_id, scConnDb(sc));
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fputc('\n', stderr);
@@ -488,9 +495,9 @@
}
}
char* sqlGetDatabase(struct sqlConnection *sc)
-/* Get the database associated with an connection. */
+/* Get the database associated with an connection. Warning: return may be NULL! */
{
assert(!sc->isFree);
return sc->conn->db;
}
@@ -1041,9 +1048,9 @@
safef(query, sizeof(query), "select * from %s limit 1,1", table);
if ((sr = sqlUseOrStore(sc, query, mysql_use_result, FALSE)) == NULL)
{
fprintf(stderr, "ASH: Got nothing from select on %s.%s. pid=%ld\n",
- sc->conn->db, table, (long)getpid());
+ scConnDb(sc), table, (long)getpid());
/* An error here is OK if and only if the table exists and is empty: */
return (sqlTableSizeIfExists(sc, table) == 0);
}
else
@@ -1051,9 +1058,9 @@
sqlMaybeNextRow(sr, &ret);
sqlFreeResult(&sr);
if (ret == FALSE)
fprintf(stderr, "ASH: Error reading result of select on %s.%s! pid=%ld\n",
- sc->conn->db, table, (long)getpid());
+ scConnDb(sc), table, (long)getpid());
return ret;
}
struct sqlResult *sqlGetResult(struct sqlConnection *sc, char *query)