-
Notifications
You must be signed in to change notification settings - Fork 4
/
WrappedConnection.php
31 lines (24 loc) · 1.3 KB
/
WrappedConnection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
namespace Moxio\SQLiteExtendedAPI;
final class WrappedConnection {
/* From https://github.com/sqlite/sqlite/blob/278b0517d88d4150830a4ee2c628a55da40d186d/src/sqlite.h.in#L421 */
private const SQLITE_OK = 0;
/* From https://github.com/sqlite/sqlite/blob/278b0517d88d4150830a4ee2c628a55da40d186d/src/sqlite.h.in#L423 */
private const SQLITE_ERROR = 1;
/* From https://github.com/sqlite/sqlite/blob/278b0517d88d4150830a4ee2c628a55da40d186d/src/sqlite.h.in#L2330 */
private const SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION = 1005;
private \FFI $sqlite3_ffi;
private \FFI\CData $sqlite3_pointer;
public function __construct(\FFI $sqlite3_ffi, \FFI\CData $sqlite3_pointer) {
$this->sqlite3_ffi = $sqlite3_ffi;
$this->sqlite3_pointer = $sqlite3_pointer;
}
public function getDatabaseFilename(): string {
return $this->sqlite3_ffi->sqlite3_db_filename($this->sqlite3_pointer, "main");
}
public function loadExtension(string $shared_library): bool {
$this->sqlite3_ffi->sqlite3_db_config($this->sqlite3_pointer, self::SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, null);
$result_code = $this->sqlite3_ffi->sqlite3_load_extension($this->sqlite3_pointer, $shared_library, null, null);
return $result_code === self::SQLITE_OK;
}
}