9. Wrappers for getting/pushing sqlite
Runt has a dumb type system, which can be used to add a thin layer of confidence that the C data you are hucking is in fact a sqlite database handle, and not something like I don't know an ftable?
Speaking of tables, the structure of these is based on the ftable wrappers found in the graforge codebase (the author is going over there right now...)
rgf_get_sqlite
will pop a SQLite database off the stack.
If that item is not a SQLite database, then it will throw
an error.
runt_int rgf_get_sqlite(runt_vm *vm, sqlite3 **db);
runt_int rgf_get_sqlite(runt_vm *vm, sqlite3 **db)
{
runt_int rc;
runt_stacklet *s;
rc = runt_ppop(vm, &s);
RUNT_ERROR_CHECK(rc);
if (s->t != RUNT_END + TYPE_SQLITE) {
runt_print(vm, "Parameter does not seem to be sqlite.\n");
*db = NULL;
return RUNT_NOT_OK;
}
*db = runt_to_cptr(s->p);
return RUNT_OK;
}
rgf_stacklet_sqlite
will configure a runt stacklet to hold
a sqlite database handle. The ID will be set to be
END + 5717
, where END
is the end value from
rgf_get_end
.
void rgf_stacklet_sqlite(runt_vm *vm, runt_stacklet *s, sqlite3 *db);
void rgf_stacklet_sqlite(runt_vm *vm, runt_stacklet *s, sqlite3 *db)
{
s->p = runt_mk_cptr(vm, db);
s->t = RUNT_END + TYPE_SQLITE;
}
The value 5717 is a number derived from
taking the base64 value "sql" (0xb2a9), and right-shifting
3: base64("sql")>>3
#define TYPE_SQLITE 5717
prev | home | next