src/hg/instinct/lib/ispyTableDefs.c 1.3
1.3 2009/06/04 03:42:50 jsanborn
added copyright notices, removed cluster library
Index: src/hg/instinct/lib/ispyTableDefs.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/lib/ispyTableDefs.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -B -U 1000000 -r1.2 -r1.3
--- src/hg/instinct/lib/ispyTableDefs.c 8 Nov 2007 22:52:06 -0000 1.2
+++ src/hg/instinct/lib/ispyTableDefs.c 4 Jun 2009 03:42:50 -0000 1.3
@@ -1,3026 +1,3030 @@
+/********************************************************************************/
+/* Copyright 2007-2009 -- The Regents of the University of California */
+/********************************************************************************/
+
/* ispyTableDefs.c was originally generated by the autoSql program, which also
* generated ispyTableDefs.h and ispyTableDefs.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 "ispyTableDefs.h"
static char const rcsid[] = "$Id$";
void patientStaticLoadWithNull(char **row, struct patient *ret)
/* Load a row from patient table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->DataExtractDt = row[1];
ret->Inst_ID = row[2];
}
struct patient *patientLoadWithNull(char **row)
/* Load a patient from row fetched with select * from patient
* from database. Dispose of this with patientFree(). */
{
struct patient *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->DataExtractDt = cloneString(row[1]);
ret->Inst_ID = cloneString(row[2]);
return ret;
}
struct patient *patientLoadAll(char *fileName)
/* Load all patient from a whitespace-separated file.
* Dispose of this with patientFreeList(). */
{
struct patient *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[3];
while (lineFileRow(lf, row))
{
el = patientLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct patient *patientLoadAllByChar(char *fileName, char chopper)
/* Load all patient from a chopper separated file.
* Dispose of this with patientFreeList(). */
{
struct patient *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[3];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = patientLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct patient *patientLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all patient 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 patientFreeList(). */
{
struct patient *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = patientLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void patientSaveToDb(struct sqlConnection *conn, struct patient *el, char *tableName, int updateSize)
/* Save patient 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use patientSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s')",
tableName, el->ispyId, el->DataExtractDt, el->Inst_ID);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void patientSaveToDbEscaped(struct sqlConnection *conn, struct patient *el, char *tableName, int updateSize)
/* Save patient 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than patientSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *DataExtractDt, *Inst_ID;
ispyId = sqlEscapeString(el->ispyId);
DataExtractDt = sqlEscapeString(el->DataExtractDt);
Inst_ID = sqlEscapeString(el->Inst_ID);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s')",
tableName, ispyId, DataExtractDt, Inst_ID);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&DataExtractDt);
freez(&Inst_ID);
}
struct patient *patientCommaIn(char **pS, struct patient *ret)
/* Create a patient out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new patient */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->DataExtractDt = sqlStringComma(&s);
ret->Inst_ID = sqlStringComma(&s);
*pS = s;
return ret;
}
void patientFree(struct patient **pEl)
/* Free a single dynamically allocated patient such as created
* with patientLoad(). */
{
struct patient *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->DataExtractDt);
freeMem(el->Inst_ID);
freez(pEl);
}
void patientFreeList(struct patient **pList)
/* Free a list of dynamically allocated patient's */
{
struct patient *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
patientFree(&el);
}
*pList = NULL;
}
void patientOutput(struct patient *el, FILE *f, char sep, char lastSep)
/* Print out patient. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->DataExtractDt);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Inst_ID);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void patientInfoStaticLoadWithNull(char **row, struct patientInfo *ret)
/* Load a row from patientInfo table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->DataExtractDt = row[1];
ret->Inst_ID = row[2];
ret->AgeCat = row[3];
if (row[4] != NULL)
{
ret->Age = needMem(sizeof(float));
*(ret->Age) = sqlFloat(row[4]);
}
ret->Race_id = row[5];
ret->Sstat = row[6];
if (row[7] != NULL)
{
ret->SurvDtD = needMem(sizeof(*(ret->SurvDtD)));
*(ret->SurvDtD) = sqlSigned(row[7]);
}
else
{
ret->SurvDtD = NULL;
}
}
struct patientInfo *patientInfoLoadWithNull(char **row)
/* Load a patientInfo from row fetched with select * from patientInfo
* from database. Dispose of this with patientInfoFree(). */
{
struct patientInfo *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->DataExtractDt = cloneString(row[1]);
ret->Inst_ID = cloneString(row[2]);
ret->AgeCat = cloneString(row[3]);
if (row[4] != NULL)
{
ret->Age = needMem(sizeof(float));
*(ret->Age) = sqlFloat(row[4]);
}
ret->Race_id = cloneString(row[5]);
ret->Sstat = cloneString(row[6]);
if (row[7] != NULL)
{
ret->SurvDtD = needMem(sizeof(*(ret->SurvDtD)));
*(ret->SurvDtD) = sqlSigned(row[7]);
}
else
{
ret->SurvDtD = NULL;
}
return ret;
}
struct patientInfo *patientInfoLoadAll(char *fileName)
/* Load all patientInfo from a whitespace-separated file.
* Dispose of this with patientInfoFreeList(). */
{
struct patientInfo *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[8];
while (lineFileRow(lf, row))
{
el = patientInfoLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct patientInfo *patientInfoLoadAllByChar(char *fileName, char chopper)
/* Load all patientInfo from a chopper separated file.
* Dispose of this with patientInfoFreeList(). */
{
struct patientInfo *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[8];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = patientInfoLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct patientInfo *patientInfoLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all patientInfo 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 patientInfoFreeList(). */
{
struct patientInfo *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = patientInfoLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void patientInfoSaveToDb(struct sqlConnection *conn, struct patientInfo *el, char *tableName, int updateSize)
/* Save patientInfo 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use patientInfoSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s',%g,'%s','%s',%d)",
tableName, el->ispyId, el->DataExtractDt, el->Inst_ID, el->AgeCat, *(el->Age), el->Race_id, el->Sstat, *(el->SurvDtD));
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void patientInfoSaveToDbEscaped(struct sqlConnection *conn, struct patientInfo *el, char *tableName, int updateSize)
/* Save patientInfo 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than patientInfoSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *DataExtractDt, *Inst_ID, *AgeCat, *Race_id, *Sstat;
ispyId = sqlEscapeString(el->ispyId);
DataExtractDt = sqlEscapeString(el->DataExtractDt);
Inst_ID = sqlEscapeString(el->Inst_ID);
AgeCat = sqlEscapeString(el->AgeCat);
Race_id = sqlEscapeString(el->Race_id);
Sstat = sqlEscapeString(el->Sstat);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s',%g,'%s','%s',%d)",
tableName, ispyId, DataExtractDt, Inst_ID, AgeCat, *(el->Age), Race_id, Sstat, *(el->SurvDtD));
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&DataExtractDt);
freez(&Inst_ID);
freez(&AgeCat);
freez(&Race_id);
freez(&Sstat);
}
struct patientInfo *patientInfoCommaIn(char **pS, struct patientInfo *ret)
/* Create a patientInfo out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new patientInfo */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->DataExtractDt = sqlStringComma(&s);
ret->Inst_ID = sqlStringComma(&s);
ret->AgeCat = sqlStringComma(&s);
ret->Age = needMem(sizeof(*(ret->Age)));
*(ret->Age) = sqlFloatComma(&s);
ret->Race_id = sqlStringComma(&s);
ret->Sstat = sqlStringComma(&s);
ret->SurvDtD = needMem(sizeof(*(ret->SurvDtD)));
*(ret->SurvDtD) = sqlSignedComma(&s);
*pS = s;
return ret;
}
void patientInfoFree(struct patientInfo **pEl)
/* Free a single dynamically allocated patientInfo such as created
* with patientInfoLoad(). */
{
struct patientInfo *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->DataExtractDt);
freeMem(el->Inst_ID);
freeMem(el->AgeCat);
freeMem(el->Race_id);
freeMem(el->Sstat);
freez(pEl);
}
void patientInfoFreeList(struct patientInfo **pList)
/* Free a list of dynamically allocated patientInfo's */
{
struct patientInfo *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
patientInfoFree(&el);
}
*pList = NULL;
}
void patientInfoOutput(struct patientInfo *el, FILE *f, char sep, char lastSep)
/* Print out patientInfo. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->DataExtractDt);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Inst_ID);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->AgeCat);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%g", *(el->Age));
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Race_id);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Sstat);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%d", *(el->SurvDtD));
fputc(lastSep,f);
}
void chemoStaticLoadWithNull(char **row, struct chemo *ret)
/* Load a row from chemo table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->Chemo = row[1];
ret->ChemoCat = row[2];
ret->DoseDenseAnthra = row[3];
ret->DoseDenseTaxane = row[4];
ret->Tam = row[5];
ret->Herceptin = row[6];
}
struct chemo *chemoLoadWithNull(char **row)
/* Load a chemo from row fetched with select * from chemo
* from database. Dispose of this with chemoFree(). */
{
struct chemo *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->Chemo = cloneString(row[1]);
ret->ChemoCat = cloneString(row[2]);
ret->DoseDenseAnthra = cloneString(row[3]);
ret->DoseDenseTaxane = cloneString(row[4]);
ret->Tam = cloneString(row[5]);
ret->Herceptin = cloneString(row[6]);
return ret;
}
struct chemo *chemoLoadAll(char *fileName)
/* Load all chemo from a whitespace-separated file.
* Dispose of this with chemoFreeList(). */
{
struct chemo *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[7];
while (lineFileRow(lf, row))
{
el = chemoLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct chemo *chemoLoadAllByChar(char *fileName, char chopper)
/* Load all chemo from a chopper separated file.
* Dispose of this with chemoFreeList(). */
{
struct chemo *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[7];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = chemoLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct chemo *chemoLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all chemo 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 chemoFreeList(). */
{
struct chemo *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = chemoLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void chemoSaveToDb(struct sqlConnection *conn, struct chemo *el, char *tableName, int updateSize)
/* Save chemo 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use chemoSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s','%s')",
tableName, el->ispyId, el->Chemo, el->ChemoCat, el->DoseDenseAnthra, el->DoseDenseTaxane, el->Tam, el->Herceptin);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void chemoSaveToDbEscaped(struct sqlConnection *conn, struct chemo *el, char *tableName, int updateSize)
/* Save chemo 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than chemoSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *Chemo, *ChemoCat, *DoseDenseAnthra, *DoseDenseTaxane, *Tam, *Herceptin;
ispyId = sqlEscapeString(el->ispyId);
Chemo = sqlEscapeString(el->Chemo);
ChemoCat = sqlEscapeString(el->ChemoCat);
DoseDenseAnthra = sqlEscapeString(el->DoseDenseAnthra);
DoseDenseTaxane = sqlEscapeString(el->DoseDenseTaxane);
Tam = sqlEscapeString(el->Tam);
Herceptin = sqlEscapeString(el->Herceptin);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s','%s')",
tableName, ispyId, Chemo, ChemoCat, DoseDenseAnthra, DoseDenseTaxane, Tam, Herceptin);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&Chemo);
freez(&ChemoCat);
freez(&DoseDenseAnthra);
freez(&DoseDenseTaxane);
freez(&Tam);
freez(&Herceptin);
}
struct chemo *chemoCommaIn(char **pS, struct chemo *ret)
/* Create a chemo out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new chemo */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->Chemo = sqlStringComma(&s);
ret->ChemoCat = sqlStringComma(&s);
ret->DoseDenseAnthra = sqlStringComma(&s);
ret->DoseDenseTaxane = sqlStringComma(&s);
ret->Tam = sqlStringComma(&s);
ret->Herceptin = sqlStringComma(&s);
*pS = s;
return ret;
}
void chemoFree(struct chemo **pEl)
/* Free a single dynamically allocated chemo such as created
* with chemoLoad(). */
{
struct chemo *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->Chemo);
freeMem(el->ChemoCat);
freeMem(el->DoseDenseAnthra);
freeMem(el->DoseDenseTaxane);
freeMem(el->Tam);
freeMem(el->Herceptin);
freez(pEl);
}
void chemoFreeList(struct chemo **pList)
/* Free a list of dynamically allocated chemo's */
{
struct chemo *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
chemoFree(&el);
}
*pList = NULL;
}
void chemoOutput(struct chemo *el, FILE *f, char sep, char lastSep)
/* Print out chemo. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Chemo);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ChemoCat);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->DoseDenseAnthra);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->DoseDenseTaxane);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Tam);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Herceptin);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void onStudyStaticLoadWithNull(char **row, struct onStudy *ret)
/* Load a row from onStudy table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->MenoStatus = row[1];
ret->SentinelNodeSample = row[2];
ret->SentinelNodeResult = row[3];
ret->HistTypeInvOS = row[4];
ret->HistologicGradeOS = row[5];
if (row[6] != NULL)
{
ret->ER_TS = needMem(sizeof(*(ret->ER_TS)));
*(ret->ER_TS) = sqlSigned(row[6]);
}
else
{
ret->ER_TS = NULL;
}
if (row[7] != NULL)
{
ret->PgR_TS = needMem(sizeof(*(ret->PgR_TS)));
*(ret->PgR_TS) = sqlSigned(row[7]);
}
else
{
ret->PgR_TS = NULL;
}
ret->ERpos = row[8];
ret->PgRpos = row[9];
ret->Her2CommunityPos = row[10];
ret->Her2CommunityMethod = row[11];
ret->pCR = row[12];
}
struct onStudy *onStudyLoadWithNull(char **row)
/* Load a onStudy from row fetched with select * from onStudy
* from database. Dispose of this with onStudyFree(). */
{
struct onStudy *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->MenoStatus = cloneString(row[1]);
ret->SentinelNodeSample = cloneString(row[2]);
ret->SentinelNodeResult = cloneString(row[3]);
ret->HistTypeInvOS = cloneString(row[4]);
ret->HistologicGradeOS = cloneString(row[5]);
if (row[6] != NULL)
{
ret->ER_TS = needMem(sizeof(*(ret->ER_TS)));
*(ret->ER_TS) = sqlSigned(row[6]);
}
else
{
ret->ER_TS = NULL;
}
if (row[7] != NULL)
{
ret->PgR_TS = needMem(sizeof(*(ret->PgR_TS)));
*(ret->PgR_TS) = sqlSigned(row[7]);
}
else
{
ret->PgR_TS = NULL;
}
ret->ERpos = cloneString(row[8]);
ret->PgRpos = cloneString(row[9]);
ret->Her2CommunityPos = cloneString(row[10]);
ret->Her2CommunityMethod = cloneString(row[11]);
ret->pCR = cloneString(row[12]);
return ret;
}
struct onStudy *onStudyLoadAll(char *fileName)
/* Load all onStudy from a whitespace-separated file.
* Dispose of this with onStudyFreeList(). */
{
struct onStudy *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[13];
while (lineFileRow(lf, row))
{
el = onStudyLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct onStudy *onStudyLoadAllByChar(char *fileName, char chopper)
/* Load all onStudy from a chopper separated file.
* Dispose of this with onStudyFreeList(). */
{
struct onStudy *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[13];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = onStudyLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct onStudy *onStudyLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all onStudy 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 onStudyFreeList(). */
{
struct onStudy *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = onStudyLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void onStudySaveToDb(struct sqlConnection *conn, struct onStudy *el, char *tableName, int updateSize)
/* Save onStudy 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use onStudySaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s',%d,%d,'%s','%s','%s','%s','%s')",
tableName, el->ispyId, el->MenoStatus, el->SentinelNodeSample, el->SentinelNodeResult, el->HistTypeInvOS, el->HistologicGradeOS, *(el->ER_TS), *(el->PgR_TS), el->ERpos, el->PgRpos, el->Her2CommunityPos, el->Her2CommunityMethod, el->pCR);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void onStudySaveToDbEscaped(struct sqlConnection *conn, struct onStudy *el, char *tableName, int updateSize)
/* Save onStudy 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than onStudySaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *MenoStatus, *SentinelNodeSample, *SentinelNodeResult, *HistTypeInvOS, *HistologicGradeOS, *ERpos, *PgRpos, *Her2CommunityPos, *Her2CommunityMethod, *pCR;
ispyId = sqlEscapeString(el->ispyId);
MenoStatus = sqlEscapeString(el->MenoStatus);
SentinelNodeSample = sqlEscapeString(el->SentinelNodeSample);
SentinelNodeResult = sqlEscapeString(el->SentinelNodeResult);
HistTypeInvOS = sqlEscapeString(el->HistTypeInvOS);
HistologicGradeOS = sqlEscapeString(el->HistologicGradeOS);
ERpos = sqlEscapeString(el->ERpos);
PgRpos = sqlEscapeString(el->PgRpos);
Her2CommunityPos = sqlEscapeString(el->Her2CommunityPos);
Her2CommunityMethod = sqlEscapeString(el->Her2CommunityMethod);
pCR = sqlEscapeString(el->pCR);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s',%d,%d,'%s','%s','%s','%s','%s')",
tableName, ispyId, MenoStatus, SentinelNodeSample, SentinelNodeResult, HistTypeInvOS, HistologicGradeOS, *(el->ER_TS), *(el->PgR_TS), ERpos, PgRpos, Her2CommunityPos, Her2CommunityMethod, pCR);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&MenoStatus);
freez(&SentinelNodeSample);
freez(&SentinelNodeResult);
freez(&HistTypeInvOS);
freez(&HistologicGradeOS);
freez(&ERpos);
freez(&PgRpos);
freez(&Her2CommunityPos);
freez(&Her2CommunityMethod);
freez(&pCR);
}
struct onStudy *onStudyCommaIn(char **pS, struct onStudy *ret)
/* Create a onStudy out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new onStudy */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->MenoStatus = sqlStringComma(&s);
ret->SentinelNodeSample = sqlStringComma(&s);
ret->SentinelNodeResult = sqlStringComma(&s);
ret->HistTypeInvOS = sqlStringComma(&s);
ret->HistologicGradeOS = sqlStringComma(&s);
ret->ER_TS = needMem(sizeof(*(ret->ER_TS)));
*(ret->ER_TS) = sqlSignedComma(&s);
ret->PgR_TS = needMem(sizeof(*(ret->PgR_TS)));
*(ret->PgR_TS) = sqlSignedComma(&s);
ret->ERpos = sqlStringComma(&s);
ret->PgRpos = sqlStringComma(&s);
ret->Her2CommunityPos = sqlStringComma(&s);
ret->Her2CommunityMethod = sqlStringComma(&s);
ret->pCR = sqlStringComma(&s);
*pS = s;
return ret;
}
void onStudyFree(struct onStudy **pEl)
/* Free a single dynamically allocated onStudy such as created
* with onStudyLoad(). */
{
struct onStudy *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->MenoStatus);
freeMem(el->SentinelNodeSample);
freeMem(el->SentinelNodeResult);
freeMem(el->HistTypeInvOS);
freeMem(el->HistologicGradeOS);
freeMem(el->ERpos);
freeMem(el->PgRpos);
freeMem(el->Her2CommunityPos);
freeMem(el->Her2CommunityMethod);
freeMem(el->pCR);
freez(pEl);
}
void onStudyFreeList(struct onStudy **pList)
/* Free a list of dynamically allocated onStudy's */
{
struct onStudy *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
onStudyFree(&el);
}
*pList = NULL;
}
void onStudyOutput(struct onStudy *el, FILE *f, char sep, char lastSep)
/* Print out onStudy. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->MenoStatus);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->SentinelNodeSample);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->SentinelNodeResult);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->HistTypeInvOS);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->HistologicGradeOS);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%d", *(el->ER_TS));
fputc(sep,f);
fprintf(f, "%d", *(el->PgR_TS));
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ERpos);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->PgRpos);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Her2CommunityPos);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Her2CommunityMethod);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->pCR);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void postSurgeryStaticLoadWithNull(char **row, struct postSurgery *ret)
/* Load a row from postSurgery table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->SurgeryLumpectomy = row[1];
ret->SurgeryMastectomy = row[2];
ret->InitLump_FupMast = row[3];
ret->Surgery = row[4];
ret->DCISonly = row[5];
if (row[6] != NULL)
{
ret->PTumor1Szcm_Micro = needMem(sizeof(float));
*(ret->PTumor1Szcm_Micro) = sqlFloat(row[6]);
}
ret->HistologicTypePS = row[7];
if (row[8] != NULL)
{
ret->HistologicGradePS = needMem(sizeof(*(ret->HistologicGradePS)));
*(ret->HistologicGradePS) = sqlSigned(row[8]);
}
else
{
ret->HistologicGradePS = NULL;
}
if (row[9] != NULL)
{
ret->NumPosNodes = needMem(sizeof(*(ret->NumPosNodes)));
*(ret->NumPosNodes) = sqlSigned(row[9]);
}
else
{
ret->NumPosNodes = NULL;
}
ret->NodesExamined = row[10];
ret->PathologyStage = row[11];
ret->ReasonNoSurg = row[12];
ret->pcr = row[13];
if (row[14] != NULL)
{
ret->rcbIndex = needMem(sizeof(float));
*(ret->rcbIndex) = sqlFloat(row[14]);
}
ret->rcbClass = row[15];
}
struct postSurgery *postSurgeryLoadWithNull(char **row)
/* Load a postSurgery from row fetched with select * from postSurgery
* from database. Dispose of this with postSurgeryFree(). */
{
struct postSurgery *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->SurgeryLumpectomy = cloneString(row[1]);
ret->SurgeryMastectomy = cloneString(row[2]);
ret->InitLump_FupMast = cloneString(row[3]);
ret->Surgery = cloneString(row[4]);
ret->DCISonly = cloneString(row[5]);
if (row[6] != NULL)
{
ret->PTumor1Szcm_Micro = needMem(sizeof(float));
*(ret->PTumor1Szcm_Micro) = sqlFloat(row[6]);
}
ret->HistologicTypePS = cloneString(row[7]);
if (row[8] != NULL)
{
ret->HistologicGradePS = needMem(sizeof(*(ret->HistologicGradePS)));
*(ret->HistologicGradePS) = sqlSigned(row[8]);
}
else
{
ret->HistologicGradePS = NULL;
}
if (row[9] != NULL)
{
ret->NumPosNodes = needMem(sizeof(*(ret->NumPosNodes)));
*(ret->NumPosNodes) = sqlSigned(row[9]);
}
else
{
ret->NumPosNodes = NULL;
}
ret->NodesExamined = cloneString(row[10]);
ret->PathologyStage = cloneString(row[11]);
ret->ReasonNoSurg = cloneString(row[12]);
ret->pcr = cloneString(row[13]);
if (row[14] != NULL)
{
ret->rcbIndex = needMem(sizeof(float));
*(ret->rcbIndex) = sqlFloat(row[14]);
}
ret->rcbClass = cloneString(row[15]);
return ret;
}
struct postSurgery *postSurgeryLoadAll(char *fileName)
/* Load all postSurgery from a whitespace-separated file.
* Dispose of this with postSurgeryFreeList(). */
{
struct postSurgery *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[16];
while (lineFileRow(lf, row))
{
el = postSurgeryLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct postSurgery *postSurgeryLoadAllByChar(char *fileName, char chopper)
/* Load all postSurgery from a chopper separated file.
* Dispose of this with postSurgeryFreeList(). */
{
struct postSurgery *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[16];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = postSurgeryLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct postSurgery *postSurgeryLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all postSurgery 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 postSurgeryFreeList(). */
{
struct postSurgery *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = postSurgeryLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void postSurgerySaveToDb(struct sqlConnection *conn, struct postSurgery *el, char *tableName, int updateSize)
/* Save postSurgery 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use postSurgerySaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s',%g,'%s',%d,%d,'%s','%s','%s','%s',%g,'%s')",
tableName, el->ispyId, el->SurgeryLumpectomy, el->SurgeryMastectomy, el->InitLump_FupMast, el->Surgery, el->DCISonly, *(el->PTumor1Szcm_Micro), el->HistologicTypePS, *(el->HistologicGradePS), *(el->NumPosNodes), el->NodesExamined, el->PathologyStage, el->ReasonNoSurg, el->pcr, *(el->rcbIndex), el->rcbClass);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void postSurgerySaveToDbEscaped(struct sqlConnection *conn, struct postSurgery *el, char *tableName, int updateSize)
/* Save postSurgery 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than postSurgerySaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *SurgeryLumpectomy, *SurgeryMastectomy, *InitLump_FupMast, *Surgery, *DCISonly, *HistologicTypePS, *NodesExamined, *PathologyStage, *ReasonNoSurg, *pcr, *rcbClass;
ispyId = sqlEscapeString(el->ispyId);
SurgeryLumpectomy = sqlEscapeString(el->SurgeryLumpectomy);
SurgeryMastectomy = sqlEscapeString(el->SurgeryMastectomy);
InitLump_FupMast = sqlEscapeString(el->InitLump_FupMast);
Surgery = sqlEscapeString(el->Surgery);
DCISonly = sqlEscapeString(el->DCISonly);
HistologicTypePS = sqlEscapeString(el->HistologicTypePS);
NodesExamined = sqlEscapeString(el->NodesExamined);
PathologyStage = sqlEscapeString(el->PathologyStage);
ReasonNoSurg = sqlEscapeString(el->ReasonNoSurg);
pcr = sqlEscapeString(el->pcr);
rcbClass = sqlEscapeString(el->rcbClass);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s',%g,'%s',%d,%d,'%s','%s','%s','%s',%g,'%s')",
tableName, ispyId, SurgeryLumpectomy, SurgeryMastectomy, InitLump_FupMast, Surgery, DCISonly, *(el->PTumor1Szcm_Micro), HistologicTypePS, *(el->HistologicGradePS), *(el->NumPosNodes), NodesExamined, PathologyStage, ReasonNoSurg, pcr, *(el->rcbIndex), rcbClass);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&SurgeryLumpectomy);
freez(&SurgeryMastectomy);
freez(&InitLump_FupMast);
freez(&Surgery);
freez(&DCISonly);
freez(&HistologicTypePS);
freez(&NodesExamined);
freez(&PathologyStage);
freez(&ReasonNoSurg);
freez(&pcr);
freez(&rcbClass);
}
struct postSurgery *postSurgeryCommaIn(char **pS, struct postSurgery *ret)
/* Create a postSurgery out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new postSurgery */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->SurgeryLumpectomy = sqlStringComma(&s);
ret->SurgeryMastectomy = sqlStringComma(&s);
ret->InitLump_FupMast = sqlStringComma(&s);
ret->Surgery = sqlStringComma(&s);
ret->DCISonly = sqlStringComma(&s);
ret->PTumor1Szcm_Micro = needMem(sizeof(*(ret->PTumor1Szcm_Micro)));
*(ret->PTumor1Szcm_Micro) = sqlFloatComma(&s);
ret->HistologicTypePS = sqlStringComma(&s);
ret->HistologicGradePS = needMem(sizeof(*(ret->HistologicGradePS)));
*(ret->HistologicGradePS) = sqlSignedComma(&s);
ret->NumPosNodes = needMem(sizeof(*(ret->NumPosNodes)));
*(ret->NumPosNodes) = sqlSignedComma(&s);
ret->NodesExamined = sqlStringComma(&s);
ret->PathologyStage = sqlStringComma(&s);
ret->ReasonNoSurg = sqlStringComma(&s);
ret->pcr = sqlStringComma(&s);
ret->rcbIndex = needMem(sizeof(*(ret->rcbIndex)));
*(ret->rcbIndex) = sqlFloatComma(&s);
ret->rcbClass = sqlStringComma(&s);
*pS = s;
return ret;
}
void postSurgeryFree(struct postSurgery **pEl)
/* Free a single dynamically allocated postSurgery such as created
* with postSurgeryLoad(). */
{
struct postSurgery *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->SurgeryLumpectomy);
freeMem(el->SurgeryMastectomy);
freeMem(el->InitLump_FupMast);
freeMem(el->Surgery);
freeMem(el->DCISonly);
freeMem(el->HistologicTypePS);
freeMem(el->NodesExamined);
freeMem(el->PathologyStage);
freeMem(el->ReasonNoSurg);
freeMem(el->pcr);
freeMem(el->rcbClass);
freez(pEl);
}
void postSurgeryFreeList(struct postSurgery **pList)
/* Free a list of dynamically allocated postSurgery's */
{
struct postSurgery *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
postSurgeryFree(&el);
}
*pList = NULL;
}
void postSurgeryOutput(struct postSurgery *el, FILE *f, char sep, char lastSep)
/* Print out postSurgery. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->SurgeryLumpectomy);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->SurgeryMastectomy);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->InitLump_FupMast);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Surgery);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->DCISonly);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%g", *(el->PTumor1Szcm_Micro));
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->HistologicTypePS);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%d", *(el->HistologicGradePS));
fputc(sep,f);
fprintf(f, "%d", *(el->NumPosNodes));
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->NodesExamined);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->PathologyStage);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ReasonNoSurg);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->pcr);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%g", *(el->rcbIndex));
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->rcbClass);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void followUpStaticLoadWithNull(char **row, struct followUp *ret)
/* Load a row from followUp table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->RtTherapy = row[1];
ret->RtBreast = row[2];
ret->RtBoost = row[3];
ret->RtAxilla = row[4];
ret->RtSNode = row[5];
ret->RtIMamNode = row[6];
ret->RTChestW = row[7];
ret->RtOther = row[8];
}
struct followUp *followUpLoadWithNull(char **row)
/* Load a followUp from row fetched with select * from followUp
* from database. Dispose of this with followUpFree(). */
{
struct followUp *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->RtTherapy = cloneString(row[1]);
ret->RtBreast = cloneString(row[2]);
ret->RtBoost = cloneString(row[3]);
ret->RtAxilla = cloneString(row[4]);
ret->RtSNode = cloneString(row[5]);
ret->RtIMamNode = cloneString(row[6]);
ret->RTChestW = cloneString(row[7]);
ret->RtOther = cloneString(row[8]);
return ret;
}
struct followUp *followUpLoadAll(char *fileName)
/* Load all followUp from a whitespace-separated file.
* Dispose of this with followUpFreeList(). */
{
struct followUp *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[9];
while (lineFileRow(lf, row))
{
el = followUpLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct followUp *followUpLoadAllByChar(char *fileName, char chopper)
/* Load all followUp from a chopper separated file.
* Dispose of this with followUpFreeList(). */
{
struct followUp *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[9];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = followUpLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct followUp *followUpLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all followUp 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 followUpFreeList(). */
{
struct followUp *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = followUpLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void followUpSaveToDb(struct sqlConnection *conn, struct followUp *el, char *tableName, int updateSize)
/* Save followUp 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use followUpSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s','%s','%s','%s')",
tableName, el->ispyId, el->RtTherapy, el->RtBreast, el->RtBoost, el->RtAxilla, el->RtSNode, el->RtIMamNode, el->RTChestW, el->RtOther);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void followUpSaveToDbEscaped(struct sqlConnection *conn, struct followUp *el, char *tableName, int updateSize)
/* Save followUp 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than followUpSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *RtTherapy, *RtBreast, *RtBoost, *RtAxilla, *RtSNode, *RtIMamNode, *RTChestW, *RtOther;
ispyId = sqlEscapeString(el->ispyId);
RtTherapy = sqlEscapeString(el->RtTherapy);
RtBreast = sqlEscapeString(el->RtBreast);
RtBoost = sqlEscapeString(el->RtBoost);
RtAxilla = sqlEscapeString(el->RtAxilla);
RtSNode = sqlEscapeString(el->RtSNode);
RtIMamNode = sqlEscapeString(el->RtIMamNode);
RTChestW = sqlEscapeString(el->RTChestW);
RtOther = sqlEscapeString(el->RtOther);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s','%s','%s','%s')",
tableName, ispyId, RtTherapy, RtBreast, RtBoost, RtAxilla, RtSNode, RtIMamNode, RTChestW, RtOther);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&RtTherapy);
freez(&RtBreast);
freez(&RtBoost);
freez(&RtAxilla);
freez(&RtSNode);
freez(&RtIMamNode);
freez(&RTChestW);
freez(&RtOther);
}
struct followUp *followUpCommaIn(char **pS, struct followUp *ret)
/* Create a followUp out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new followUp */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->RtTherapy = sqlStringComma(&s);
ret->RtBreast = sqlStringComma(&s);
ret->RtBoost = sqlStringComma(&s);
ret->RtAxilla = sqlStringComma(&s);
ret->RtSNode = sqlStringComma(&s);
ret->RtIMamNode = sqlStringComma(&s);
ret->RTChestW = sqlStringComma(&s);
ret->RtOther = sqlStringComma(&s);
*pS = s;
return ret;
}
void followUpFree(struct followUp **pEl)
/* Free a single dynamically allocated followUp such as created
* with followUpLoad(). */
{
struct followUp *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->RtTherapy);
freeMem(el->RtBreast);
freeMem(el->RtBoost);
freeMem(el->RtAxilla);
freeMem(el->RtSNode);
freeMem(el->RtIMamNode);
freeMem(el->RTChestW);
freeMem(el->RtOther);
freez(pEl);
}
void followUpFreeList(struct followUp **pList)
/* Free a list of dynamically allocated followUp's */
{
struct followUp *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
followUpFree(&el);
}
*pList = NULL;
}
void followUpOutput(struct followUp *el, FILE *f, char sep, char lastSep)
/* Print out followUp. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->RtTherapy);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->RtBreast);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->RtBoost);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->RtAxilla);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->RtSNode);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->RtIMamNode);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->RTChestW);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->RtOther);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void respEvalStaticLoadWithNull(char **row, struct respEval *ret)
/* Load a row from respEval table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
if (row[1] != NULL)
{
ret->TSizeClinical = needMem(sizeof(float));
*(ret->TSizeClinical) = sqlFloat(row[1]);
}
if (row[2] != NULL)
{
ret->NSizeClinical = needMem(sizeof(float));
*(ret->NSizeClinical) = sqlFloat(row[2]);
}
ret->StageTe = row[3];
ret->StageNe = row[4];
ret->StageMe = row[5];
ret->ClinicalStage = row[6];
ret->ClinRespT1_T2 = row[7];
ret->ClinRespT1_T3 = row[8];
ret->ClinRespT1_T4 = row[9];
}
struct respEval *respEvalLoadWithNull(char **row)
/* Load a respEval from row fetched with select * from respEval
* from database. Dispose of this with respEvalFree(). */
{
struct respEval *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
if (row[1] != NULL)
{
ret->TSizeClinical = needMem(sizeof(float));
*(ret->TSizeClinical) = sqlFloat(row[1]);
}
if (row[2] != NULL)
{
ret->NSizeClinical = needMem(sizeof(float));
*(ret->NSizeClinical) = sqlFloat(row[2]);
}
ret->StageTe = cloneString(row[3]);
ret->StageNe = cloneString(row[4]);
ret->StageMe = cloneString(row[5]);
ret->ClinicalStage = cloneString(row[6]);
ret->ClinRespT1_T2 = cloneString(row[7]);
ret->ClinRespT1_T3 = cloneString(row[8]);
ret->ClinRespT1_T4 = cloneString(row[9]);
return ret;
}
struct respEval *respEvalLoadAll(char *fileName)
/* Load all respEval from a whitespace-separated file.
* Dispose of this with respEvalFreeList(). */
{
struct respEval *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[10];
while (lineFileRow(lf, row))
{
el = respEvalLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct respEval *respEvalLoadAllByChar(char *fileName, char chopper)
/* Load all respEval from a chopper separated file.
* Dispose of this with respEvalFreeList(). */
{
struct respEval *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[10];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = respEvalLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct respEval *respEvalLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all respEval 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 respEvalFreeList(). */
{
struct respEval *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = respEvalLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void respEvalSaveToDb(struct sqlConnection *conn, struct respEval *el, char *tableName, int updateSize)
/* Save respEval 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use respEvalSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s',%g,%g,'%s','%s','%s','%s','%s','%s','%s')",
tableName, el->ispyId, *(el->TSizeClinical), *(el->NSizeClinical), el->StageTe, el->StageNe, el->StageMe, el->ClinicalStage, el->ClinRespT1_T2, el->ClinRespT1_T3, el->ClinRespT1_T4);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void respEvalSaveToDbEscaped(struct sqlConnection *conn, struct respEval *el, char *tableName, int updateSize)
/* Save respEval 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than respEvalSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *StageTe, *StageNe, *StageMe, *ClinicalStage, *ClinRespT1_T2, *ClinRespT1_T3, *ClinRespT1_T4;
ispyId = sqlEscapeString(el->ispyId);
StageTe = sqlEscapeString(el->StageTe);
StageNe = sqlEscapeString(el->StageNe);
StageMe = sqlEscapeString(el->StageMe);
ClinicalStage = sqlEscapeString(el->ClinicalStage);
ClinRespT1_T2 = sqlEscapeString(el->ClinRespT1_T2);
ClinRespT1_T3 = sqlEscapeString(el->ClinRespT1_T3);
ClinRespT1_T4 = sqlEscapeString(el->ClinRespT1_T4);
dyStringPrintf(update, "insert into %s values ( '%s',%g,%g,'%s','%s','%s','%s','%s','%s','%s')",
tableName, ispyId, *(el->TSizeClinical), *(el->NSizeClinical), StageTe, StageNe, StageMe, ClinicalStage, ClinRespT1_T2, ClinRespT1_T3, ClinRespT1_T4);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&StageTe);
freez(&StageNe);
freez(&StageMe);
freez(&ClinicalStage);
freez(&ClinRespT1_T2);
freez(&ClinRespT1_T3);
freez(&ClinRespT1_T4);
}
struct respEval *respEvalCommaIn(char **pS, struct respEval *ret)
/* Create a respEval out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new respEval */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->TSizeClinical = needMem(sizeof(*(ret->TSizeClinical)));
*(ret->TSizeClinical) = sqlFloatComma(&s);
ret->NSizeClinical = needMem(sizeof(*(ret->NSizeClinical)));
*(ret->NSizeClinical) = sqlFloatComma(&s);
ret->StageTe = sqlStringComma(&s);
ret->StageNe = sqlStringComma(&s);
ret->StageMe = sqlStringComma(&s);
ret->ClinicalStage = sqlStringComma(&s);
ret->ClinRespT1_T2 = sqlStringComma(&s);
ret->ClinRespT1_T3 = sqlStringComma(&s);
ret->ClinRespT1_T4 = sqlStringComma(&s);
*pS = s;
return ret;
}
void respEvalFree(struct respEval **pEl)
/* Free a single dynamically allocated respEval such as created
* with respEvalLoad(). */
{
struct respEval *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->StageTe);
freeMem(el->StageNe);
freeMem(el->StageMe);
freeMem(el->ClinicalStage);
freeMem(el->ClinRespT1_T2);
freeMem(el->ClinRespT1_T3);
freeMem(el->ClinRespT1_T4);
freez(pEl);
}
void respEvalFreeList(struct respEval **pList)
/* Free a list of dynamically allocated respEval's */
{
struct respEval *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
respEvalFree(&el);
}
*pList = NULL;
}
void respEvalOutput(struct respEval *el, FILE *f, char sep, char lastSep)
/* Print out respEval. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%g", *(el->TSizeClinical));
fputc(sep,f);
fprintf(f, "%g", *(el->NSizeClinical));
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->StageTe);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->StageNe);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->StageMe);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ClinicalStage);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ClinRespT1_T2);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ClinRespT1_T3);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ClinRespT1_T4);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void mrStaticLoadWithNull(char **row, struct mr *ret)
/* Load a row from mr table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->ChemoCat = row[1];
ret->DoseDenseAnthra = row[2];
ret->DoseDenseTaxane = row[3];
ret->LES_T1 = row[4];
ret->LES_T2 = row[5];
ret->LES_T3 = row[6];
ret->LES_T4 = row[7];
if (row[8] != NULL)
{
ret->LD_T1 = needMem(sizeof(*(ret->LD_T1)));
*(ret->LD_T1) = sqlSigned(row[8]);
}
else
{
ret->LD_T1 = NULL;
}
if (row[9] != NULL)
{
ret->LD_T2 = needMem(sizeof(*(ret->LD_T2)));
*(ret->LD_T2) = sqlSigned(row[9]);
}
else
{
ret->LD_T2 = NULL;
}
if (row[10] != NULL)
{
ret->LD_T3 = needMem(sizeof(*(ret->LD_T3)));
*(ret->LD_T3) = sqlSigned(row[10]);
}
else
{
ret->LD_T3 = NULL;
}
if (row[11] != NULL)
{
ret->LD_T4 = needMem(sizeof(*(ret->LD_T4)));
*(ret->LD_T4) = sqlSigned(row[11]);
}
else
{
ret->LD_T4 = NULL;
}
if (row[12] != NULL)
{
ret->LD_T1_T2_PERCT = needMem(sizeof(float));
*(ret->LD_T1_T2_PERCT) = sqlFloat(row[12]);
}
if (row[13] != NULL)
{
ret->LD_T1_T3_PERCT = needMem(sizeof(float));
*(ret->LD_T1_T3_PERCT) = sqlFloat(row[13]);
}
if (row[14] != NULL)
{
ret->LD_T1_T4_PERCT = needMem(sizeof(float));
*(ret->LD_T1_T4_PERCT) = sqlFloat(row[14]);
}
if (row[15] != NULL)
{
ret->LD_T2_T3_PERCT = needMem(sizeof(float));
*(ret->LD_T2_T3_PERCT) = sqlFloat(row[15]);
}
if (row[16] != NULL)
{
ret->LD_T2_T4_PERCT = needMem(sizeof(float));
*(ret->LD_T2_T4_PERCT) = sqlFloat(row[16]);
}
if (row[17] != NULL)
{
ret->LD_T3_T4_PERCT = needMem(sizeof(float));
*(ret->LD_T3_T4_PERCT) = sqlFloat(row[17]);
}
ret->Mri_Pattern_Code = row[18];
ret->Mri_Pattern_Desc = row[19];
}
struct mr *mrLoadWithNull(char **row)
/* Load a mr from row fetched with select * from mr
* from database. Dispose of this with mrFree(). */
{
struct mr *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->ChemoCat = cloneString(row[1]);
ret->DoseDenseAnthra = cloneString(row[2]);
ret->DoseDenseTaxane = cloneString(row[3]);
ret->LES_T1 = cloneString(row[4]);
ret->LES_T2 = cloneString(row[5]);
ret->LES_T3 = cloneString(row[6]);
ret->LES_T4 = cloneString(row[7]);
if (row[8] != NULL)
{
ret->LD_T1 = needMem(sizeof(*(ret->LD_T1)));
*(ret->LD_T1) = sqlSigned(row[8]);
}
else
{
ret->LD_T1 = NULL;
}
if (row[9] != NULL)
{
ret->LD_T2 = needMem(sizeof(*(ret->LD_T2)));
*(ret->LD_T2) = sqlSigned(row[9]);
}
else
{
ret->LD_T2 = NULL;
}
if (row[10] != NULL)
{
ret->LD_T3 = needMem(sizeof(*(ret->LD_T3)));
*(ret->LD_T3) = sqlSigned(row[10]);
}
else
{
ret->LD_T3 = NULL;
}
if (row[11] != NULL)
{
ret->LD_T4 = needMem(sizeof(*(ret->LD_T4)));
*(ret->LD_T4) = sqlSigned(row[11]);
}
else
{
ret->LD_T4 = NULL;
}
if (row[12] != NULL)
{
ret->LD_T1_T2_PERCT = needMem(sizeof(float));
*(ret->LD_T1_T2_PERCT) = sqlFloat(row[12]);
}
if (row[13] != NULL)
{
ret->LD_T1_T3_PERCT = needMem(sizeof(float));
*(ret->LD_T1_T3_PERCT) = sqlFloat(row[13]);
}
if (row[14] != NULL)
{
ret->LD_T1_T4_PERCT = needMem(sizeof(float));
*(ret->LD_T1_T4_PERCT) = sqlFloat(row[14]);
}
if (row[15] != NULL)
{
ret->LD_T2_T3_PERCT = needMem(sizeof(float));
*(ret->LD_T2_T3_PERCT) = sqlFloat(row[15]);
}
if (row[16] != NULL)
{
ret->LD_T2_T4_PERCT = needMem(sizeof(float));
*(ret->LD_T2_T4_PERCT) = sqlFloat(row[16]);
}
if (row[17] != NULL)
{
ret->LD_T3_T4_PERCT = needMem(sizeof(float));
*(ret->LD_T3_T4_PERCT) = sqlFloat(row[17]);
}
ret->Mri_Pattern_Code = cloneString(row[18]);
ret->Mri_Pattern_Desc = cloneString(row[19]);
return ret;
}
struct mr *mrLoadAll(char *fileName)
/* Load all mr from a whitespace-separated file.
* Dispose of this with mrFreeList(). */
{
struct mr *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[20];
while (lineFileRow(lf, row))
{
el = mrLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct mr *mrLoadAllByChar(char *fileName, char chopper)
/* Load all mr from a chopper separated file.
* Dispose of this with mrFreeList(). */
{
struct mr *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[20];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = mrLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct mr *mrLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all mr 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 mrFreeList(). */
{
struct mr *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = mrLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void mrSaveToDb(struct sqlConnection *conn, struct mr *el, char *tableName, int updateSize)
/* Save mr 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use mrSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s','%s','%s',%d,%d,%d,%d,%g,%g,%g,%g,%g,%g,'%s','%s')",
tableName, el->ispyId, el->ChemoCat, el->DoseDenseAnthra, el->DoseDenseTaxane, el->LES_T1, el->LES_T2, el->LES_T3, el->LES_T4, *(el->LD_T1), *(el->LD_T2), *(el->LD_T3), *(el->LD_T4), *(el->LD_T1_T2_PERCT), *(el->LD_T1_T3_PERCT), *(el->LD_T1_T4_PERCT), *(el->LD_T2_T3_PERCT), *(el->LD_T2_T4_PERCT), *(el->LD_T3_T4_PERCT), el->Mri_Pattern_Code, el->Mri_Pattern_Desc);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void mrSaveToDbEscaped(struct sqlConnection *conn, struct mr *el, char *tableName, int updateSize)
/* Save mr 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than mrSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *ChemoCat, *DoseDenseAnthra, *DoseDenseTaxane, *LES_T1, *LES_T2, *LES_T3, *LES_T4, *Mri_Pattern_Code, *Mri_Pattern_Desc;
ispyId = sqlEscapeString(el->ispyId);
ChemoCat = sqlEscapeString(el->ChemoCat);
DoseDenseAnthra = sqlEscapeString(el->DoseDenseAnthra);
DoseDenseTaxane = sqlEscapeString(el->DoseDenseTaxane);
LES_T1 = sqlEscapeString(el->LES_T1);
LES_T2 = sqlEscapeString(el->LES_T2);
LES_T3 = sqlEscapeString(el->LES_T3);
LES_T4 = sqlEscapeString(el->LES_T4);
Mri_Pattern_Code = sqlEscapeString(el->Mri_Pattern_Code);
Mri_Pattern_Desc = sqlEscapeString(el->Mri_Pattern_Desc);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s','%s','%s','%s',%d,%d,%d,%d,%g,%g,%g,%g,%g,%g,'%s','%s')",
tableName, ispyId, ChemoCat, DoseDenseAnthra, DoseDenseTaxane, LES_T1, LES_T2, LES_T3, LES_T4, *(el->LD_T1), *(el->LD_T2), *(el->LD_T3), *(el->LD_T4), *(el->LD_T1_T2_PERCT), *(el->LD_T1_T3_PERCT), *(el->LD_T1_T4_PERCT), *(el->LD_T2_T3_PERCT), *(el->LD_T2_T4_PERCT), *(el->LD_T3_T4_PERCT), Mri_Pattern_Code, Mri_Pattern_Desc);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&ChemoCat);
freez(&DoseDenseAnthra);
freez(&DoseDenseTaxane);
freez(&LES_T1);
freez(&LES_T2);
freez(&LES_T3);
freez(&LES_T4);
freez(&Mri_Pattern_Code);
freez(&Mri_Pattern_Desc);
}
struct mr *mrCommaIn(char **pS, struct mr *ret)
/* Create a mr out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new mr */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->ChemoCat = sqlStringComma(&s);
ret->DoseDenseAnthra = sqlStringComma(&s);
ret->DoseDenseTaxane = sqlStringComma(&s);
ret->LES_T1 = sqlStringComma(&s);
ret->LES_T2 = sqlStringComma(&s);
ret->LES_T3 = sqlStringComma(&s);
ret->LES_T4 = sqlStringComma(&s);
ret->LD_T1 = needMem(sizeof(*(ret->LD_T1)));
*(ret->LD_T1) = sqlSignedComma(&s);
ret->LD_T2 = needMem(sizeof(*(ret->LD_T2)));
*(ret->LD_T2) = sqlSignedComma(&s);
ret->LD_T3 = needMem(sizeof(*(ret->LD_T3)));
*(ret->LD_T3) = sqlSignedComma(&s);
ret->LD_T4 = needMem(sizeof(*(ret->LD_T4)));
*(ret->LD_T4) = sqlSignedComma(&s);
ret->LD_T1_T2_PERCT = needMem(sizeof(*(ret->LD_T1_T2_PERCT)));
*(ret->LD_T1_T2_PERCT) = sqlFloatComma(&s);
ret->LD_T1_T3_PERCT = needMem(sizeof(*(ret->LD_T1_T3_PERCT)));
*(ret->LD_T1_T3_PERCT) = sqlFloatComma(&s);
ret->LD_T1_T4_PERCT = needMem(sizeof(*(ret->LD_T1_T4_PERCT)));
*(ret->LD_T1_T4_PERCT) = sqlFloatComma(&s);
ret->LD_T2_T3_PERCT = needMem(sizeof(*(ret->LD_T2_T3_PERCT)));
*(ret->LD_T2_T3_PERCT) = sqlFloatComma(&s);
ret->LD_T2_T4_PERCT = needMem(sizeof(*(ret->LD_T2_T4_PERCT)));
*(ret->LD_T2_T4_PERCT) = sqlFloatComma(&s);
ret->LD_T3_T4_PERCT = needMem(sizeof(*(ret->LD_T3_T4_PERCT)));
*(ret->LD_T3_T4_PERCT) = sqlFloatComma(&s);
ret->Mri_Pattern_Code = sqlStringComma(&s);
ret->Mri_Pattern_Desc = sqlStringComma(&s);
*pS = s;
return ret;
}
void mrFree(struct mr **pEl)
/* Free a single dynamically allocated mr such as created
* with mrLoad(). */
{
struct mr *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->ChemoCat);
freeMem(el->DoseDenseAnthra);
freeMem(el->DoseDenseTaxane);
freeMem(el->LES_T1);
freeMem(el->LES_T2);
freeMem(el->LES_T3);
freeMem(el->LES_T4);
freeMem(el->Mri_Pattern_Code);
freeMem(el->Mri_Pattern_Desc);
freez(pEl);
}
void mrFreeList(struct mr **pList)
/* Free a list of dynamically allocated mr's */
{
struct mr *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
mrFree(&el);
}
*pList = NULL;
}
void mrOutput(struct mr *el, FILE *f, char sep, char lastSep)
/* Print out mr. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ChemoCat);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->DoseDenseAnthra);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->DoseDenseTaxane);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->LES_T1);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->LES_T2);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->LES_T3);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->LES_T4);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%d", *(el->LD_T1));
fputc(sep,f);
fprintf(f, "%d", *(el->LD_T2));
fputc(sep,f);
fprintf(f, "%d", *(el->LD_T3));
fputc(sep,f);
fprintf(f, "%d", *(el->LD_T4));
fputc(sep,f);
fprintf(f, "%g", *(el->LD_T1_T2_PERCT));
fputc(sep,f);
fprintf(f, "%g", *(el->LD_T1_T3_PERCT));
fputc(sep,f);
fprintf(f, "%g", *(el->LD_T1_T4_PERCT));
fputc(sep,f);
fprintf(f, "%g", *(el->LD_T2_T3_PERCT));
fputc(sep,f);
fprintf(f, "%g", *(el->LD_T2_T4_PERCT));
fputc(sep,f);
fprintf(f, "%g", *(el->LD_T3_T4_PERCT));
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Mri_Pattern_Code);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Mri_Pattern_Desc);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void cdnaStaticLoadWithNull(char **row, struct cdna *ret)
/* Load a row from cdna table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->Cdna_T1 = row[1];
ret->Cdna_T2 = row[2];
ret->Cdna_T3 = row[3];
ret->Cdna_T4 = row[4];
}
struct cdna *cdnaLoadWithNull(char **row)
/* Load a cdna from row fetched with select * from cdna
* from database. Dispose of this with cdnaFree(). */
{
struct cdna *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->Cdna_T1 = cloneString(row[1]);
ret->Cdna_T2 = cloneString(row[2]);
ret->Cdna_T3 = cloneString(row[3]);
ret->Cdna_T4 = cloneString(row[4]);
return ret;
}
struct cdna *cdnaLoadAll(char *fileName)
/* Load all cdna from a whitespace-separated file.
* Dispose of this with cdnaFreeList(). */
{
struct cdna *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[5];
while (lineFileRow(lf, row))
{
el = cdnaLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct cdna *cdnaLoadAllByChar(char *fileName, char chopper)
/* Load all cdna from a chopper separated file.
* Dispose of this with cdnaFreeList(). */
{
struct cdna *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[5];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = cdnaLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct cdna *cdnaLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all cdna 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 cdnaFreeList(). */
{
struct cdna *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = cdnaLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void cdnaSaveToDb(struct sqlConnection *conn, struct cdna *el, char *tableName, int updateSize)
/* Save cdna 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use cdnaSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s')",
tableName, el->ispyId, el->Cdna_T1, el->Cdna_T2, el->Cdna_T3, el->Cdna_T4);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void cdnaSaveToDbEscaped(struct sqlConnection *conn, struct cdna *el, char *tableName, int updateSize)
/* Save cdna 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than cdnaSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *Cdna_T1, *Cdna_T2, *Cdna_T3, *Cdna_T4;
ispyId = sqlEscapeString(el->ispyId);
Cdna_T1 = sqlEscapeString(el->Cdna_T1);
Cdna_T2 = sqlEscapeString(el->Cdna_T2);
Cdna_T3 = sqlEscapeString(el->Cdna_T3);
Cdna_T4 = sqlEscapeString(el->Cdna_T4);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s')",
tableName, ispyId, Cdna_T1, Cdna_T2, Cdna_T3, Cdna_T4);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&Cdna_T1);
freez(&Cdna_T2);
freez(&Cdna_T3);
freez(&Cdna_T4);
}
struct cdna *cdnaCommaIn(char **pS, struct cdna *ret)
/* Create a cdna out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new cdna */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->Cdna_T1 = sqlStringComma(&s);
ret->Cdna_T2 = sqlStringComma(&s);
ret->Cdna_T3 = sqlStringComma(&s);
ret->Cdna_T4 = sqlStringComma(&s);
*pS = s;
return ret;
}
void cdnaFree(struct cdna **pEl)
/* Free a single dynamically allocated cdna such as created
* with cdnaLoad(). */
{
struct cdna *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->Cdna_T1);
freeMem(el->Cdna_T2);
freeMem(el->Cdna_T3);
freeMem(el->Cdna_T4);
freez(pEl);
}
void cdnaFreeList(struct cdna **pList)
/* Free a list of dynamically allocated cdna's */
{
struct cdna *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
cdnaFree(&el);
}
*pList = NULL;
}
void cdnaOutput(struct cdna *el, FILE *f, char sep, char lastSep)
/* Print out cdna. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Cdna_T1);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Cdna_T2);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Cdna_T3);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Cdna_T4);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void agiStaticLoadWithNull(char **row, struct agi *ret)
/* Load a row from agi table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->Agi_T1 = row[1];
ret->Agi_T2 = row[2];
ret->Agi_T3 = row[3];
ret->Agi_T4 = row[4];
}
struct agi *agiLoadWithNull(char **row)
/* Load a agi from row fetched with select * from agi
* from database. Dispose of this with agiFree(). */
{
struct agi *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->Agi_T1 = cloneString(row[1]);
ret->Agi_T2 = cloneString(row[2]);
ret->Agi_T3 = cloneString(row[3]);
ret->Agi_T4 = cloneString(row[4]);
return ret;
}
struct agi *agiLoadAll(char *fileName)
/* Load all agi from a whitespace-separated file.
* Dispose of this with agiFreeList(). */
{
struct agi *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[5];
while (lineFileRow(lf, row))
{
el = agiLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct agi *agiLoadAllByChar(char *fileName, char chopper)
/* Load all agi from a chopper separated file.
* Dispose of this with agiFreeList(). */
{
struct agi *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[5];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = agiLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct agi *agiLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all agi 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 agiFreeList(). */
{
struct agi *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = agiLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void agiSaveToDb(struct sqlConnection *conn, struct agi *el, char *tableName, int updateSize)
/* Save agi 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use agiSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s')",
tableName, el->ispyId, el->Agi_T1, el->Agi_T2, el->Agi_T3, el->Agi_T4);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void agiSaveToDbEscaped(struct sqlConnection *conn, struct agi *el, char *tableName, int updateSize)
/* Save agi 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than agiSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *Agi_T1, *Agi_T2, *Agi_T3, *Agi_T4;
ispyId = sqlEscapeString(el->ispyId);
Agi_T1 = sqlEscapeString(el->Agi_T1);
Agi_T2 = sqlEscapeString(el->Agi_T2);
Agi_T3 = sqlEscapeString(el->Agi_T3);
Agi_T4 = sqlEscapeString(el->Agi_T4);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s')",
tableName, ispyId, Agi_T1, Agi_T2, Agi_T3, Agi_T4);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&Agi_T1);
freez(&Agi_T2);
freez(&Agi_T3);
freez(&Agi_T4);
}
struct agi *agiCommaIn(char **pS, struct agi *ret)
/* Create a agi out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new agi */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->Agi_T1 = sqlStringComma(&s);
ret->Agi_T2 = sqlStringComma(&s);
ret->Agi_T3 = sqlStringComma(&s);
ret->Agi_T4 = sqlStringComma(&s);
*pS = s;
return ret;
}
void agiFree(struct agi **pEl)
/* Free a single dynamically allocated agi such as created
* with agiLoad(). */
{
struct agi *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->Agi_T1);
freeMem(el->Agi_T2);
freeMem(el->Agi_T3);
freeMem(el->Agi_T4);
freez(pEl);
}
void agiFreeList(struct agi **pList)
/* Free a list of dynamically allocated agi's */
{
struct agi *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
agiFree(&el);
}
*pList = NULL;
}
void agiOutput(struct agi *el, FILE *f, char sep, char lastSep)
/* Print out agi. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Agi_T1);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Agi_T2);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Agi_T3);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Agi_T4);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void ihcStaticLoadWithNull(char **row, struct ihc *ret)
/* Load a row from ihc table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->Ihc_T1 = row[1];
ret->Ihc_T2 = row[2];
ret->Ihc_T3 = row[3];
ret->Ihc_T4 = row[4];
}
struct ihc *ihcLoadWithNull(char **row)
/* Load a ihc from row fetched with select * from ihc
* from database. Dispose of this with ihcFree(). */
{
struct ihc *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->Ihc_T1 = cloneString(row[1]);
ret->Ihc_T2 = cloneString(row[2]);
ret->Ihc_T3 = cloneString(row[3]);
ret->Ihc_T4 = cloneString(row[4]);
return ret;
}
struct ihc *ihcLoadAll(char *fileName)
/* Load all ihc from a whitespace-separated file.
* Dispose of this with ihcFreeList(). */
{
struct ihc *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[5];
while (lineFileRow(lf, row))
{
el = ihcLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct ihc *ihcLoadAllByChar(char *fileName, char chopper)
/* Load all ihc from a chopper separated file.
* Dispose of this with ihcFreeList(). */
{
struct ihc *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[5];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = ihcLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct ihc *ihcLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all ihc 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 ihcFreeList(). */
{
struct ihc *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = ihcLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void ihcSaveToDb(struct sqlConnection *conn, struct ihc *el, char *tableName, int updateSize)
/* Save ihc 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use ihcSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s')",
tableName, el->ispyId, el->Ihc_T1, el->Ihc_T2, el->Ihc_T3, el->Ihc_T4);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void ihcSaveToDbEscaped(struct sqlConnection *conn, struct ihc *el, char *tableName, int updateSize)
/* Save ihc 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than ihcSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *Ihc_T1, *Ihc_T2, *Ihc_T3, *Ihc_T4;
ispyId = sqlEscapeString(el->ispyId);
Ihc_T1 = sqlEscapeString(el->Ihc_T1);
Ihc_T2 = sqlEscapeString(el->Ihc_T2);
Ihc_T3 = sqlEscapeString(el->Ihc_T3);
Ihc_T4 = sqlEscapeString(el->Ihc_T4);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s')",
tableName, ispyId, Ihc_T1, Ihc_T2, Ihc_T3, Ihc_T4);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&Ihc_T1);
freez(&Ihc_T2);
freez(&Ihc_T3);
freez(&Ihc_T4);
}
struct ihc *ihcCommaIn(char **pS, struct ihc *ret)
/* Create a ihc out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new ihc */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->Ihc_T1 = sqlStringComma(&s);
ret->Ihc_T2 = sqlStringComma(&s);
ret->Ihc_T3 = sqlStringComma(&s);
ret->Ihc_T4 = sqlStringComma(&s);
*pS = s;
return ret;
}
void ihcFree(struct ihc **pEl)
/* Free a single dynamically allocated ihc such as created
* with ihcLoad(). */
{
struct ihc *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->Ihc_T1);
freeMem(el->Ihc_T2);
freeMem(el->Ihc_T3);
freeMem(el->Ihc_T4);
freez(pEl);
}
void ihcFreeList(struct ihc **pList)
/* Free a list of dynamically allocated ihc's */
{
struct ihc *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
ihcFree(&el);
}
*pList = NULL;
}
void ihcOutput(struct ihc *el, FILE *f, char sep, char lastSep)
/* Print out ihc. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Ihc_T1);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Ihc_T2);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Ihc_T3);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Ihc_T4);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
void fishStaticLoadWithNull(char **row, struct fish *ret)
/* Load a row from fish table into ret. The contents of ret will
* be replaced at the next call to this function. */
{
ret->ispyId = row[0];
ret->Fish_T1 = row[1];
ret->Fish_T2 = row[2];
ret->Fish_T3 = row[3];
ret->Fish_T4 = row[4];
}
struct fish *fishLoadWithNull(char **row)
/* Load a fish from row fetched with select * from fish
* from database. Dispose of this with fishFree(). */
{
struct fish *ret;
AllocVar(ret);
ret->ispyId = cloneString(row[0]);
ret->Fish_T1 = cloneString(row[1]);
ret->Fish_T2 = cloneString(row[2]);
ret->Fish_T3 = cloneString(row[3]);
ret->Fish_T4 = cloneString(row[4]);
return ret;
}
struct fish *fishLoadAll(char *fileName)
/* Load all fish from a whitespace-separated file.
* Dispose of this with fishFreeList(). */
{
struct fish *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[5];
while (lineFileRow(lf, row))
{
el = fishLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct fish *fishLoadAllByChar(char *fileName, char chopper)
/* Load all fish from a chopper separated file.
* Dispose of this with fishFreeList(). */
{
struct fish *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[5];
while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
{
el = fishLoadWithNull(row);
slAddHead(&list, el);
}
lineFileClose(&lf);
slReverse(&list);
return list;
}
struct fish *fishLoadByQuery(struct sqlConnection *conn, char *query)
/* Load all fish 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 fishFreeList(). */
{
struct fish *list = NULL, *el;
struct sqlResult *sr;
char **row;
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
{
el = fishLoadWithNull(row);
slAddHead(&list, el);
}
slReverse(&list);
sqlFreeResult(&sr);
return list;
}
void fishSaveToDb(struct sqlConnection *conn, struct fish *el, char *tableName, int updateSize)
/* Save fish 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. Note that strings must be escaped to allow insertion into the database.
* For example "autosql's features include" --> "autosql\'s features include"
* If worried about this use fishSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s')",
tableName, el->ispyId, el->Fish_T1, el->Fish_T2, el->Fish_T3, el->Fish_T4);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void fishSaveToDbEscaped(struct sqlConnection *conn, struct fish *el, char *tableName, int updateSize)
/* Save fish 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. Automatically
* escapes all simple strings (not arrays of string) but may be slower than fishSaveToDb().
* For example automatically copies and converts:
* "autosql's features include" --> "autosql\'s features include"
* before inserting into database. */
{
struct dyString *update = newDyString(updateSize);
char *ispyId, *Fish_T1, *Fish_T2, *Fish_T3, *Fish_T4;
ispyId = sqlEscapeString(el->ispyId);
Fish_T1 = sqlEscapeString(el->Fish_T1);
Fish_T2 = sqlEscapeString(el->Fish_T2);
Fish_T3 = sqlEscapeString(el->Fish_T3);
Fish_T4 = sqlEscapeString(el->Fish_T4);
dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s')",
tableName, ispyId, Fish_T1, Fish_T2, Fish_T3, Fish_T4);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&ispyId);
freez(&Fish_T1);
freez(&Fish_T2);
freez(&Fish_T3);
freez(&Fish_T4);
}
struct fish *fishCommaIn(char **pS, struct fish *ret)
/* Create a fish out of a comma separated string.
* This will fill in ret if non-null, otherwise will
* return a new fish */
{
char *s = *pS;
if (ret == NULL)
AllocVar(ret);
ret->ispyId = sqlStringComma(&s);
ret->Fish_T1 = sqlStringComma(&s);
ret->Fish_T2 = sqlStringComma(&s);
ret->Fish_T3 = sqlStringComma(&s);
ret->Fish_T4 = sqlStringComma(&s);
*pS = s;
return ret;
}
void fishFree(struct fish **pEl)
/* Free a single dynamically allocated fish such as created
* with fishLoad(). */
{
struct fish *el;
if ((el = *pEl) == NULL) return;
freeMem(el->ispyId);
freeMem(el->Fish_T1);
freeMem(el->Fish_T2);
freeMem(el->Fish_T3);
freeMem(el->Fish_T4);
freez(pEl);
}
void fishFreeList(struct fish **pList)
/* Free a list of dynamically allocated fish's */
{
struct fish *el, *next;
for (el = *pList; el != NULL; el = next)
{
next = el->next;
fishFree(&el);
}
*pList = NULL;
}
void fishOutput(struct fish *el, FILE *f, char sep, char lastSep)
/* Print out fish. Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ispyId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Fish_T1);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Fish_T2);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Fish_T3);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->Fish_T4);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}
/* -------------------------------- End autoSql Generated Code -------------------------------- */