Bug #81376 [Ver]: fetchArray refuses to work with UPDATE ... RETURNING
| From: | cmb@php.net | Date: | Wed, 25 Aug 2021 14:18:41 +0000 |
| Subject: | Bug #81376 [Ver]: fetchArray refuses to work with UPDATE ... RETURNING | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236068@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81376&edit=1
ID: 81376
Updated by: cmb@php.net
Reported by: abrahin dot andrei at yandex dot ru
Summary: fetchArray refuses to work with UPDATE ... RETURNING
Status: Verified
Type: Bug
Package: SQLite related
Operating System: Arch Linux
PHP Version: 8.0.9
Block user comment: N
Private report: N
New Comment:
@nikic, see <https://github.com/php/php-src/pull/5204>.
TL;DR: we *need* to drop SQLite3Result altogether.
Previous Comments:
------------------------------------------------------------------------
[2021-08-25 09:05:30] nikic@php.net
@cmb PDO uses a flag to skip the next step without resetting, maybe we should do that in sqlite3 as
well?
------------------------------------------------------------------------
[2021-08-23 12:25:27] cmb@php.net
> I expected to see a row full of data and enjoy the possibilities
> provided by the SQLite v3.36.0
Use PDO_SQLite instead. :)
------------------------------------------------------------------------
[2021-08-23 12:23:01] cmb@php.net
I can confirm the issue. It has the same root cause as bug
#64531, namely that SQLite3::execute() already calls
sqlite3_step() to learn if there is a result set or not, and then
resets the statement to be able to start from the beginning. This
doesn't work for DML statements, though.
I think the only way forward to fix this issue and some others,
would be to drop SQLite3Result altogether, and to move its methods
to SQLite3Statement. Serious BC break, though.
------------------------------------------------------------------------
[2021-08-21 19:39:40] abrahin dot andrei at yandex dot ru
Description:
------------
---
From manual page: https://php.net/sqlite3result.fetcharray
---
SQLite3Result::fetchArray() returns FALSE on 'UPDATE ... RETURNING ...' even if some rows
were affected.
Please note that this interface is fully supported since v3.35, and i have v3.36 installed (as
evidenced by output of
SQLite3::version()).
https://www.sqlite.org/lang_returning.html
https://www.sqlite.org/lang_update.html
Test script:
---------------
$GLOBALS['db'] = new SQLite3('testdb.sqlite');
$db->exec('CREATE TABLE IF NOT EXISTS cron (time INTEGER, type INTEGER, private TEXT');
$db->exec('INSERT INTO cron (time, type, private) VALUES (3, 1, 0)');
$stmt = $db->prepare('UPDATE cron SET time = 10 WHERE time < 10 RETURNING *;');
$res = $stmt->execute();
var_dump($res->fetchArray()); # <-- returns false, should instead return a row
Expected result:
----------------
I expected to see a row full of data and enjoy the possibilities provided by the SQLite v3.36.0
Actual result:
--------------
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81376&edit=1