Compatible with and can be included in C++ or Objective-C projects.
A small, easy to use Open Source Database Connection Pool Library with the following features:
Requirements: Runs on iOS, Linux, OS X, FreeBSD, Solaris, OpenBSD and other POSIX systems. A C99 compiler is required to build the library.
Compatible with and can be included in C++ or Objective-C projects.
Modern, Object Oriented API design. Fully documented.
The library is licensed under a Free Open Source Software License.
Used in M/Monit
- The Monit Team mmonit.comUsed in DBMail
dbmail.orgYes, libzdb can be used from and included in any C, C++ or Objective-C project. The Xcode project file used to develop libzdb is available from the repository and can be included in your own Xcode project.
Libzdb is thread-safe and designed to be used in a multi-threaded program.
Yes, the pool can be setup to dynamically change the number of Connections in the pool depending on the load.
Click the d icon in the footer below to access previous versions of the library.
The project is hosted at Google. Click the P icon in the footer below to visit the repository and browse the code online.
Libzdb currently supports SQLite, MySQL, PostgreSQL and Oracle. At the moment there are no plans to support additional database systems.
The URL given to a Connection Pool at creation time specify a database connection on the standard URL format. The format of the connection URL is defined as:
database://[user:password@][host][:port]/database[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
The property names user and password are always recognized and specify how to login to the database. Other properties depends on the database server in question. (See Connection URL for details). User name and password can alternatively be specified in the auth-part of the URL. If port number is omitted, the default port number for the database server is used.
To obtain a connection pool for a MySQL database, the code below can be used. The exact same code can be used for PostgreSQL, SQLite and Oracle, the only change needed is to modify the Connection URL. Here we connect to the database test on localhost and start the pool with the default 5 initial connections.
URL_T url = URL_new("mysql://localhost/test?user=root&password=swordfish");
ConnectionPool_T pool = ConnectionPool_new(url);
ConnectionPool_start(pool);
Connection_T con = ConnectionPool_getConnection(pool);
ResultSet_T result = Connection_executeQuery(con,
"select id, name, image from employee where salary > %d", aNumber);
while (ResultSet_next(result))
{
int id = ResultSet_getInt(result, 1);
const char *name = ResultSet_getString(result, 2);
int blobSize;
const void *image = ResultSet_getBlob(result, 3, &blobSize);
[..]
}
Here is another example where a generated result is selected and printed:
ResultSet_T r = Connection_executeQuery(con, "SELECT count(*) FROM users");
printf("Number of users: %s\n", ResultSet_next(r) ? ResultSet_getString(r, 1) : "no users");
PreparedStatement_T p = Connection_prepareStatement(con,
"INSERT INTO employee(name, picture) VALUES(?, ?)");
PreparedStatement_setString(p, 1, "Kamiya Kaoru");
PreparedStatement_setBlob(p, 2, jpeg, jpeg_size);
PreparedStatement_execute(p);
Here is another example where we use a Prepared Statement to execute a query which returns a Result Set:
PreparedStatement_T p = Connection_prepareStatement(con,
"SELECT id FROM employee WHERE name LIKE ?");
PreparedStatement_setString(p, 1, "%Kaoru%");
ResultSet_T r = PreparedStatement_executeQuery(p);
while (ResultSet_next(r))
printf("employee.id = %d\n", ResultSet_getInt(r, 1));
More examples in the API documentation.
If you have questions or comments about the software or documentation please subscribe to the libzdb general mailing list and post your questions there.
If you believe you have found a bug, please send this information, plus information about the machine and OS platform used along with a description of the problem to
bugs-libzdb@tildeslash.com