diff options
author | George Peter Banyard <girgias@php.net> | 2020-09-25 00:41:21 +0100 |
---|---|---|
committer | George Peter Banyard <girgias@php.net> | 2020-09-28 18:51:36 +0100 |
commit | a5cf82802d097f7c327ee7e4eafe2224a5c9f78b (patch) | |
tree | a1072b3c40f6bc9cfb66324850701a0c4944bb36 /ext/pdo_sqlite | |
parent | 24e2ba26b457da2c93aae75c7193c519b5a0aed9 (diff) | |
download | php-git-a5cf82802d097f7c327ee7e4eafe2224a5c9f78b.tar.gz |
Make various failure conditions in PDO unconditional errors
This includes TypeErrors, ValueErrors, Error for uninitialized objects
and invalid user classes/callable instanciation
Closes GH-6212
Diffstat (limited to 'ext/pdo_sqlite')
-rw-r--r-- | ext/pdo_sqlite/tests/bug_44159_sqlite_version.phpt | 22 | ||||
-rw-r--r-- | ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt | 112 |
2 files changed, 78 insertions, 56 deletions
diff --git a/ext/pdo_sqlite/tests/bug_44159_sqlite_version.phpt b/ext/pdo_sqlite/tests/bug_44159_sqlite_version.phpt new file mode 100644 index 0000000000..fc30f1d21c --- /dev/null +++ b/ext/pdo_sqlite/tests/bug_44159_sqlite_version.phpt @@ -0,0 +1,22 @@ +--TEST-- +PDO Common: Bug #44159: SQLite variant +--SKIPIF-- +<?php +if (!extension_loaded('pdo_sqlite')) die('skip PDO SQLite not available'); +?> +--FILE-- +<?php +$pdo = new PDO("sqlite:".__DIR__."/foo.db"); +$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); + +var_dump($pdo->setAttribute(PDO::NULL_TO_STRING, NULL)); +var_dump($pdo->setAttribute(PDO::NULL_TO_STRING, 1)); +var_dump($pdo->setAttribute(PDO::NULL_TO_STRING, 'nonsense')); + +@unlink(__DIR__."/foo.db"); + +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) diff --git a/ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt b/ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt index 4600b7935b..814a01a647 100644 --- a/ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt +++ b/ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt @@ -20,20 +20,40 @@ $st->fetchAll(PDO::FETCH_FUNC, function($x, $y) use ($st) { var_dump($st); print $st = $db->query('SELECT name FROM testing'); var_dump($st->fetchAll(PDO::FETCH_FUNC, 'strtoupper')); -$st = $db->query('SELECT * FROM testing'); -var_dump($st->fetchAll(PDO::FETCH_FUNC, 'nothing')); +try { + $st = $db->query('SELECT * FROM testing'); + var_dump($st->fetchAll(PDO::FETCH_FUNC, 'nothing')); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} -$st = $db->query('SELECT * FROM testing'); -var_dump($st->fetchAll(PDO::FETCH_FUNC, '')); +try { + $st = $db->query('SELECT * FROM testing'); + var_dump($st->fetchAll(PDO::FETCH_FUNC, '')); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} -$st = $db->query('SELECT * FROM testing'); -var_dump($st->fetchAll(PDO::FETCH_FUNC, NULL)); +try { + $st = $db->query('SELECT * FROM testing'); + var_dump($st->fetchAll(PDO::FETCH_FUNC, NULL)); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} -$st = $db->query('SELECT * FROM testing'); -var_dump($st->fetchAll(PDO::FETCH_FUNC, 1)); +try { + $st = $db->query('SELECT * FROM testing'); + var_dump($st->fetchAll(PDO::FETCH_FUNC, 1)); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} -$st = $db->query('SELECT * FROM testing'); -var_dump($st->fetchAll(PDO::FETCH_FUNC, array('self', 'foo'))); +try { + $st = $db->query('SELECT * FROM testing'); + var_dump($st->fetchAll(PDO::FETCH_FUNC, array('self', 'foo'))); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} class foo { public function method($x) { @@ -64,14 +84,26 @@ new bar($db); $st = $db->query('SELECT * FROM testing'); var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test'))); -$st = $db->query('SELECT * FROM testing'); -var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test2'))); +try { + $st = $db->query('SELECT * FROM testing'); + var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test2'))); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} -$st = $db->query('SELECT * FROM testing'); -var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test3'))); +try { + $st = $db->query('SELECT * FROM testing'); + var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test3'))); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} -$st = $db->query('SELECT * FROM testing'); -var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'inexistent'))); +try { + $st = $db->query('SELECT * FROM testing'); + var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'inexistent'))); +} catch (\TypeError $e) { + echo $e->getMessage(), \PHP_EOL; +} ?> --EXPECTF-- @@ -91,31 +123,11 @@ array(2) { [1]=> string(0) "" } - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: function "nothing" not found or invalid function name in %s on line %d - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error in %s on line %d -bool(false) - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: function "" not found or invalid function name in %s on line %d - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error in %s on line %d -bool(false) - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: no array or string given in %s on line %d - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error in %s on line %d -bool(false) - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: no array or string given in %s on line %d - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error in %s on line %d -bool(false) - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: cannot access "self" when no class scope is active in %s on line %d - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error in %s on line %d -bool(false) +function "nothing" not found or invalid function name +function "" not found or invalid function name +PDOStatement::fetchAll(): Argument #2 must be a callable, null given +no array or string given +cannot access "self" when no class scope is active array(2) { [0]=> string(9) "--- 1 ---" @@ -128,18 +140,6 @@ array(2) { [1]=> string(4) "2---" } - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: non-static method bar::test2() cannot be called statically in %s on line %d - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error in %s on line %d -bool(false) - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: non-static method bar::test3() cannot be called statically in %s on line %d - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error in %s on line %d -bool(false) - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: class bar does not have a method "inexistent" in %s on line %d - -Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error in %s on line %d -bool(false) +non-static method bar::test2() cannot be called statically +non-static method bar::test3() cannot be called statically +class bar does not have a method "inexistent" |