|
Functions | |
| Q_DB * | qDbInit (const char *dbtype, const char *addr, int port, const char *username, const char *password, const char *database, bool autocommit) |
| Initialize internal connector structure. | |
| bool | qDbOpen (Q_DB *db) |
| Connect to database server. | |
| bool | qDbClose (Q_DB *db) |
| Disconnect from database server. | |
| bool | qDbFree (Q_DB *db) |
| De-allocate Q_DB structure. | |
| const char * | qDbGetError (Q_DB *db, unsigned int *errorno) |
| Get error number and message. | |
| bool | qDbPing (Q_DB *db) |
| Checks whether the connection to the server is working. | |
| bool | qDbGetLastConnStatus (Q_DB *db) |
| Get last connection status. | |
| bool | qDbSetFetchType (Q_DB *db, bool use) |
| Set result fetching type. | |
| int | qDbExecuteUpdate (Q_DB *db, const char *query) |
| Executes the update DML. | |
| int | qDbExecuteUpdatef (Q_DB *db, const char *format,...) |
| Executes the formatted update DML. | |
| Q_DBRESULT * | qDbExecuteQuery (Q_DB *db, const char *query) |
| Executes the query. | |
| Q_DBRESULT * | qDbExecuteQueryf (Q_DB *db, const char *format,...) |
| Executes the formatted query. | |
| bool | qDbResultNext (Q_DBRESULT *result) |
| Retrieves the next row of a result set. | |
| bool | qDbResultFree (Q_DBRESULT *result) |
| De-allocate the result. | |
| int | qDbGetCols (Q_DBRESULT *result) |
| Get the number of columns in the result set. | |
| int | qDbGetRows (Q_DBRESULT *result) |
| Get the number of rows in the result set. | |
| int | qDbGetRow (Q_DBRESULT *result) |
| Get the current row number. | |
| const char * | qDbGetStr (Q_DBRESULT *result, const char *field) |
| Get the result as string by field name. | |
| const char * | qDbGetStrAt (Q_DBRESULT *result, int idx) |
| Get the result as string by column number. | |
| int | qDbGetInt (Q_DBRESULT *result, const char *field) |
| Get the result as integer by field name. | |
| int | qDbGetIntAt (Q_DBRESULT *result, int idx) |
| Get the result as integer by column number. | |
| bool | qDbBeginTran (Q_DB *db) |
| Start transaction. | |
| bool | qDbEndTran (Q_DB *db, bool commit) |
| End transaction. | |
| bool | qDbCommit (Q_DB *db) |
| Commit transaction. | |
| bool | qDbRollback (Q_DB *db) |
| Roll-back transaction. | |
[include order at your source codes] #include "mysql.h" #include "qDecoder.h"
Not documented yet, please refer below sample codes.
Q_DB *db = NULL; Q_DBRESULT *result = NULL; db = qDbInit("MYSQL", "dbhost.qdecoder.org", 3306, "test", "secret", "sampledb", true); if (db == NULL) { printf("ERROR: Not supported database type.\n"); return -1; } // try to connect if (qDbOpen(db) == false) { printf("WARNING: Can't connect to database.\n"); return -1; } // get results result = qDbExecuteQuery(db, "SELECT name, population FROM City"); if (result != NULL) { printf("COLS : %d , ROWS : %d\n", qDbGetCols(result), qDbGetRows(result)); while (qDbResultNext(result) == true) { char *pszName = qDbGetValue(result, "name"); int nPopulation = qDbGetInt(result, "population"); printf("Country : %s , Population : %d\n", pszName, nPopulation); } qDbResultFree(result); } // close connection qDbClose(db); // free db object qDbFree(db);
| Q_DB* qDbInit | ( | const char * | dbtype, | |
| const char * | addr, | |||
| int | port, | |||
| const char * | username, | |||
| const char * | password, | |||
| const char * | database, | |||
| bool | autocommit | |||
| ) |
Initialize internal connector structure.
| dbtype | database server type. currently "MYSQL" is only supported | |
| addr | ip or fqdn address. | |
| port | port number | |
| username | database username | |
| password | database password | |
| database | database server type. currently "MYSQL" is only supported | |
| autocommit | sets autocommit mode on if autocommit is true, off if autocommit is false |
| bool qDbOpen | ( | Q_DB * | db | ) |
| bool qDbClose | ( | Q_DB * | db | ) |
| bool qDbFree | ( | Q_DB * | db | ) |
| const char* qDbGetError | ( | Q_DB * | db, | |
| unsigned int * | errorno | |||
| ) |
Get error number and message.
| db | a pointer of Q_DB structure | |
| errorno | if not NULL, error number will be stored |
| bool qDbPing | ( | Q_DB * | db | ) |
Checks whether the connection to the server is working.
| db | a pointer of Q_DB structure |
| bool qDbGetLastConnStatus | ( | Q_DB * | db | ) |
Get last connection status.
| db | a pointer of Q_DB structure |
| bool qDbSetFetchType | ( | Q_DB * | db, | |
| bool | use | |||
| ) |
Set result fetching type.
| db | a pointer of Q_DB structure | |
| use | false for storing the results to client (default mode), true for fetching directly from server, |
| int qDbExecuteUpdate | ( | Q_DB * | db, | |
| const char * | query | |||
| ) |
Executes the update DML.
| db | a pointer of Q_DB structure | |
| query | query string |
| int qDbExecuteUpdatef | ( | Q_DB * | db, | |
| const char * | format, | |||
| ... | ||||
| ) |
Executes the formatted update DML.
| db | a pointer of Q_DB structure | |
| format | query string format |
| Q_DBRESULT* qDbExecuteQuery | ( | Q_DB * | db, | |
| const char * | query | |||
| ) |
Executes the query.
| db | a pointer of Q_DB structure | |
| query | query string |
| Q_DBRESULT* qDbExecuteQueryf | ( | Q_DB * | db, | |
| const char * | format, | |||
| ... | ||||
| ) |
Executes the formatted query.
| db | a pointer of Q_DB structure | |
| format | query string format |
| bool qDbResultNext | ( | Q_DBRESULT * | result | ) |
Retrieves the next row of a result set.
| result | a pointer of Q_DBRESULT |
| bool qDbResultFree | ( | Q_DBRESULT * | result | ) |
De-allocate the result.
| result | a pointer of Q_DBRESULT |
| int qDbGetCols | ( | Q_DBRESULT * | result | ) |
Get the number of columns in the result set.
| result | a pointer of Q_DBRESULT |
| int qDbGetRows | ( | Q_DBRESULT * | result | ) |
Get the number of rows in the result set.
| result | a pointer of Q_DBRESULT |
| int qDbGetRow | ( | Q_DBRESULT * | result | ) |
Get the current row number.
| result | a pointer of Q_DBRESULT |
| const char* qDbGetStr | ( | Q_DBRESULT * | result, | |
| const char * | field | |||
| ) |
Get the result as string by field name.
| result | a pointer of Q_DBRESULT | |
| field | column name |
| const char* qDbGetStrAt | ( | Q_DBRESULT * | result, | |
| int | idx | |||
| ) |
Get the result as string by column number.
| result | a pointer of Q_DBRESULT | |
| idx | column number (first column is 1) |
| int qDbGetInt | ( | Q_DBRESULT * | result, | |
| const char * | field | |||
| ) |
Get the result as integer by field name.
| result | a pointer of Q_DBRESULT | |
| field | column name |
| int qDbGetIntAt | ( | Q_DBRESULT * | result, | |
| int | idx | |||
| ) |
Get the result as integer by column number.
| result | a pointer of Q_DBRESULT | |
| idx | column number (first column is 1) |
| bool qDbBeginTran | ( | Q_DB * | db | ) |
Start transaction.
| db | a pointer of Q_DB structure |
| bool qDbEndTran | ( | Q_DB * | db, | |
| bool | commit | |||
| ) |
End transaction.
| db | a pointer of Q_DB structure | |
| commit | true for commit, false for roll-back |
| bool qDbCommit | ( | Q_DB * | db | ) |
Commit transaction.
| db | a pointer of Q_DB structure |
| bool qDbRollback | ( | Q_DB * | db | ) |
Roll-back transaction.
| db | a pointer of Q_DB structure |
| [Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference] |