Home/Modules/db-connector

db-connector

library module lib/db-connector

lib/db-connector — the SLeeLa DB connector

The SLeeLa equivalent of JDBC plus a driver. Java splits database access into an API (java.sql.*) and pluggable drivers shipped as jars (e.g. the PostgreSQL connector jar). SLeeLa has the same split, and this package is the missing middle layer:

JavaSLeeLa
java.sql.* APIlib/database/*.sleela facade classes
JDBC driver (the connector jar)this package (sldbc_*)
the databaselib/sleela-sql engine (or, later, an external RDBMS)

What it is

A small, driver-agnostic C ABI (include/sldbc.h) with the JDBC lifecycle:

sldbc_conn *c;
sldbc_open("sleelasql:./data", &c);          /* DriverManager.getConnection */

sldbc_stmt *s;
sldbc_prepare(c, "INSERT INTO person VALUES (?, ?)", &s);
sldbc_bind(s, 1, "1");                        /* PreparedStatement.setString */
sldbc_bind(s, 2, "Ada");
sldbc_execute(s);                             /* executeUpdate */
sldbc_finalize(s);

sldbc_prepare(c, "SELECT id, name FROM person", &s);
sldbc_rows *r;
sldbc_query(s, &r);                           /* executeQuery -> ResultSet */
for (size_t i = 0; i < sldbc_rows_count(r); ++i)
    printf("%s\n", sldbc_rows_value_named(r, i, "name"));
sldbc_rows_free(r);
sldbc_finalize(s);

sldbc_begin(c); /* ... */ sldbc_rollback(c);  /* setAutoCommit(false)/rollback */
sldbc_close(c);

Drivers

The connection URL scheme selects the driver, exactly like a JDBC URL:

This keeps the connector truthful: it only claims the backend it can actually reach today, while providing the full API shape for the rest.

Build and test

cd lib/db-connector
make          # -> build/libsldbc.a (bundles the sleela-sql engine core)
make test     # full JDBC-style lifecycle + honest-stub behaviour

The static archive bundles the engine core, so a consumer links one library:

cc myapp.c -I lib/db-connector/include lib/db-connector/build/libsldbc.a -o myapp

Honest limits

Files 5