base/libs/qdecoder/qDatabase.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdarg.h>
#include <string.h>
#include "qDecoder.h"
#include "qInternal.h"

Include dependency graph for qDatabase.c:

Go to the source code of this file.

FunctionsTitleTestFour

bool qDbBeginTran (Q_DB *db)
bool qDbClose (Q_DB *db)
bool qDbCommit (Q_DB *db)
bool qDbEndTran (Q_DB *db, bool commit)
Q_DBRESULTqDbExecuteQuery (Q_DB *db, const char *query)
Q_DBRESULTqDbExecuteQueryf (Q_DB *db, const char *format,...)
int qDbExecuteUpdate (Q_DB *db, const char *query)
int qDbExecuteUpdatef (Q_DB *db, const char *format,...)
bool qDbFree (Q_DB *db)
int qDbGetCols (Q_DBRESULT *result)
const char * qDbGetError (Q_DB *db, unsigned int *errorno)
int qDbGetInt (Q_DBRESULT *result, const char *field)
int qDbGetIntAt (Q_DBRESULT *result, int idx)
bool qDbGetLastConnStatus (Q_DB *db)
int qDbGetRow (Q_DBRESULT *result)
int qDbGetRows (Q_DBRESULT *result)
const char * qDbGetStr (Q_DBRESULT *result, const char *field)
const char * qDbGetStrAt (Q_DBRESULT *result, int idx)
Q_DBqDbInit (const char *dbtype, const char *addr, int port, const char *username, const char *password, const char *database, bool autocommit)
bool qDbOpen (Q_DB *db)
bool qDbPing (Q_DB *db)
bool qDbResultFree (Q_DBRESULT *result)
bool qDbResultNext (Q_DBRESULT *result)
bool qDbRollback (Q_DB *db)
bool qDbSetFetchType (Q_DB *db, bool use)


Detailed Description

Database Independent Wrapper API

Note:
To use this API, you must include database header file before including qDecoder.h in your source code like below. And please remember that qDecoder must be compiled with ENABLE_MYSQL or ENABLE_SOME_DATABASE option.
   [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);

Definition in file qDatabase.c.


Generated on Mon Mar 26 07:00:51 2018 for JSOC_Documentation by  doxygen 1.5.7.1