ID: 39564 User updated by: php dot bugreport dot tarpit at spamgourmet dot com Reported By: php dot bugreport dot tarpit at spamgourmet dot com -Status: Bogus +Status: Open Bug Type: PDO related Operating System: Windows 98SE and XP/SP1 PHP Version: 5.2.0 New Comment:
I tried the following code using SQLite 3.3.7: #include <stdio.h> #include <process.h> #include <string.h> #include <sqlite3.h> int main() { sqlite3 *db; sqlite3_stmt *stm; int rc; char *sqli, *sqlp, *zErr; const char *tail; rc = sqlite3_open("bugtest.db", &db); if(rc) { fprintf(stdout, "Can't open database: %s\n", sqlite3_errmsg(db)); exit(255); } sqli = "Insert Into TEST (Key, Text) Values (1, 'Test1')"; sqlp = "Insert Into TEST (Key, Text) Values (?, ?)"; rc = sqlite3_exec(db, sqli, NULL, NULL, &zErr); if(rc) { fprintf(stdout, "exec(): %i - %s\n", rc, zErr); } rc = sqlite3_prepare(db, sqlp, strlen(sqlp), &stm, &tail); if(rc) { fprintf(stdout, "prepare(): %i - %s\n", rc, zErr); } rc = sqlite3_bind_int(stm, 1, 1); if(rc) { fprintf(stdout, "bind_int(): %i - %s\n", rc, zErr); } rc = sqlite3_bind_text(stm, 2, "Test1", 5, SQLITE_STATIC); if(rc) { fprintf(stdout, "bind_text(): %i - %s\n", rc, zErr); } rc = sqlite3_step(stm); if(rc) { fprintf(stdout, "step(): %i - %s\n", rc, zErr); } sqlite3_finalize(stm); sqlite3_close(db); return 0; } With result: exec(): 19 - PRIMARY KEY must be unique step(): 1 - PRIMARY KEY must be unique Yes, sqlite3_step() does return the wrong errorcode - that is a bug in SQLite. But it still returns the correct message, which appears to get lost somewhere..... Previous Comments: ------------------------------------------------------------------------ [2006-11-21 22:10:34] [EMAIL PROTECTED] These two methods use different SQLite functions to execute queries, which report different errors. And that is the reason I can hardly imagine why it's PDO fault. ------------------------------------------------------------------------ [2006-11-21 22:04:52] php dot bugreport dot tarpit at spamgourmet dot com Original category was "SQLite related" - because that is the only part of PDO I use. Since the error is obviously not in SQLite (which reports the correct errors), but in PDO (which reports different errors depending on the use of PDO::exec() or PDOStatement::execute() functions), category "PDO related" would be better. ------------------------------------------------------------------------ [2006-11-21 09:29:12] [EMAIL PROTECTED] SQLite inconsistencies should be reported to SQLite developers. ------------------------------------------------------------------------ [2006-11-20 23:56:21] php dot bugreport dot tarpit at spamgourmet dot com Description: ------------ When retrieving error information with PDO::errorInfo() after an SQL-insert causing a constraint violation results are inconsistent depending on the form of the statement: PDO::exec() or PDOStatement::execute(). Reproduce code: --------------- SQL to create database followed by sample PHP: CREATE TABLE TEST ( Key Integer Primary Key, Text Char(20) Not Null ); CREATE UNIQUE INDEX iTEST On TEST ( Text ); <?php $dbh_test=New PDO("sqlite:C:/Data/PHP5TEST.DB"); $dbh_test->SetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); $dbh_test->Exec("Insert Into TEST (Key, Text) Values (1, 'Test1')"); $pdo_error=$dbh_test->ErrorInfo(); Print "\n$pdo_error[0] $pdo_error[1] $pdo_error[2] :: 1, 'Test1'\n"; $sql="Insert Into TEST (Key, Text) Values (:key, :text)"; $sq_insert=$dbh_test->Prepare($sql); $sq_insert->BindParam(':key', $key); $sq_insert->BindParam(':text', $text); $key=1; $text="Test1"; $sq_insert->Execute(); $pdo_error=$sq_insert->ErrorInfo(); Print "\n$pdo_error[0] $pdo_error[1] $pdo_error[2] :: $key, $text\n"; Exit(0); ?> Expected result: ---------------- 23000 19 PRIMARY KEY must be unique :: 1, 'Test1' 23000 19 PRIMARY KEY must be unique :: 1, 'Test1' Actual result: -------------- PHP 5.1.6: 23000 19 PRIMARY KEY must be unique :: 1, 'Test1' HY000 1 PRIMARY KEY must be unique :: 1, Test1 PHP 5.2.0: 23000 19 PRIMARY KEY must be unique :: 1, 'Test1' HY000 1 SQL logic error or missing database :: 1, Test1 5CVS-2006-11-18: 23000 19 PRIMARY KEY must be unique :: 1, 'Test1' HY000 1 SQL logic error or missing database :: 1, Test1 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39564&edit=1