示例#1
0
文件: mysql.c 项目: gastonb/R1EMU
MySQLStatus mySqlQuery(MySQL *self, const char* query, ...) {
	va_list	args;
	char buf[MAX_QUERY_SIZE];

	if (self->handle == NULL) {
        error("MySQL hasn't been initialized yet.");
		return SQL_ERROR;
	}

	mySqlFreeResult(self);

	va_start(args, query);
	vsnprintf(buf, MAX_QUERY_SIZE - 1, query, args);
	va_end(args);

	dbg("Launching SQL command : %s", buf);

	if (mysql_real_query(self->handle, buf,(unsigned long) strlen(buf))) {
		return SQL_ERROR;
	}

	self->result = mysql_store_result(self->handle);

	return SQL_SUCCESS;
}
示例#2
0
bool mySqlBuildItemCommonDataDb(MySQL *self, StaticData **_db) {

    bool status = false;
    StaticData *db = NULL;
    MYSQL_ROW row;

    if (!(db = staticDataNew("itemCommonDataDb"))) {
        error("Cannot allocate a new static data for item data.");
        goto cleanup;
    }

    size_t rowsCount;
    if (!(mySqlRequestItemsCommonData(self, &rowsCount))) {
        error("Cannot request items data from MySQL.");
        goto cleanup;
    }

    while ((row = mysql_fetch_row(self->result)) != NULL) {
        ItemCommonData *itemCommonData = itemCommonDataNew(row);
        if (!(staticDataAdd(db, itemCommonData->ClassID, itemCommonData))) {
            error("Cannot add the item data '%d' to the db.", itemCommonData->ClassID);
            goto cleanup;
        }
    }

    status = true;
    *_db = db;

cleanup:
    if (!status) {
        staticDataDestroy(&db);
    }
    mySqlFreeResult(self);
    return status;
}
示例#3
0
文件: mysql.c 项目: gastonb/R1EMU
void mySqlDestroy(MySQL **_self) {
    MySQL *self = *_self;

    mySqlInfoFree(&self->info);
    mySqlFreeResult(self);
    mysql_close(self->handle);

    free(self);
    *_self = NULL;
}