static bool containsRecord(stKVDatabase *database, int64_t key) { MySqlDb *dbImpl = database->dbImpl; MYSQL_RES *rs = queryStart(dbImpl, "select id from %s where id=%lld", dbImpl->table, (long long)key); char **row = queryNext(dbImpl, rs); bool found = (row != NULL); queryEnd(dbImpl, rs); return found; }
struct genePred *genePredReaderNext(struct genePredReader* gpr) /* Read the next genePred, returning NULL if no more */ { if (gpr->lf != NULL) return fileNext(gpr); else return queryNext(gpr); }
struct psl *pslReaderNext(struct pslReader* pr) /* Read the next psl, returning NULL if no more */ { if (pr->lf != NULL) return fileNext(pr); else return queryNext(pr); }
/* immediate execution of a statement that doesn't return results, formatting * arguments into query */ static void sqlExec(MySqlDb *dbImpl, char *query, ...) { va_list args; va_start(args, query); MYSQL_RES *rs = queryStartv(dbImpl, query, args); va_end(args); if (queryNext(dbImpl, rs) != NULL) { stThrowNew(ST_KV_DATABASE_EXCEPTION_ID, "SQL command should not have returned a result: \"%s\"", query); } queryEnd(dbImpl, rs); }
// collect warnings into an array static int getWarnings(MySqlDb *dbImpl, int maxToReport, char **warnings) { int numReturned = 0; MYSQL_RES *rs = queryStart(dbImpl, "show warnings limit %d", maxToReport); char **row; while ((row = queryNext(dbImpl, rs)) != NULL) { if (numReturned < maxToReport) { warnings[numReturned++] = stSafeCDynFmt("%s: %s (%s)", row[0], row[2], row[1]); } } mysql_free_result(rs); return numReturned; }
static void *getPartialRecord(stKVDatabase *database, int64_t key, int64_t zeroBasedByteOffset, int64_t sizeInBytes, int64_t recordSize) { MySqlDb *dbImpl = database->dbImpl; MYSQL_RES *rs = queryStart(dbImpl, "select substring(data, %lld, %lld) from %s where id=%lld", (long long)zeroBasedByteOffset+1, (long long)sizeInBytes, dbImpl->table, (long long)key); char **row = queryNext(dbImpl, rs); void *data = NULL; int64_t readLen = 0; if (row != NULL) { readLen = queryLength(dbImpl, rs); data = stSafeCCopyMem(row[0], readLen); } queryEnd(dbImpl, rs); if (readLen != sizeInBytes) { stThrowNew(ST_KV_DATABASE_EXCEPTION_ID, "partial read of key %lld, expected %lld bytes got %lld bytes", (long long)key, (long long)sizeInBytes, (long long)readLen); } return data; }
static void *getRecord2(stKVDatabase *database, int64_t key, int64_t *sizeOfRecord) { MySqlDb *dbImpl = database->dbImpl; MYSQL_RES *rs = queryStart(dbImpl, "select data from %s where id=%lld", dbImpl->table, (long long)key); char **row = queryNext(dbImpl, rs); void *data = NULL; int64_t readLen = 0; if (row != NULL) { readLen = queryLength(dbImpl, rs); data = stSafeCCopyMem(row[0], readLen); } queryEnd(dbImpl, rs); if (sizeOfRecord != NULL) { *sizeOfRecord = readLen; } return data; }