void vgLoadJax(char *visiGeneDir, char *jaxDb, char *outDir) /* vgLoadJax - Load visiGene database from jackson database. */ { struct sqlConnection *conn = sqlConnect(jaxDb); struct sqlConnection *conn2 = sqlConnect(jaxDb); struct sqlConnection *connSp = sqlConnect("uniProt"); char inFull[PATH_LEN]; char *jaxPath = "inSitu/Mouse/jax"; char inJax[PATH_LEN]; #ifdef UNUSED /* won't work yet */ char* host = "genome-test"; char* user = cfgOptionEnv("HGDB_USER", "db.user"); char* password = cfgOptionEnv("HGDB_PASSWORD", "db.password"); connSp = sqlConnectRemote(host, user, password, "uniProt"); #endif safef(inFull, sizeof(inFull), "%s/full", visiGeneDir); safef(inJax, sizeof(inJax), "%s/%s", inFull, jaxPath); submitToDir(conn, conn2, connSp, outDir, inJax); sqlDisconnect(&connSp); sqlDisconnect(&conn2); sqlDisconnect(&conn); }
void refPepRepair(char *db, char *accFile, boolean dryRun) /* fix dangling repPep gbSeq entries. */ { struct sqlConnection *conn = sqlConnect(db); struct brokenRefPepTbl *brpTbl; struct extFileTbl* extFileTbl; struct slName *accs = (accFile == NULL) ? NULL : slNameLoadReal(accFile); if (!checkForRefLink(conn)) { sqlDisconnect(&conn); return; } gbVerbMsg(1, "%s: repairing refseq protein gbExtFile entries%s", sqlGetDatabase(conn), (dryRun? " (dry run)" : "")); extFileTbl = extFileTblLoad(conn); brpTbl = brokenRefPepTblNew(conn, accs); brokenRefPepGetSeqScan(conn, extFileTbl, brpTbl); brokenRefPepGetMrnas(conn, brpTbl); fillInFastaOffsets(brpTbl, conn, extFileTbl); if (brpTbl->numToRepair > 0) makeRepairs(brpTbl, conn, extFileTbl, dryRun); else gbVerbMsg(1, "%s: no refseq proteins to repair", sqlGetDatabase(conn)); brokenRefPepTblFree(&brpTbl); extFileTblFree(&extFileTbl); sqlDisconnect(&conn); slFreeList(&accs); }
void doValidatedEmail(struct edwSubmit *submit, boolean isComplete) /* Send an email with info on all validated files */ { struct sqlConnection *conn = edwConnect(); struct edwUser *user = edwUserFromId(conn, submit->userId); struct dyString *message = dyStringNew(0); /* Is this submission has no new file at all */ if ((submit->oldFiles != 0) && (submit->newFiles == 0) && (submit->metaChangeCount == 0) && isEmpty(submit->errorMessage) && (submit->fileIdInTransit == 0)) { dyStringPrintf(message, "Your submission from %s is completed, but validation was not performed for this submission since all files in validate.txt have been previously submitted and validated.\n", submit->url); mailViaPipe(user->email, "EDW Validation Results", message->string, edwDaemonEmail); sqlDisconnect(&conn); dyStringFree(&message); return; } if (isComplete) dyStringPrintf(message, "Your submission from %s is completely validated\n", submit->url); else dyStringPrintf(message, "Your submission hasn't validated after 24 hours, something is probably wrong\n" "at %s\n", submit->url); dyStringPrintf(message, "\n#accession\tsubmitted_file_name\tnotes\n"); char query[512]; sqlSafef(query, sizeof(query), "select licensePlate,submitFileName " " from edwFile left join edwValidFile on edwFile.id = edwValidFile.fileId " " where edwFile.submitId = %u and edwFile.id != %u" , submit->id, submit->submitFileId); struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) { char *licensePlate = row[0]; char *submitFileName = row[1]; dyStringPrintf(message, "%s\t%s\t", naForNull(licensePlate), submitFileName); if (licensePlate == NULL) { dyStringPrintf(message, "Not validating"); } dyStringPrintf(message, "\n"); } sqlFreeResult(&sr); mailViaPipe(user->email, "EDW Validation Results", message->string, edwDaemonEmail); sqlDisconnect(&conn); dyStringFree(&message); }
void mrnaToGene(char *db, char *cdsDb, char *cdsFile, char *pslSpec, char *genePredFile) /* convert an PSL mRNA table to a genePred file */ { struct sqlConnection *conn = NULL; FILE* genePredFh; if (db != NULL) conn = sqlConnect(db); else if (cdsDb != NULL) conn = sqlConnect(cdsDb); genePredFh = mustOpen(genePredFile, "w"); if (cdsFile != NULL) loadCdsFile(cdsFile); if (db == NULL) convertPslFile(conn, pslSpec, genePredFh); else convertPslTable(conn, pslSpec, genePredFh); if (ferror(genePredFh)) errAbort("error writing %s", genePredFile); carefulClose(&genePredFh); sqlDisconnect(&conn); }
void refPepList(char *db, FILE* outFh) /* list of sequences needing repair */ { struct sqlConnection *conn = sqlConnect(db); struct brokenRefPepTbl *brpTbl; struct hashCookie cookie; struct hashEl *hel; struct extFileTbl* extFileTbl = NULL; if (!checkForRefLink(conn)) { sqlDisconnect(&conn); return; } extFileTbl = extFileTblLoad(conn); brpTbl = brokenRefPepTblNew(conn, NULL); brokenRefPepGetSeqScan(conn, extFileTbl, brpTbl); brokenRefPepGetMrnas(conn, brpTbl); extFileTblFree(&extFileTbl); cookie = hashFirst(brpTbl->protAccHash); while ((hel = hashNext(&cookie)) != NULL) { struct brokenRefPep *brp = hel->val; fprintf(outFh, "%s\t%s\t%s\n", sqlGetDatabase(conn), brp->protAcc, (brp->mrnaAcc != NULL)? "repair" : "drop"); } gbVerbMsg(1, "%s: need to repair %d refseq protein gbExtFile entries", sqlGetDatabase(conn), brpTbl->numToRepair); gbVerbMsg(1, "%s: need to drop %d refseq protein gbExtFile entries", sqlGetDatabase(conn), brpTbl->numToDrop); }
void docIdReport(char *database) /* docIdReport - generate report from docIdSub table. */ { struct sqlConnection *conn = sqlConnect(database); struct docIdSub *docIdSub; char query[10 * 1024]; struct sqlResult *sr; char **row; safef(query, sizeof query, "select * from %s", docIdTable); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { docIdSub = docIdSubLoad(row); verbose(2, "ix %d\n", docIdSub->ix); verbose(2, "submitDate %s\n", docIdSub->submitDate); verbose(2, "md5sum %s\n", docIdSub->md5sum); verbose(2, "valReport %s\n", docIdSub->valReport); verbose(2, "metaData %s\n", docIdSub->metaData); verbose(2, "submitPath %s\n", docIdSub->submitPath); verbose(2, "submitter %s\n", docIdSub->submitter); cgiDecode(docIdSub->metaData, docIdSub->metaData, strlen(docIdSub->metaData)); char *tempFile = "temp"; FILE *f = mustOpen(tempFile, "w"); fwrite(docIdSub->metaData, strlen(docIdSub->metaData), 1, f); fclose(f); boolean validated; struct mdbObj *mdbObj = mdbObjsLoadFromFormattedFile(tempFile, &validated); printf("%s %s %s %s %s\n", docIdDecorate(docIdSub->ix), mdbObjFindValue(mdbObj, "dataType"), mdbObjFindValue(mdbObj, "view"), mdbObjFindValue(mdbObj, "cell"), mdbObjFindValue(mdbObj, "lab")); } sqlFreeResult(&sr); sqlDisconnect(&conn); }
struct chromGraph *chromGraphListWithTable(char *fileName, char *db, char *table) /* Read the chromGraph file and convert to the chr,chromStart format. */ { struct sqlConnection *conn = sqlConnect(db); struct hash *posHash = NULL; struct lineFile *lf; struct chromGraph *list = NULL; char *words[2]; checkTableForFields(conn, table); posHash = posHashFromTable(conn, table); sqlDisconnect(&conn); lf = lineFileOpen(fileName, TRUE); while (lineFileRow(lf, words)) { struct chromGraph *cg; /* Look up ID in hash. */ struct slPair *infoFromHash = hashFindVal(posHash, words[0]); if (!infoFromHash) warn("%s line %d: %s not found in %s table", fileName, lf->lineIx, words[0], table); else { AllocVar(cg); cg->chrom = cloneString(infoFromHash->name); cg->chromStart = ptToInt(infoFromHash->val); cg->val = sqlDouble(words[1]); slAddHead(&list, cg); } } slReverse(&list); /* Free stuff up. */ lineFileClose(&lf); hashFreeWithVals(&posHash, slPairFree); return list; }
int searchProteinsInSwissProtByGene(char *queryGeneID) /* search Swiss-Prot database to see if it contains the protein Input: queryGeneID return: number of proteins found in Swiss-Prot */ { int proteinCnt; struct sqlConnection *conn; char query[256]; struct sqlResult *sr; char **row; conn = sqlConnect(UNIPROT_DB_NAME); sqlSafef(query, sizeof(query), "select count(*) from gene, displayId, accToTaxon,taxon " "where gene.val='%s' and gene.acc=displayId.acc and accToTaxon.taxon=taxon.id " "and accToTaxon.acc=gene.acc order by taxon.id", queryGeneID); sr = sqlMustGetResult(conn, query); row = sqlNextRow(sr); if (row == NULL) { errAbort("Error occured during mySQL query: %s\n", query); } proteinCnt = atoi(row[0]); sqlFreeResult(&sr); sqlDisconnect(&conn); return(proteinCnt); }
void saveClonePos(struct clonePos *cloneList, char *database) /* Save sorted clone position list to database. */ { struct sqlConnection *conn = sqlConnect(database); struct clonePos *clone; struct tempName tn; FILE *f; struct dyString *ds = newDyString(2048); /* Create tab file from clone list. */ printf("Creating tab file\n"); makeTempName(&tn, "hgCP", ".tab"); f = mustOpen(tn.forCgi, "w"); for (clone = cloneList; clone != NULL; clone = clone->next) clonePosTabOut(clone, f); fclose(f); /* Create table if it doesn't exist, delete whatever is * already in it, and fill it up from tab file. */ printf("Loading clonePos table\n"); sqlMaybeMakeTable(conn, "clonePos", createClonePos); sqlUpdate(conn, "NOSQLINJ DELETE from clonePos"); sqlDyStringPrintf(ds, "LOAD data local infile '%s' into table clonePos", tn.forCgi); sqlUpdate(conn, ds->string); /* Clean up. */ remove(tn.forCgi); sqlDisconnect(&conn); }
static void ccdsMkTables(char *ccdsDb, char *hgDb, int ccdsBuildId, char *ccdsInfoOut, char *ccdsNotesOut, char *ccdsGeneOut) /* create tables for hg db from imported CCDS database */ { if (verboseLevel() >= 2) sqlMonitorEnable(JKSQL_TRACE); struct sqlConnection *ccdsConn = ccdsSqlConn(ccdsDb); struct genomeInfo *genome = getGenomeInfo(hgDb, ccdsBuildId); struct hash *infoCcds = hashNew(20); struct hash *geneCcds = hashNew(20); struct hash* ignoreTbl = buildIgnoreTbl(ccdsConn, genome); char ccdsInfoFile[PATH_LEN], ccdsInfoTbl[PATH_LEN]; ccdsGetTblFileNames(ccdsInfoOut, ccdsInfoTbl, ccdsInfoFile); createCcdsInfo(ccdsConn, ccdsInfoFile, genome, ignoreTbl, infoCcds); char ccdsNotesFile[PATH_LEN], ccdsNotesTbl[PATH_LEN]; ccdsGetTblFileNames(ccdsNotesOut, ccdsNotesTbl, ccdsNotesFile); createCcdsNotes(ccdsConn, ccdsNotesFile, genome, infoCcds); char ccdsGeneFile[PATH_LEN], ccdsGeneTbl[PATH_LEN]; ccdsGetTblFileNames(ccdsGeneOut, ccdsGeneTbl, ccdsGeneFile); createCcdsGene(ccdsConn, ccdsGeneFile, genome, ignoreTbl, geneCcds); sqlDisconnect(&ccdsConn); sqlMonitorDisable(); gotCcdsValidate(infoCcds, geneCcds); if (loadDb) loadTables(hgDb, ccdsInfoTbl, ccdsInfoFile, ccdsGeneTbl, ccdsGeneFile, ccdsNotesTbl, ccdsNotesFile); }
void readTableTask(char *db, char *table) /* Implements the readTable task */ { FILE *outFh = NULL; struct sqlConnection *conn = sqlConnect(db); struct pslReader* pr = pslReaderQuery(conn, table, gWhere); struct psl* psl; int numRows = 0; if (gOutput != NULL) outFh = mustOpen(gOutput, "w"); while ((numRows < gMaxRows) && ((psl = pslReaderNext(pr)) != NULL)) { if (outFh != NULL) pslTabOut(psl, outFh); pslFree(&psl); numRows++; } carefulClose(&outFh); pslReaderFree(&pr); sqlDisconnect(&conn); checkNumRows(table, numRows); }
void saveCtgPos(struct ctgPos *ctgList, char *database) /* Save ctgList to database. */ { struct sqlConnection *conn = sqlConnect(database); struct ctgPos *ctg; char *tabFileName = "ctgPos.tab"; FILE *f; struct dyString *ds = newDyString(2048); /* Create tab file from ctg list. */ printf("Creating tab file\n"); f = mustOpen(tabFileName, "w"); for (ctg = ctgList; ctg != NULL; ctg = ctg->next) ctgPosTabOut(ctg, f); fclose(f); /* Create table if it doesn't exist, delete whatever is * already in it, and fill it up from tab file. */ printf("Loading ctgPos table\n"); sqlMaybeMakeTable(conn, "ctgPos", createCtgPos); sqlUpdate(conn, "NOSQLINJ DELETE from ctgPos"); sqlDyStringPrintf(ds, "LOAD data local infile '%s' into table ctgPos", tabFileName); sqlUpdate(conn, ds->string); /* Clean up. */ remove(tabFileName); sqlDisconnect(&conn); }
boolean chromSeqFileExists(char *db, char *chrom) /* Check whether chromInfo exists for a database, find the path of the */ /* sequence file for this chromosome and check if the file exists. */ { char seqFile[512]; struct sqlConnection *conn = sqlConnect(db); char query[256]; char *res = NULL; boolean exists = FALSE; /* if the database exists, check for the chromInfo file */ if (sqlDatabaseExists(db)) { sqlSafef(query, sizeof(query), "select fileName from chromInfo where chrom = '%s'", chrom); res = sqlQuickQuery(conn, query, seqFile, 512); sqlDisconnect(&conn); } /* if there is not table or no information in the table or if the table */ /* exists but the file can not be opened return false, otherwise sequence */ /* file exists and return true */ if (res != NULL) { char *seqFile2 = hReplaceGbdb(seqFile); exists = udcExists(seqFile2); freeMem(seqFile2); } return exists; }
void hgMaxExp(char *database, char *table) /* Output maximum expScore in table */ { struct sqlConnection *conn = sqlConnect(database); struct sqlResult *sr; char query[256]; char **row; /* Get list of all items with expression values. */ char *fieldNames = "name, expCount, expScores"; sqlSafef(query, sizeof(query), "select %s from %s", fieldNames, table); sr = sqlGetResult(conn, query); float maxScore = 0.0; float minScore = 100000.0; while ((row = sqlNextRow(sr)) != NULL) { char *name = row[0]; int expCount = sqlUnsigned(row[1]); int commaCount; float *expScores = NULL; sqlFloatDynamicArray(row[2], &expScores, &commaCount); if (expCount != commaCount) errAbort("expCount and expScores don't match on %s in %s", name, table); int i; for (i=0; i<expCount; i++) { maxScore = max(maxScore, expScores[i]); minScore = min(minScore, expScores[i]); } } sqlFreeResult(&sr); conn = sqlConnect(database); sqlDisconnect(&conn); /* Disconnect because next step is slow. */ printf("max: %0.2f min: %0.2f\n", maxScore, minScore); }
void hgSoftberryHom(char *database, int fileCount, char *files[]) /* hgSoftberryHom - Make table storing Softberry protein homology information. */ { int i; char *fileName; char *table = "softberryHom"; char *tabFileName = "softberryHom.tab"; FILE *f = mustOpen(tabFileName, "w"); struct sqlConnection *conn = NULL; struct dyString *ds = newDyString(2048); for (i=0; i<fileCount; ++i) { fileName = files[i]; printf("Processing %s\n", fileName); makeTabLines(fileName, f); } carefulClose(&f); /* Create table if it doesn't exist, delete whatever is * already in it, and fill it up from tab file. */ conn = sqlConnect(database); printf("Loading %s table\n", table); sqlMaybeMakeTable(conn, table, createTable); sqlDyStringPrintf(ds, "DELETE from %s", table); sqlUpdate(conn, ds->string); dyStringClear(ds); sqlDyStringPrintf(ds, "LOAD data local infile '%s' into table %s", tabFileName, table); sqlUpdate(conn, ds->string); sqlDisconnect(&conn); }
void relationRecon(char *fileName) /* Do relationship based reconstruction. */ { char **words; long start, end; struct sqlConnection *conn = sqlConnect(database); struct sqlResult *sr; char **row; FILE *f = mustOpen(fileName, "w"); int lineCount; int i; char query[256]; start = clock1000(); words = loadWords(); end = clock1000(); printf("Time to load words: %4.3f\n", 0.001*(end-start)); start = clock1000(); lineCount = sqlTableSize(conn, "lineSize"); for (i=0; i<lineCount; ++i) { sprintf(query, "select * from lineWords where line = %d", i); sr = sqlQuery(conn, query); while ((row = sqlNextRow(sr)) != NULL) fileOutput(f,words[sqlUnsigned(row[1])]); sqlFreeResult(&sr); } end = clock1000(); printf("Time to relation reconstruct file: %4.3f\n", 0.001*(end-start)); sqlDisconnect(&conn); }
void doLabContacts(struct cart *theCart) { char *subId = cartString(theCart, "lab"); cartWebStart(cart, database, "ENCODE DCC: Contacts for submission: %s",subId); struct sqlConnection *conn = sqlConnect(database); char query[10 * 1024]; struct sqlResult *sr; char **row; printf("<a href=docIdView?db=%s> Return </a><BR>", database); safef(query, sizeof query, "select user_id from %s where id = %s ", "projects",subId); char *userId = sqlQuickString(conn, query); safef(query, sizeof query, "select name,email,pi from %s where id = '%s' ", "users",userId); sr = sqlGetResult(conn, query); printf("<pre>"); while ((row = sqlNextRow(sr)) != NULL) { printf("Name: %s\nEmail: %s\nPI: %s", row[0], row[1], row[2]); } sqlFreeResult(&sr); sqlDisconnect(&conn); cartWebEnd(); }
boolean chromSeqFileExists(char *db, char *chrom) /* Check whether chromInfo exists for a database, find the path of the */ /* sequence file for this chromosome and check if the file exists. */ { char seqFile[512]; struct sqlConnection *conn = sqlConnect(db); char query[256]; char *res = NULL; boolean exists = FALSE; /* if the database exists, check for the chromInfo file */ if (sqlDatabaseExists(db)) { safef(query, sizeof(query), "select fileName from chromInfo where chrom = '%s'", chrom); res = sqlQuickQuery(conn, query, seqFile, 512); sqlDisconnect(&conn); } /* if there is not table or no information in the table or if the table */ /* exists but the file can not be opened return false, otherwise sequence */ /* file exists and return true */ if (res != NULL) { /* chromInfo table exists so check that sequence file can be opened */ FILE *f = fopen(seqFile, "rb"); if (f != NULL) { exists = TRUE; fclose(f); } } return exists; }
void checkDbTables(char *database, char *composite, struct hash *mdbHash, struct hash *allBbiNames) // search the database for tables that begin with composite and call checkTable { struct sqlConnection *conn = sqlConnect(database); char buffer[10 * 1024]; verbose(1, "----------------------------------------------\n"); verbose(1, "Checking that tables starting with composite in db are in metaDb\n (also checks dummy table and the bbi symlink and its target)\n"); verbose(1, "----------------------------------------------\n"); sqlSafef(buffer, sizeof buffer, "show tables like '%s%%'", composite); struct sqlResult *sr; sr = sqlGetResult(conn, buffer); char **row; struct slName *list = NULL; while ((row = sqlNextRow(sr)) != NULL) { struct slName *el = slNameNew(row[0]); slAddHead(&list, el); } sqlFreeResult(&sr); for(; list; list = list->next) checkTable(conn, list->name, mdbHash, allBbiNames); sqlDisconnect(&conn); }
int main(int argc, char *argv[]) { // sql vars SQLHENV henv = SQL_NULL_HENV; // environment SQLHDBC hdbc = SQL_NULL_HDBC; // connection SQLHSTMT hstmt = SQL_NULL_HSTMT; // statement // sql connect sqlConnect(&henv, &hdbc, &hstmt); // input vars char beruf[BERUFSIZE + 1]; char mitID[MITIDSIZE + 1]; // program logic while (getBerufe(&henv, &hdbc, &hstmt, beruf)) { if (getMitarbeiter(&henv, &hdbc, &hstmt, beruf, mitID)) { if (getMitDetails(&henv, &hdbc, &hstmt, beruf, mitID)) { getProjektDetails(&henv, &hdbc, &hstmt, beruf, mitID); } } } puts(""); // sql disconnect sqlDisconnect(&henv, &hdbc, &hstmt); return 0; }
void writeSplitTables() /* sequentially read ContigLocFilter, writing to appropriate chrom file */ /* we are storing chromName in the table just as a sanity check */ /* It is dropped in the next step of the pipeline */ { char query[512]; struct sqlConnection *conn = hAllocConn(); struct sqlResult *sr; char **row; struct hashEl *hel; char *chromName; verbose(1, "reading ContigLocFilter...\n"); sqlSafef(query, sizeof(query), "select snp_id, ctg_id, chromName, loc_type, phys_pos_from, phys_pos, orientation, allele from ContigLocFilter"); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { hel = hashLookup(chromHash,row[2]); if (hel == NULL) { verbose(1, "%s not found\n", row[2]); continue; } fprintf(hel->val, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7]); } sqlFreeResult(&sr); sqlDisconnect(&conn); }
void createAll() /* Define all tables. */ { struct sqlConnection *conn = sqlConnect(database); sqlGetResult(conn, "CREATE table word (" "id smallint not null primary key," "word varchar(250) not null" ")" ); sqlGetResult(conn, "CREATE table lineSize (" "id int(8) not null primary key," "size smallint not null" ")" ); sqlGetResult(conn, "CREATE table lineWords (" "line int(8) not null," "word smallint not null," "pos smallint not null" ")" ); sqlGetResult(conn, "CREATE table commaLine (" "id int(8) not null primary key," "size smallint not null," "wordList blob not null" ")" ); sqlDisconnect(&conn); }
void cartMain(struct cart *theCart) /* We got the persistent/CGI variable cart. Now * set up the globals and make a web page. */ { cart = theCart; /* Break out new block after have set cart */ { int id = cartUsualInt(cart, hgbiId, 1); struct sqlConnection *conn = sqlConnect("bioImage"); char *geneName = bioImageGeneName(conn, id); if (cartVarExists(cart, hgbiDoFullSize)) { htmStart(stdout, "BioImage Full Sized Image"); printf("<IMG SRC=\"/%s\"><BR>\n", bioImageFullSizePath(conn, id)); printCaption(conn, id, geneName); htmlEnd(); } else /* Default case - start fancy web page. */ { mainPage(conn, id, geneName); } cartRemovePrefix(cart, hgbiDoPrefix); sqlDisconnect(&conn); } }
void encode2ExpDumpFlat(char *outFile, char *viewSql, char *flatTable) /* encode2ExpDumpFlat - Dump the experiment table in a semi-flat way from a relationalized Encode2 metadatabase.. */ { FILE *f = mustOpen(outFile, "w"); struct sqlConnection *conn = sqlConnect(database); struct starTableInfo **stiArray; AllocArray(stiArray, ArraySize(starFields)); int i; for (i=0; i<ArraySize(starFields); ++i) stiArray[i] = starTableInfoNew(conn, starFields[i]); struct dyString *query = dyStringNew(2000); sqlDyStringPrintf(query, "select "); for (i=0; i<ArraySize(flatFields); ++i) { if (i != 0) dyStringAppendC(query, ','); sqlDyStringPrintf(query, "%s", flatFields[i]); } for (i=0; i<ArraySize(starFields); ++i) { dyStringAppendC(query, ','); sqlDyStringPrintf(query, "%s", starFields[i]); } dyStringPrintf(query, " from %s%s", tablePrefix, "experiment"); struct sqlResult *sr = sqlGetResult(conn, query->string); char **row; while ((row = sqlNextRow(sr)) != NULL) { int flatSize = ArraySize(flatFields); int starSize = ArraySize(starFields); int i; for (i=0; i<flatSize; ++i) { if (i != 0) fputc('\t', f); fputs(row[i], f); } for (i=0; i<starSize; ++i) { int id = sqlUnsigned(row[i+flatSize]); fputc('\t', f); if (id == 0) fputs("n/a", f); else fputs(stiArray[i]->termsForIds[id], f); } fputc('\n', f); } sqlFreeResult(&sr); sqlDisconnect(&conn); carefulClose(&f); makeViewSql(viewSql); makeFlatTableSql(flatTable); }
int tableSize(char *db, char *table) /* Return number of rows in table. */ { struct sqlConnection *conn = sqlConnect(db); int size = sqlTableSize(conn, table); sqlDisconnect(&conn); return size; }
struct mdbObj *getMdbList(char *database) /* Get list of metaDb objects for a database. */ { struct sqlConnection *conn = sqlConnect(database); struct mdbObj *list = mdbObjsQueryAll(conn, metaTable); sqlDisconnect(&conn); return list; }
void localWebWrap(struct cart *theCart) /* We got the http stuff handled, and a cart. */ { cart = theCart; struct sqlConnection *conn = sqlConnect(cdwDatabase); dispatch(conn); sqlDisconnect(&conn); }
void createFakeEntries(char *host, char *user, char *password, char *database, int count) /* create count new fake entries in database. */ { struct sqlConnection *conn = sqlConnectRemote(host, user, password, database); int i; for (i=0; i<count; ++i) createFakeEntry(conn, randomFakeSize()); sqlDisconnect(&conn); }
void createEmptyDatabase(char *host, char *user, char *password, char *database) /* Create a new database with no tables. */ { struct sqlConnection *conn = sqlConnectRemote(host, user, password, NULL); char query[512]; sqlSafef(query, sizeof(query), "create database %s", database); sqlUpdate(conn, query); sqlDisconnect(&conn); }
boolean databaseExists(char *host, char *user, char *password, char *database) /* Return TRUE if database exists. */ { struct sqlConnection *conn = sqlMayConnectRemote(host, user, password, database); if (conn == NULL) return FALSE; sqlDisconnect(&conn); return TRUE; }