Skip to content

Commit ddd9a08

Browse files
bohwazTimWolla
andauthored
[RFC] Transition SQLite3 to exceptions (#11058)
* Deprecate warnings in SQLite3, change returned exception class to SQLite3Exception RFC: https://wiki.php.net/rfc/sqlite3_exceptions Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
1 parent 9f4bd30 commit ddd9a08

14 files changed

+133
-82
lines changed

UPGRADING

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ PHP 8.3 UPGRADE NOTES
117117
. The ZipArchive::FL_RECOMPRESS constant is deprecated and will be removed
118118
in a future version of libzip
119119

120+
- SQLite3
121+
. Using exceptions is now preferred, warnings will be removed in the future.
122+
Calling SQLite3::enableExceptions(false) will trigger a depreciation warning
123+
in this version.
124+
120125
========================================
121126
5. Changed Functions
122127
========================================
@@ -262,6 +267,12 @@ PHP 8.3 UPGRADE NOTES
262267
9. Other Changes to Extensions
263268
========================================
264269

270+
- SQLite3
271+
. The SQLite3 class now throws \SQLite3Exception (extends \Exception) instead
272+
of \Exception.
273+
. The SQLite error code is now passed in the exception error code instead of being
274+
included in the error message.
275+
265276
========================================
266277
10. New Global Constants
267278
========================================

ext/sqlite3/sqlite3.c

Lines changed: 81 additions & 66 deletions
Large diffs are not rendered by default.

ext/sqlite3/sqlite3.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868
const SQLITE3_DETERMINISTIC = UNKNOWN;
6969
#endif
7070

71+
/**
72+
* @strict-properties
73+
*/
74+
class SQLite3Exception extends \Exception
75+
{
76+
}
77+
7178
/** @not-serializable */
7279
class SQLite3
7380
{

ext/sqlite3/sqlite3_arginfo.h

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/sqlite3/tests/bug69972.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ echo "Error Msg: " . $db->lastErrorMsg() . "\n";
1818
--EXPECTF--
1919
SELECTING from invalid table
2020

21-
Warning: SQLite3::query(): Unable to prepare statement: 1, no such table: non_existent_table in %sbug69972.php on line %d
21+
Warning: SQLite3::query(): Unable to prepare statement: no such table: non_existent_table in %sbug69972.php on line %d
2222
Closing database
2323
bool(true)
2424
Done

ext/sqlite3/tests/gh9032.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ try {
1717
$st->bindValue("a", ":memory:");
1818
$st->execute();
1919
var_dump($db->exec('create table db2.r (id int)'));
20-
} catch (Exception $ex) {
20+
} catch (SQLite3Exception $ex) {
2121
echo $ex->getMessage(), PHP_EOL;
2222
}
2323
?>
2424
--EXPECT--
2525
bool(true)
26-
Unable to prepare statement: 23, not authorized
26+
Unable to prepare statement: not authorized

ext/sqlite3/tests/sqlite3_20_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ echo "Done\n";
2020
--EXPECTF--
2121
SELECTING from invalid table
2222

23-
Warning: SQLite3::query(): Unable to prepare statement: 1, no such table: non_existent_table in %s on line %d
23+
Warning: SQLite3::query(): Unable to prepare statement: no such table: non_existent_table in %s on line %d
2424
Error Code: 1
2525
Error Msg: no such table: non_existent_table
2626
Closing database

ext/sqlite3/tests/sqlite3_33_load_extension_param.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ $db = new SQLite3(':memory:');
2020

2121
try {
2222
$db->loadExtension("");
23-
} catch (Extension $ex) {
23+
} catch (\Throwable $ex) {
2424
var_dump($ex->getMessage());
2525
}
2626

2727
?>
2828
--EXPECTF--
29-
Warning: SQLite3::loadExtension(): Empty string as an extension in %s on line %d
29+
string(61) "SQLite3::loadExtension(): Argument #1 ($name) cannot be empty"

ext/sqlite3/tests/sqlite3_34_load_extension_ext_dir.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ try {
2424

2525
?>
2626
--EXPECTF--
27-
Warning: SQLite3::loadExtension(): SQLite Extension are disabled in %s on line %d
27+
Warning: SQLite3::loadExtension(): SQLite Extensions are disabled in %s on line %d

ext/sqlite3/tests/sqlite3_40_setauthorizer.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ try {
7171
?>
7272
--EXPECT--
7373
int(1)
74-
Unable to prepare statement: 23, not authorized
74+
Unable to prepare statement: not authorized
7575
bool(true)
7676
int(42)
7777
string(6) "SELECT"
@@ -98,7 +98,7 @@ string(28) "sqlite_master,rootpage,main,"
9898
string(4) "READ"
9999
string(28) "sqlite_master,rootpage,main,"
100100
bool(true)
101-
Unable to prepare statement: 23, not authorized
101+
Unable to prepare statement: not authorized
102102
The authorizer callback returned an invalid type: expected int
103-
Unable to prepare statement: 23, not authorized
104-
The authorizer callback returned an invalid value
103+
Unable to prepare statement: not authorized
104+
The authorizer callback returned an invalid value: 4200

ext/sqlite3/tests/sqlite3_defensive.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ bool(true)
3737
int(1)
3838
int(1)
3939

40-
Warning: SQLite3::querySingle(): Unable to prepare statement: 1, table sqlite_master may not be modified in %s on line %d
40+
Warning: SQLite3::querySingle(): Unable to prepare statement: table sqlite_master may not be modified in %s on line %d
4141
bool(false)
42-
int(1)
42+
int(1)

ext/sqlite3/tests/sqlite3_enable_exceptions.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ echo "Done\n";
2424
--EXPECTF--
2525
bool(false)
2626
no such table: non_existent_table
27+
28+
Deprecated: SQLite3::enableExceptions(): Use of warnings for SQLite3 is deprecated in %s
2729
bool(true)
2830

2931
Warning: SQLite3::query(): no such table: non_existent_table in %s on line %d

ext/sqlite3/tests/sqlite3_prepare_faultystmt.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ $stmt = $db->prepare('SELECT foo FROM bar');
1616
var_dump($stmt);
1717
?>
1818
--EXPECTF--
19-
Warning: SQLite3::prepare(): Unable to prepare statement: 1, no such table: bar in %s on line %d
19+
Warning: SQLite3::prepare(): Unable to prepare statement: no such table: bar in %s on line %d
2020
bool(false)

ext/sqlite3/tests/sqlite3_trampoline_setauthorizer.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ try {
3838
Trampoline for authorizer
3939
int(1)
4040
Trampoline for authorizer
41-
Unable to prepare statement: 23, not authorized
41+
Unable to prepare statement: not authorized

0 commit comments

Comments
 (0)