Пример #1
0
/* create an exception for the current MySQL error */
static stExcept *createMySqlExceptv(MySqlDb *dbImpl, const char *msg, va_list args) {
    char *fmtMsg = stSafeCDynFmtv(msg, args);
    const char *exId = isMysqlRetryError(mysql_errno(dbImpl->conn)) ?  ST_KV_DATABASE_RETRY_TRANSACTION_EXCEPTION_ID : ST_KV_DATABASE_EXCEPTION_ID;
    stExcept *except = stExcept_new(exId, "%s: %s (%d)", fmtMsg, mysql_error(dbImpl->conn), mysql_errno(dbImpl->conn));
    stSafeCFree(fmtMsg);
    return except;
}
Пример #2
0
/* print set for debugging */
void malnSet_dumpv(struct malnSet *malnSet, FILE *fh, const char *label, va_list args) {
    char *fmtLabel = stSafeCDynFmtv(label, args);
    fprintf(fh, "malnSet: begin %s\n", fmtLabel);
    struct malnBlkSetIterator *iter = malnBlkSet_getIterator(malnSet->blks);
    struct malnBlk *blk;
    while ((blk = malnBlkSetIterator_getNext(iter)) != NULL) {
        fputs("  ", fh);
        malnBlk_dump(blk, fh, malnBlk_dumpDefault, "  blk");
    }
    malnBlkSetIterator_destruct(iter);
    fprintf(fh, "malnSet: end %s\n", fmtLabel);
    freeMem(fmtLabel);
}
Пример #3
0
/* start an SQL query, formatting arguments into the query */
static MYSQL_RES *queryStartv(MySqlDb *dbImpl, const char *query, va_list args) {
    char *sql = stSafeCDynFmtv(query, args);
    if (mysql_real_query(dbImpl->conn, sql, strlen(sql)) != 0) {
        stExcept *ex = createMySqlExcept(dbImpl, "query failed \"%0.60s\"", sql);
        stSafeCFree(sql);
        stThrow(ex);
    }
    MYSQL_RES *rs = mysql_use_result(dbImpl->conn);
    if ((rs == NULL) && (mysql_errno(dbImpl->conn) != 0)) {
        stExcept *ex = createMySqlExcept(dbImpl, "query failed \"%0.60s\"", sql);
        stSafeCFree(sql);
        stThrow(ex);
    }
    stSafeCFree(sql);
    return rs;
}
Пример #4
0
stExcept *stExcept_newv(const char *id, const char *msg, va_list args) {
    stExcept *except = stSafeCCalloc(sizeof(stExcept));
    except->id = id;
    except->msg = stSafeCDynFmtv(msg, args);
    return except;
}