Skip to content

artnum/quaerimus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quaerimus

Caution

This is a work in progress. The API is not stable, anything can change at any time.

Abstraction for libmariadb to allow named parameters, as in PHP PDO.

The underlying code use prepared statement.

In PHP, when you prepare a statement with a named parameter, you bind with the colon in the name. In quaerimus, the colon is not needed (and not wanted) :

$stmt = $dbh->prepare("SELECT * FROM table WHERE id = :id");
$stmt->bindParam(":id", 10, PDO::PARAM_INT);

In quaerimus :

qury_stmt_t *stmt = qury_new(qury_conn, NULL);
qury_prepare(stmt, "SELECT * FROM table WHERE id = :id", 0);
qury_bind_bind_int(stmt, "id", 10);

Custom allocator

A custom allocator can be used, still a work in progress on how I want it to be.

SELECT query

Warning

Not everything is wrapped within quaerimus. Maybe not everything will be wrapped, I see no reason to create a qury_connect function as there is already mysql_real_connect.

A basic select with quaerimus would be like :

qury_conn_t conn;
qury_conn_init(&conn);

mysql_library_init(0, NULL, NULL);

if (!mysql_real_connect(conn.mysql, "localhost", "user", "password", NULL,
                        0, NULL, 0)) {
    exit(EXIT_FAILURE);
}

/* Not using a custom allocator */
qury_stmt_t *stmt = qury_new(&conn, NULL);
if (!stmt
    || !qury_prepare(stmt, "SELECT * FROM table WHERE size > :size", 0)
    || !qury_select_db(stmt, "my_db")
    || !qury_stmt_bind_int(stmt, "size", 10)
    || !qury_execute(stmt)) {
    qury_free(stmt);
    exit(EXIT_FAILURE);
}

while(qury_fetch(stmt)) {
    qury_bind_t *value = NULL;
    
    if(qury_get_value(stmt, "name", &)) {
        char *name = qury_get_cstr(v);
        if (name) {
            printf("NAME %s\n", name);
        }
    }
}

qury_free(stmt);
mysql_close(conn.mysql);
mysql_libaray_end();

INSERT/UPDATE/DELETE query

Nothing has been done for that yet.

License

MIT.

About the name

Project name was choosen by AI.

About

Higher-level mariadb (mysql) C client library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors