36a6c30381ac63be42824055efee08a9574e2030
galt
  Wed Nov 14 09:52:24 2012 -0800
temporary tables will now be created in a special database hgTemp
diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c
index 51e55fc..4ad092f 100644
--- src/hg/lib/jksql.c
+++ src/hg/lib/jksql.c
@@ -2387,39 +2387,45 @@
 return enumDef;
 }
 
 struct slName *sqlRandomSampleWithSeedConn(struct sqlConnection *conn, char *table, char *field, int count, int seed)
 /* Get random sample from database specifiying rand number seed, or -1 for none */
 {
 char query[256], **row;
 struct sqlResult *sr;
 struct slName *list = NULL, *el;
 char seedString[256] = "";
 /* The randomized-order, distinct-ing query can take a very long time on
  * very large tables.  So create a smaller temporary table and use that.
  * The temporary table is visible only to the current connection, so
  * doesn't have to be very uniquely named, and will disappear when the
  * connection is closed. */
+/* check if table has 'db.' prefix in it */
+char *plainTable = strrchr(table, '.');
+if (plainTable)
+    plainTable++;
+else
+    plainTable = table;
 safef(query, sizeof(query),
-      "create temporary table tmp%s select %s from %s limit 100000",
-      table, field, table);
+      "create temporary table hgTemp.tmp%s select %s from %s limit 100000",
+      plainTable, field, table);
 sqlUpdate(conn, query);
 if (seed != -1)
     safef(seedString,sizeof(seedString),"%d",seed);
-safef(query, sizeof(query), "select distinct %s from tmp%s "
+safef(query, sizeof(query), "select distinct %s from hgTemp.tmp%s "
       "order by rand(%s) limit %d",
-      field, table, seedString, count);
+      field, plainTable, seedString, count);
 sr = sqlGetResult(conn, query);
 while ((row = sqlNextRow(sr)) != NULL)
     {
     el = slNameNew(row[0]);
     slAddHead(&list, el);
     }
 sqlFreeResult(&sr);
 return list;
 }
 
 struct slName *sqlRandomSampleWithSeed(char *db, char *table, char *field, int count, int seed)
 /* Get random sample from database specifiying rand number seed, or -1 for none */
 {
 struct sqlConnection *conn = sqlConnect(db);
 return sqlRandomSampleWithSeedConn(conn, table, field, count, seed);