d983323cd2570af1cf3971763d14ef2d88c06fe4 jcasper Wed Feb 19 17:00:19 2025 -0800 sqlTableSize needs to support tables with more than 2B rows (rarely, but it does), refs #35262 diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c index 83f518dce83..473f430b0dc 100644 --- src/hg/lib/jksql.c +++ src/hg/lib/jksql.c @@ -1901,44 +1901,44 @@ boolean result = FALSE; struct slName *tablesList = slNameListFromComma(tables); struct slName *table; for(table = tablesList; table; table = table->next) { if (sqlColumnExists(conn, table->name, field)) { result = TRUE; break; } } slFreeList(&tablesList); return result; } -int sqlTableSizeIfExists(struct sqlConnection *sc, char *table) +long sqlTableSizeIfExists(struct sqlConnection *sc, char *table) /* Return row count if a table exists, -1 if it doesn't. */ { char query[256]; struct sqlResult *sr; char **row = 0; int ret = 0; sqlSafef(query, sizeof(query), "select count(*) from %s", table); if ((sr = sqlUseOrStore(sc, query, DEFAULTGETTER, FALSE)) == NULL) return -1; row = sqlNextRow(sr); if (row != NULL && row[0] != NULL) - ret = atoi(row[0]); + ret = atol(row[0]); sqlFreeResult(&sr); return ret; } boolean sqlTablesExist(struct sqlConnection *conn, char *tables) /* Check all tables in space delimited string exist. */ { char *dupe = cloneString(tables); char *s = dupe, *word; boolean ok = TRUE; while ((word = nextWord(&s)) != NULL) { if (!sqlTableExists(conn, word)) { ok = FALSE; @@ -2581,36 +2581,36 @@ struct slPair *sqlQuickPairList(struct sqlConnection *conn, char *query) /* Return a list of slPairs with the results of a two-column query. * Free result with slPairFreeValsAndList. */ { struct slPair *pairList = NULL; struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) slAddHead(&pairList, slPairNew(row[0], cloneString(row[1]))); sqlFreeResult(&sr); slReverse(&pairList); return pairList; } -int sqlTableSize(struct sqlConnection *conn, char *table) +long sqlTableSize(struct sqlConnection *conn, char *table) /* Find number of rows in table. */ { char query[128]; sqlSafef(query, sizeof(query), "SELECT COUNT(*) FROM %s", table); -return sqlQuickNum(conn, query); +return (long) sqlQuickLongLong(conn, query); } int sqlFieldIndex(struct sqlConnection *conn, char *table, char *field) /* Returns index of field in a row from table, or -1 if it * doesn't exist. */ { struct sqlResult *sr; char **row; int i = 0, ix=-1; /* Read table description into hash. */ sr = sqlDescribe(conn, table); while ((row = sqlNextRow(sr)) != NULL) { if (sameString(row[0], field))