4cffc3eb6f43e109452b5b52d1f760cf1ea6a981
jcasper
  Sun Jun 7 21:47:37 2026 -0700
Adjusting sessionDb and userDb IDs to be 64-bit in the code, since the database
is now ready for it and we're crossing the threshold.  refs #33554

diff --git src/hg/lib/cart.c src/hg/lib/cart.c
index f37ac597263..dfefd94fd91 100644
--- src/hg/lib/cart.c
+++ src/hg/lib/cart.c
@@ -103,68 +103,68 @@
 void cartTrace(struct cart *cart, char *when, struct sqlConnection *conn)
 /* Write some properties of the cart to stderr for debugging. */
 {
 if (cfgOption("cart.trace") == NULL)
     return;
 struct cartDb *u = cart->userInfo, *s = cart->sessionInfo;
 char *pix = hashFindVal(cart->hash, "pix");
 char *textSize = hashFindVal(cart->hash, "textSize");
 char *trackControls = hashFindVal(cart->hash, "trackControlsOnMain");
 int uLen, sLen;
 if (conn != NULL)
     {
     /* Since the content string is chopped, query for the actual length. */
     struct dyString *query = dyStringNew(1024);
     sqlDyStringPrintf(query, "select length(contents) from %s"
-	  " where id = %d", userDbTable(), u->id);
+	  " where id = %lu", userDbTable(), u->id);
     if (cartDbUseSessionKey())
 	  sqlDyStringPrintf(query, " and sessionKey='%s'", u->sessionKey);
     uLen = sqlQuickNum(conn, query->string);
     dyStringClear(query);
     sqlDyStringPrintf(query, "select length(contents) from %s"
-	  " where id = %d", sessionDbTable(),s->id);
+	  " where id = %lu", sessionDbTable(),s->id);
     if (cartDbUseSessionKey())
 	  sqlDyStringPrintf(query, " and sessionKey='%s'", s->sessionKey);
     sLen = sqlQuickNum(conn, query->string);
     dyStringFree(&query);
     }
 else
     {
     uLen = strlen(u->contents);
     sLen = strlen(s->contents);
     }
 if (pix == NULL)
     pix = "-";
 if (textSize == NULL)
     textSize = "-";
 if (trackControls == NULL)
     trackControls = "-";
 fprintf(stderr, "cartTrace: %22s: "
-	"u.i=%d u.l=%d u.c=%d s.i=%d s.l=%d s.c=%d "
+	"u.i=%lu u.l=%d u.c=%d s.i=%lu s.l=%d s.c=%d "
 	"p=%s f=%s t=%s pid=%ld %s\n",
 	when,
 	u->id, uLen, u->useCount, s->id, sLen, s->useCount,
 	pix, textSize, trackControls, (long)getpid(), cgiRemoteAddr());
 char userIdKey[256];
 cartDbSecureId(userIdKey, sizeof userIdKey, u);
 if (cart->userId && !sameString(userIdKey, cart->userId))
