3 extern const char *sqlite3_libversion(void);
4 function sqlite3\version() : string {
5 return to_string(sqlite3_libversion);
8 extern const char *sqlite3_errstr(int errno);
9 function sqlite3\errstr(int $errno) : string {
10 let errno = intval($errno);
11 return to_string(sqlite3_errstr);
14 /* obviously fake, we ever always need a pointer to it */
15 struct sqlite3::(8, 8);
17 typedef struct sqlite3 sqlite3;
19 typedef int64_t sqlite_int64;
20 typedef uint64_t sqlite_uint64;
22 typedef sqlite_int64 sqlite3_int64;
23 typedef sqlite_uint64 sqlite3_uint64;
25 extern void sqlite3_free(void *ptr);
26 function sqlite3\free(object $object) : void {
27 let ptr = objval($object);
28 return void(sqlite3_free);
31 extern int sqlite3_close(sqlite3 *db);
32 function sqlite3\close(object $db) : int {
34 return to_int(sqlite3_close);
37 extern int sqlite3_open(const char *filename, sqlite3 **db_ptr);
38 function sqlite3\open(string $uri, object &$db) : int {
39 let filename = pathval($uri);
41 return to_int(sqlite3_open);
42 set $db = to_object(*db_ptr);
45 typedef int (*sqlite3_callback)(void *data, int argc, char** argv, char** cols);
48 * C calls into us, so we have to have a way to define how the callback
49 * arguments have to be marshaled for the userland callback, i.e. from
50 * native C types to ZE zvals /and/ how the userland return value has
51 * to be marshaled to a native type. All in all, the opposite of function impls.
54 extern int sqlite3_exec(sqlite3 *db, const char *sql, sqlite3_callback callback, void *data, char **errmsg);
55 function sqlite3\exec(object $db, string $sql, callable $cb, mixed $cd, string &$error = null) : int {
57 let sql = strval($sql);
58 let callback = callback intval(
62 to_array(argv, argc, to_string(argv)),
63 to_array(cols, argc, to_string(cols))
68 return to_int(sqlite3_exec);
69 set $error = to_string(*errmsg);