Skip to content

Commit 5caf4c4

Browse files
committed
Let loadExtension return success status
1 parent aa35f83 commit 5caf4c4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/WrappedConnection.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
namespace Moxio\SQLiteExtendedAPI;
33

44
final class WrappedConnection {
5+
/* From https://github.com/sqlite/sqlite/blob/278b0517d88d4150830a4ee2c628a55da40d186d/src/sqlite.h.in#L421 */
6+
private const SQLITE_OK = 0;
7+
/* From https://github.com/sqlite/sqlite/blob/278b0517d88d4150830a4ee2c628a55da40d186d/src/sqlite.h.in#L423 */
8+
private const SQLITE_ERROR = 1;
9+
510
/* From https://github.com/sqlite/sqlite/blob/278b0517d88d4150830a4ee2c628a55da40d186d/src/sqlite.h.in#L2330 */
611
private const SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION = 1005;
712

@@ -17,8 +22,10 @@ public function getDatabaseFilename(): string {
1722
return $this->sqlite3_ffi->sqlite3_db_filename($this->sqlite3_pointer, "main");
1823
}
1924

20-
public function loadExtension(string $shared_library): void {
25+
public function loadExtension(string $shared_library): bool {
2126
$this->sqlite3_ffi->sqlite3_db_config($this->sqlite3_pointer, self::SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, null);
22-
$this->sqlite3_ffi->sqlite3_load_extension($this->sqlite3_pointer, $shared_library, null, null);
27+
$result_code = $this->sqlite3_ffi->sqlite3_load_extension($this->sqlite3_pointer, $shared_library, null, null);
28+
29+
return $result_code === self::SQLITE_OK;
2330
}
2431
}

test/Integration/ExtensionLoadingTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ public function testLoadExtensionLoadsAnSQLiteExtension() {
2424
$this->markTestSkipped(sprintf("SQLite extension file '%s' needed for test not found", self::EXTENSION));
2525
}
2626

27-
$this->wrapped_connection->loadExtension(self::EXTENSION);
27+
$this->assertTrue($this->wrapped_connection->loadExtension(self::EXTENSION));
2828
$this->assertNotFalse($this->pdo->query(self::EXTENSION_VERIFICATION_QUERY));
2929
}
30+
31+
public function testLoadExtensionReturnsFalseIfExtensionCouldNotBeLoaded() {
32+
$extension_dir = ini_get('sqlite3.extension_dir') ?: '/usr/lib/x86_64-linux-gnu';
33+
$extension_file = $extension_dir . '/mod_does_not_exist.so';
34+
35+
$this->assertFalse($this->wrapped_connection->loadExtension($extension_file));
36+
}
3037
}

0 commit comments

Comments
 (0)