Skip to content

Commit 889f75c

Browse files
committed
Migrate SQLite to use exceptions instead of returning FALSE
Includes forward-compatible checks for PHP 9.0, when this will be the default See https://wiki.php.net/rfc/sqlite3_exceptions Implements #52
1 parent fa2bbef commit 889f75c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/php/rdbms/sqlite3/SQLite3Connection.class.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public function connect($reconnect= false) {
103103

104104
try {
105105
$this->handle= new SQLite3($database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
106+
PHP_VERSION_ID >= 90000 || $this->handle->enableExceptions(true);
106107
} catch (Exception $e) {
108+
$this->handle= false;
107109
throw new SQLConnectException($e->getMessage().': '.$database, $this->dsn);
108110
}
109111

@@ -160,16 +162,17 @@ public function identity($field= null) {
160162
protected function query0($sql, $buffered= true) {
161163
$this->handle instanceof SQLite3 || $this->connections->establish($this);
162164

163-
$result= $this->handle->query($sql);
164-
if (false === $result) {
165-
$e= new SQLStatementFailedException(
165+
try {
166+
$result= $this->handle->query($sql);
167+
} catch (Exception $e) {
168+
throw new SQLStatementFailedException(
166169
'Statement failed: '.$this->handle->lastErrorMsg().' @ '.$this->dsn->getDatabase(),
167170
$sql,
168171
$this->handle->lastErrorCode()
169172
);
170-
\xp::gc(__FILE__);
171-
throw $e;
172-
} else if ($result->numColumns()) {
173+
}
174+
175+
if ($result->numColumns()) {
173176
return new SQLite3ResultSet($result);
174177
} else {
175178
return new QuerySucceeded($this->handle->changes());

0 commit comments

Comments
 (0)