SQLite User Forum

PHP: fetchArray: UNIQUE constraint failed
Login

PHP: fetchArray: UNIQUE constraint failed

(1) By M95D (Marius95) on 2022-01-10 10:29:27 [link] [source]

Hi. I have personal project using Hiawatha, PHP and Firebird. I saw that sqlite recently introduced support for SELECT...RETURNING... and I'm trying to switch to sqlite3. I encountered some problems. It might be a bug in sqlite or php. I need some confirmation it's not just on my system.

Please test this program:

$DB=new SQLite3('/tmp/test.sqlite');
$DB->exec('CREATE TABLE test (ID INTEGER NOT NULL PRIMARY KEY, OtherID INTEGER NULL UNIQUE);');
$DB->exec('BEGIN;');
$STATEMENT=$DB->prepare('INSERT INTO test (OtherID) VALUES (:OtherID) RETURNING ID, OtherID');
$STATEMENT->bindValue(':OtherID', 1234);
$RESULT=$STATEMENT->execute();
$ROW=$RESULT->fetchArray();
var_dump($ROW);
$DB->exec('COMMIT;');
On my system I get: Warning: SQLite3Result::fetchArray(): Unable to execute statement: UNIQUE constraint failed: test.OtherID The row is introduced corectly after the program finishes, but the program outputs NULL after the error, not the returning row.

Thanks. Marius

(2) By M95D (Marius95) on 2022-01-10 10:46:08 in reply to 1 [source]

It's a PHP bug. I found it just now. Sorry.

https://bugs.php.net/bug.php?id=81376