-    fprintf(stderr, "cartTrace: bad userId %s --> %d_%s!  pid=%ld\n",
+    fprintf(stderr, "cartTrace: bad userId %s --> %lu_%s!  pid=%ld\n",
 	    cart->userId, u->id, u->sessionKey, (long)getpid());
 char sessionIdKey[256];
 cartDbSecureId(sessionIdKey, sizeof sessionIdKey, s);
 if (cart->sessionId && !sameString(sessionIdKey, cart->sessionId))
-    fprintf(stderr, "cartTrace: bad sessionId %s --> %d_%s!  pid=%ld\n",
+    fprintf(stderr, "cartTrace: bad sessionId %s --> %lu_%s!  pid=%ld\n",
 	    cart->sessionId, s->id, s->sessionKey, (long)getpid());
 }
 
 boolean cartTablesOk(struct sqlConnection *conn)
 /* Return TRUE if cart tables are accessible (otherwise, the connection
  * doesn't do us any good). */
 {
 if (!sqlTableExists(conn, userDbTable()))
     {
     fprintf(stderr, "cartTablesOk failed on %s.%s  pid=%ld\n",
 	    sqlGetDatabase(conn), userDbTable(),  (long)getpid());
     return FALSE;
     }
 if (!sqlTableExists(conn, sessionDbTable()))
     {
@@ -273,46 +273,46 @@
     return isCorr;
     }
 }
 
 struct cartDb *cartDbLoadFromId(struct sqlConnection *conn, char *table, char *secureId)
 /* Load up cartDb entry for particular ID.  Returns NULL if no such id. */
 {
 
 if (!secureId)
     return NULL;
 else
     {
     struct cartDb *cdb = NULL;
     struct dyString *where = dyStringNew(256);
     char *sessionKey = NULL;	    
-    unsigned int id = cartDbParseId(secureId, &sessionKey);
-    sqlDyStringPrintf(where, "id = %u", id);
+    unsigned long id = cartDbParseId(secureId, &sessionKey);
+    sqlDyStringPrintf(where, "id = %lu", id);
     if (cartDbUseSessionKey())
 	{
 	if (!sessionKey)
 	    sessionKey = "";
 	sqlDyStringPrintf(where, " and sessionKey='%s'", sessionKey);
 	}
     cdb = cartDbLoadWhere(conn, table, where->string);
     dyStringFree(&where);
     if (looksCorrupted(cdb))
        {
        /* Can't use warn here -- it interrupts the HTML header, causing an
 	* err500 (and nothing useful in error_log) instead of a warning. */
        fprintf(stderr,
-	       "%s id=%u looks corrupted -- starting over with new %s id.\n",
+	       "%s id=%lu looks corrupted -- starting over with new %s id.\n",
 	       table, id, table);
        cdb = NULL;
        }
     return cdb;
     }
 }
 
 static char *getDefaultCart(struct sqlConnection *conn)
 /* Get the default cart if any. */
 {
 char *contents = "";
 char *table = defaultCartTable();
 if (sqlTableExists(conn, table))
     {
     char query[1024];
@@ -338,38 +338,38 @@
     result = FALSE;
     struct dyString *query = dyStringNew(256);
     sqlDyStringPrintf(query, "INSERT %s VALUES(0,'',0,now(),now(),0", table);
     char *sessionKey = "";
     if (cartDbHasSessionKey(conn, table)) 
 	{
 	if (cartDbUseSessionKey())
 	    {
 	    sessionKey = makeRandomKey(128+33); // at least 128 bits of protection, 33 for the world population size.
 	    }
 	sqlDyStringPrintf(query, ",'%s'", sessionKey);
 	}
     sqlDyStringPrintf(query, ")");
     sqlUpdate(conn, query->string);
     dyStringFree(&query);
-    unsigned int id = sqlLastAutoId(conn);
+    unsigned long id = sqlLastAutoId64(conn);
     char newSecureId[256];
     if (cartDbUseSessionKey() && !sameString(sessionKey,""))
-	safef(newSecureId, sizeof newSecureId, "%u_%s", id, sessionKey);
+	safef(newSecureId, sizeof newSecureId, "%lu_%s", id, sessionKey);
     else
-	safef(newSecureId, sizeof newSecureId, "%u", id);
+	safef(newSecureId, sizeof newSecureId, "%lu", id);
     if ((cdb = cartDbLoadFromId(conn,table,newSecureId)) == NULL)
-        errAbort("Couldn't get cartDb for id=%u right after loading.  "
+        errAbort("Couldn't get cartDb for id=%lu right after loading.  "
 		 "MySQL problem??", id);
     if (!sameString(sessionKey,""))
 	freeMem(sessionKey);
     }
 *found = result;
 return cdb;
 }
 
 void cartExclude(struct cart *cart, char *var)
 /* Exclude var from persistent storage. */
 {
 hashAdd(cart->exclude, var, NULL);
 }
 
 
@@ -1601,38 +1601,38 @@
     return;
 
 // when the captcha is solved, our JS code does a full page-reload, no AJAX. That saves us one round-trip.
 // After the reload, the new page URL has the captcha token in the URL argument list, so now we need to validate it
 // and remove it from the cart
 char *token = cgiOptionalString("token");
 if (token)
 {
     if (isValidToken(token))
         {
         cartRemove(cart, "token");
         // Drop any IP-tracking rows for this hguid so a legitimate user
         // who roams networks isn't repeatedly captcha-gated.
         if (cfgOptionBooleanDefault("hguidIpTracking.enabled", FALSE) && isNotEmpty(userId))
             {
-            unsigned int userIdNum = cartDbParseId(userId, NULL);
+            unsigned long userIdNum = cartDbParseId(userId, NULL);
             if (userIdNum != 0)
                 {
                 struct sqlConnection *conn = hConnectCentralNoCache();
                 char *table = cfgOptionDefault("hguidIpTracking.table", "hguidIpAccess");
                 char query[256];
                 sqlSafef(query, sizeof(query),
-                         "DELETE FROM %s WHERE userId=%u", table, userIdNum);
+                         "DELETE FROM %s WHERE userId=%lu", table, userIdNum);
                 sqlUpdate(conn, query);
                 sqlDisconnect(&conn);
                 }
             }
         return;
         }
     else
         {
         puts("Content-Type: text/html\n");
         puts("<html><body>Internal captcha error: Cloudflare rejected the captcha token. "
                 "Something is not working internally, we are very sorry. You can try reloading the page. "
                 "If this problem persists, send an email to genome-www@soe.ucsc.edu and we will "
                 "look into it as quickly as we can in the PST timezone. You can use any internet browser "
                 "where you have used the genome browser before, but not from this internet browser. "
                 "You can try our mirror sites, "
@@ -1791,31 +1791,31 @@
 if (didSessionLoad)
     cartHideDefaultTracks(cart);
 return cart;
 }
 
 
 
 static void updateOne(struct sqlConnection *conn,
 	char *table, struct cartDb *cdb, char *contents, int contentSize)
 /* Update cdb in database. */
 {
 struct dyString *dy = dyStringNew(4096);
 sqlDyStringPrintf(dy, "UPDATE %s SET contents='", table);
 sqlDyAppendEscaped(dy, contents);
 sqlDyStringPrintf(dy, "',lastUse=now(),useCount=%d ", cdb->useCount+1);
-sqlDyStringPrintf(dy, " where id=%u", cdb->id);
+sqlDyStringPrintf(dy, " where id=%lu", cdb->id);
 if (cartDbUseSessionKey())
   sqlDyStringPrintf(dy, " and sessionKey='%s'", cdb->sessionKey);
 sqlUpdate(conn, dy->string);
 dyStringFree(&dy);
 }
 
 
 void cartEncodeState(struct cart *cart, struct dyString *dy)
 /* Add a CGI-encoded var=val&... string of all cart variables to dy. */
 {
 struct hashEl *el, *elList = hashElListHash(cart->hash);
 boolean firstTime = TRUE;
 char *s = NULL;
 for (el = elList; el != NULL; el = el->next)
     {
@@ -1884,53 +1884,53 @@
 
 char *cartSessionVarName()
 /* Return name of CGI session ID variable. */
 {
 return sessionVar;
 }
 
 char *cartSessionId(struct cart *cart)
 /* Return session id. */
 {
 static char buf[256];
 cartDbSecureId(buf, sizeof buf, cart->sessionInfo);
 return buf;
 }
 
-unsigned cartSessionRawId(struct cart *cart)
+unsigned long cartSessionRawId(struct cart *cart)
 /* Return raw session id without security key. */
 {
 return cart->sessionInfo->id;
 }
 
 char *cartSidUrlString(struct cart *cart)
 /* Return session id string as in hgsid=N . */
 {
 static char buf[64];
 safef(buf, sizeof(buf), "%s=%s", cartSessionVarName(), cartSessionId(cart));
 return buf;
 }
 
 char *cartUserId(struct cart *cart)
 /* Return session id. */
 {
 static char buf[256];
 cartDbSecureId(buf, sizeof buf, cart->userInfo);
 return buf;
 }
 
-unsigned cartUserRawId(struct cart *cart)
+unsigned long cartUserRawId(struct cart *cart)
 /* Return raw user id without security key. */
 {
 return cart->userInfo->id;
 }
 
 static char *cartMultShadowVar(struct cart *cart, char *var)
 /* Return a pointer to the list variable shadow variable name for var.
  * Don't modify or free result. */
 {
 static char multShadowVar[PATH_LEN];
 safef(multShadowVar, sizeof(multShadowVar), "%s%s", cgiMultListShadowPrefix(), var);
 return multShadowVar;
 }
 
 static int cartRemoveAndCountNoShadow(struct cart *cart, char *var)
@@ -2542,33 +2542,33 @@
 }
 
 static char *getSessionId()
 /* Get session id if any from CGI. */
 {
 return cgiOptionalString("hgsid");
 }
 
 static void clearDbContents(struct sqlConnection *conn, char *table, char * secureId)
 /* Clear out contents field of row in table that matches id. */
 {
 if (!secureId)
     return;
 struct dyString *query = dyStringNew(256);
 char *sessionKey = NULL;	    
-unsigned int id = cartDbParseId(secureId, &sessionKey);
+unsigned long id = cartDbParseId(secureId, &sessionKey);
 char *defaultCartContents = getDefaultCart(conn);
-sqlDyStringPrintf(query, "update %s set contents='%s' where id=%u", table, defaultCartContents, id);
+sqlDyStringPrintf(query, "update %s set contents='%s' where id=%lu", table, defaultCartContents, id);
 if (cartDbUseSessionKey())
     {
     if (!sessionKey)
 	sessionKey = "";
     sqlDyStringPrintf(query, " and sessionKey='%s'", sessionKey);
     }
 sqlUpdate(conn, query->string);
 dyStringFree(&query);
 
 
 }
 
 void cartResetInDb(char *cookieName)
 /* Clear cart in database. */
 {