The qDecoder Project

qDatabase.c File Reference

Database Independent Wrapper API. More...


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 = qDb("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 (db->open(db) == false) {
     printf("WARNING: Can't connect to database.\n");
     return -1;
   }

   // get results
   result = db->executeQuery(db, "SELECT name, population FROM City");
   if (result != NULL) {
     printf("COLS : %d , ROWS : %d\n", result->getCols(result), result->getRows(result));
     while (result->getNext(result) == true) {
       char *pszName = result->getStr(result, "name");
       int   nPopulation = result->getInt(result, "population");
       printf("Country : %s , Population : %d\n", pszName, nPopulation);
     }
     result->free(result);
   }

   // close connection
   db->close(db);

   // free db object
   db->free(db);

Note:
Use "--enable-threadsafe" configure script option to use under multi-threaded environments.

[Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference]