3a88c02326aadbb1df3436cd519f7b8a4df6ae5b chmalee Thu Jun 6 15:32:15 2024 -0700 Work in progress using the mysql table for hubSpace on client side diff --git src/hg/lib/hubSpace.c src/hg/lib/hubSpace.c index 05447b5..17da83e 100644 --- src/hg/lib/hubSpace.c +++ src/hg/lib/hubSpace.c @@ -1,43 +1,44 @@ /* hubSpace.c was originally generated by the autoSql program, which also * generated hubSpace.h and hubSpace.sql. This module links the database and * the RAM representation of objects. */ #include "common.h" #include "linefile.h" #include "dystring.h" #include "jksql.h" #include "hubSpace.h" -char *hubSpaceCommaSepFieldNames = "userName,fileName,fileSize,fileType,creationTime,lastModified,hubNameList,db,location"; +char *hubSpaceCommaSepFieldNames = "userName,fileName,fileSize,fileType,creationTime,lastModified,hubNameList,db,location,md5sum"; void hubSpaceStaticLoad(char **row, struct hubSpace *ret) /* Load a row from hubSpace table into ret. The contents of ret will * be replaced at the next call to this function. */ { ret->userName = row[0]; ret->fileName = row[1]; ret->fileSize = sqlLongLong(row[2]); ret->fileType = row[3]; ret->creationTime = row[4]; ret->lastModified = row[5]; ret->hubNameList = row[6]; ret->db = row[7]; ret->location = row[8]; +ret->md5sum = row[9]; } struct hubSpace *hubSpaceLoadByQuery(struct sqlConnection *conn, char *query) /* Load all hubSpace from table that satisfy the query given. * Where query is of the form 'select * from example where something=something' * or 'select example.* from example, anotherTable where example.something = * anotherTable.something'. * Dispose of this with hubSpaceFreeList(). */ { struct hubSpace *list = NULL, *el; struct sqlResult *sr; char **row; sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) @@ -46,128 +47,131 @@ slAddHead(&list, el); } slReverse(&list); sqlFreeResult(&sr); return list; } void hubSpaceSaveToDb(struct sqlConnection *conn, struct hubSpace *el, char *tableName, int updateSize) /* Save hubSpace as a row to the table specified by tableName. * As blob fields may be arbitrary size updateSize specifies the approx size * of a string that would contain the entire query. Arrays of native types are * converted to comma separated strings and loaded as such, User defined types are * inserted as NULL. This function automatically escapes quoted strings for mysql. */ { struct dyString *update = dyStringNew(updateSize); -sqlDyStringPrintf(update, "insert into %s values ( '%s','%s',%lld,'%s','%s','%s','%s','%s','%s')", - tableName, el->userName, el->fileName, el->fileSize, el->fileType, el->creationTime, el->lastModified, el->hubNameList, el->db, el->location); +sqlDyStringPrintf(update, "insert into %s values ( '%s','%s',%lld,'%s','%s','%s','%s','%s','%s','%s')", + tableName, el->userName, el->fileName, el->fileSize, el->fileType, el->creationTime, el->lastModified, el->hubNameList, el->db, el->location, el->md5sum); sqlUpdate(conn, update->string); dyStringFree(&update); } struct hubSpace *hubSpaceLoad(char **row) /* Load a hubSpace from row fetched with select * from hubSpace * from database. Dispose of this with hubSpaceFree(). */ { struct hubSpace *ret; AllocVar(ret); ret->userName = cloneString(row[0]); ret->fileName = cloneString(row[1]); ret->fileSize = sqlLongLong(row[2]); ret->fileType = cloneString(row[3]); ret->creationTime = cloneString(row[4]); ret->lastModified = cloneString(row[5]); ret->hubNameList = cloneString(row[6]); ret->db = cloneString(row[7]); ret->location = cloneString(row[8]); +ret->md5sum = cloneString(row[9]); return ret; } struct hubSpace *hubSpaceLoadAll(char *fileName) /* Load all hubSpace from a whitespace-separated file. * Dispose of this with hubSpaceFreeList(). */ { struct hubSpace *list = NULL, *el; struct lineFile *lf = lineFileOpen(fileName, TRUE); -char *row[9]; +char *row[10]; while (lineFileRow(lf, row)) { el = hubSpaceLoad(row); slAddHead(&list, el); } lineFileClose(&lf); slReverse(&list); return list; } struct hubSpace *hubSpaceLoadAllByChar(char *fileName, char chopper) /* Load all hubSpace from a chopper separated file. * Dispose of this with hubSpaceFreeList(). */ { struct hubSpace *list = NULL, *el; struct lineFile *lf = lineFileOpen(fileName, TRUE); -char *row[9]; +char *row[10]; while (lineFileNextCharRow(lf, chopper, row, ArraySize(row))) { el = hubSpaceLoad(row); slAddHead(&list, el); } lineFileClose(&lf); slReverse(&list); return list; } struct hubSpace *hubSpaceCommaIn(char **pS, struct hubSpace *ret) /* Create a hubSpace out of a comma separated string. * This will fill in ret if non-null, otherwise will * return a new hubSpace */ { char *s = *pS; if (ret == NULL) AllocVar(ret); ret->userName = sqlStringComma(&s); ret->fileName = sqlStringComma(&s); ret->fileSize = sqlLongLongComma(&s); ret->fileType = sqlStringComma(&s); ret->creationTime = sqlStringComma(&s); ret->lastModified = sqlStringComma(&s); ret->hubNameList = sqlStringComma(&s); ret->db = sqlStringComma(&s); ret->location = sqlStringComma(&s); +ret->md5sum = sqlStringComma(&s); *pS = s; return ret; } void hubSpaceFree(struct hubSpace **pEl) /* Free a single dynamically allocated hubSpace such as created * with hubSpaceLoad(). */ { struct hubSpace *el; if ((el = *pEl) == NULL) return; freeMem(el->userName); freeMem(el->fileName); freeMem(el->fileType); freeMem(el->creationTime); freeMem(el->lastModified); freeMem(el->hubNameList); freeMem(el->db); freeMem(el->location); +freeMem(el->md5sum); freez(pEl); } void hubSpaceFreeList(struct hubSpace **pList) /* Free a list of dynamically allocated hubSpace's */ { struct hubSpace *el, *next; for (el = *pList; el != NULL; el = next) { next = el->next; hubSpaceFree(&el); } *pList = NULL; } @@ -196,30 +200,34 @@ if (sep == ',') fputc('"',f); fprintf(f, "%s", el->lastModified); if (sep == ',') fputc('"',f); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->hubNameList); if (sep == ',') fputc('"',f); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->db); if (sep == ',') fputc('"',f); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->location); if (sep == ',') fputc('"',f); +fputc(sep,f); +if (sep == ',') fputc('"',f); +fprintf(f, "%s", el->md5sum); +if (sep == ',') fputc('"',f); fputc(lastSep,f); } void hubSpaceJsonOutput(struct hubSpace *el, FILE *f) /* Print out hubSpace in JSON format. */ { fputc('{',f); fputc('"',f); fprintf(f,"userName"); fputc('"',f); fputc(':',f); fputc('"',f); fprintf(f, "%s", el->userName); fputc('"',f); fputc(',',f); @@ -272,20 +280,28 @@ fputc('"',f); fprintf(f,"db"); fputc('"',f); fputc(':',f); fputc('"',f); fprintf(f, "%s", el->db); fputc('"',f); fputc(',',f); fputc('"',f); fprintf(f,"location"); fputc('"',f); fputc(':',f); fputc('"',f); fprintf(f, "%s", el->location); fputc('"',f); +fputc(',',f); +fputc('"',f); +fprintf(f,"md5sum"); +fputc('"',f); +fputc(':',f); +fputc('"',f); +fprintf(f, "%s", el->md5sum); +fputc('"',f); fputc('}',f); } /* -------------------------------- End autoSql Generated Code -------------------------------- */