Jump to content
  • Advertisement
  • entries
    109
  • comments
    175
  • views
    117325

C/C++ DBMS API

Sign in to follow this  
Emmanuel Deloget

296 views

Today, I gave a fast look to some popular SQL database API. If you want to dig them, I suggest you to have a look to the Qt library - the database driver part.

PostgreSQL pgsql API


Free. Actually, the main problem is more PostgreSQL than the API. PostgreSQL is supposedly better than MySQL, but setting up the database server is somewhat complex (on a unix system; it seems to be easier on a Windows system) and it seems that MySQL is faster. It supports atomic transactions.

The API is C oriented, and is farily simple. The function used to send a SQL query is:

PGresult *PQexec(PGconn *conn, const char *command);

To retrieve the results, I have to use

// to test the PGresult status:
ExecStatusType PQresultStatus(const PGresult *res);
// to count the number of tuples
int PQntuples(const PGresult *res);
// to get the number of column in each tuple
int PQnfields(const PGresult *res);
// to get the type of a column
Oid PQftype(const PGresult *res, int column_number);
// to get the value
char *PQgetvalue(const PGresult *res, int row_number, int column_number);


SQLite API


Free too. No dependencies (SQLite doesn't connect to a database, it stores your datas in plain files) but is limited to a subset of SQL.

The API is very simple too: it is described here.

int sqlite3_exec(sqlite3*, const char *sql, sqlite_callback, void*, char**);

Is used to send a SQL query to the engine. Newt, we use

int sqlite3_column_count(sqlite3_stmt *pStmt);
int sqlite3_column_type(sqlite3_stmt*, int iCol);

sqlite3_column_XXX() functions are used to read the data.

There is an atomic transaction management.

MySQL API


Free for open-source use (which is not my plan at all); otherwise it is not very expensive - well... It can be...

The InnoDB table engine provide the needed atomic transactions.

The API is very simple too: there is a bunch of mysql_* C function that are rather easy to use. There is also a C++ API (which can be found here) - and that's a very good point (because, take it or not, I program in C++).

Here is a simple example of the MySQL++ API.

Of course, if you know some other SQL API (either C or C++), I encourage you to post a comment here ;)
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!