|
qdb_t * | qdb (const char *dbtype, const char *addr, int port, const char *username, const char *password, const char *database, bool autocommit) |
| Initialize internal connector structure.
|
|
static bool | open_ (qdb_t *db) |
| qdb->open(): Connect to database server
|
|
static bool | close_ (qdb_t *db) |
| qdb->close(): Disconnect from database server
|
|
static int | execute_update (qdb_t *db, const char *query) |
| qdb->execute_update(): Executes the update DML
|
|
static int | execute_updatef (qdb_t *db, const char *format,...) |
| qdb->execute_updatef(): Executes the formatted update DML
|
|
static qdbresult_t * | execute_query (qdb_t *db, const char *query) |
| qdb->execute_query(): Executes the query
|
|
static qdbresult_t * | execute_queryf (qdb_t *db, const char *format,...) |
| qdb->execute_queryf(): Executes the formatted query
|
|
static bool | begin_tran (qdb_t *db) |
| qdb->begin_tran(): Start transaction
|
|
static bool | commit (qdb_t *db) |
| qdb->commit(): Commit transaction
|
|
static bool | rollback (qdb_t *db) |
| qdb->rellback(): Roll-back and abort transaction
|
|
static bool | set_fetchtype (qdb_t *db, bool fromdb) |
| qdb->set_fetchtype(): Set result fetching type
|
|
static bool | get_conn_status (qdb_t *db) |
| qdb->get_conn_status(): Get last connection status
|
|
static bool | ping (qdb_t *db) |
| qdb->ping(): Checks whether the connection to the server is working.
|
|
static const char * | get_error (qdb_t *db, unsigned int *errorno) |
| qdb->get_error(): Get error number and message
|
|
static void | free_ (qdb_t *db) |
| qdb->free(): De-allocate qdb_t structure
|
|
static const char * | _resultGetStr (qdbresult_t *result, const char *field) |
| qdbresult->get_str(): Get the result as string by field name
|
|
static const char * | _resultGetStrAt (qdbresult_t *result, int idx) |
| qdbresult->get_str_at(): Get the result as string by column number
|
|
static int | _resultGetInt (qdbresult_t *result, const char *field) |
| qdbresult->get_int(): Get the result as integer by field name
|
|
static int | _resultGetIntAt (qdbresult_t *result, int idx) |
| qdbresult->get_int_at(): Get the result as integer by column number
|
|
static bool | _resultGetNext (qdbresult_t *result) |
| qdbresult->get_next(): Retrieves the next row of a result set
|
|
static int | result_get_cols (qdbresult_t *result) |
| qdbresult->get_cols(): Get the number of columns in the result set
|
|
static int | result_get_rows (qdbresult_t *result) |
| qdbresult->get_rows(): Get the number of rows in the result set
|
|
static int | result_get_row (qdbresult_t *result) |
| qdbresult->get_row(): Get the current row number
|
|
static void | result_free (qdbresult_t *result) |
| qdbresult->free(): De-allocate the result
|
|
Database wrapper.
Database header files should be included prior to qlibcext.h in your source codes like below.
#include "mysql.h"
qlibc extension header file.
qdb_t *db = NULL;
qdbresult_t *result = NULL;
db =
qdb(
"MYSQL",
"dbhost.qdecoder.org", 3306,
"test", "secret", "sampledb", true);
if (db == NULL) {
printf("ERROR: Not supported database type.\n");
return -1;
}
if (db->open(db) == false) {
printf("WARNING: Can't connect to database.\n");
return -1;
}
result = db->execute_query(db, "SELECT name, population FROM City");
if (result != NULL) {
printf("COLS : %d , ROWS : %d\n",
result->get_cols(result), result->get_rows(result));
while (result->get_next(result) == true) {
char *pszName = result->get_str(result, "name");
int nPopulation = result->get_int(result, "population");
printf("Country : %s , Population : %d\n", pszName, nPopulation);
}
result->free(result);
}
db->close(db);
db->free(db);
qdb_t * qdb(const char *dbtype, const char *addr, int port, const char *username, const char *password, const char *database, bool autocommit)
Initialize internal connector structure.
Definition in file qdatabase.c.