php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49268 PDO::Execute and SQLite CHECK constarints quoting INTS
Submitted: 2009-08-15 15:24 UTC Modified: 2009-08-15 16:36 UTC
From: face at dfhu dot org Assigned:
Status: Not a bug Package: SQLite related
PHP Version: 5.2.6-2ubuntu4.2 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
3 + 11 = ?
Subscribe to this entry?

 
 [2009-08-15 15:24 UTC] face at dfhu dot org
Description:
------------
PDO::Execute quotes integers even though this will cause problems in SQLite. SQLite has type affinity and sometimes requires hard checks.

that is "(product_id) VALUES ('1')" is NOT the same as "(product_id) VALUES (1)";


Thanks!
 -- Victory 
http://dfhu.org/blog/


Reproduce code:
---------------
$pdo=new PDO("sqlite:./db/sales.sqlite");
$pdo->setAttribute(PDO::ATTR_ERRMODE,
		   PDO::ERRMODE_EXCEPTION);
$sql="
CREATE TABLE IF NOT EXISTS sales (
product_id INT
 CHECK(typeof(product_id) = 'integer')
)";
$pdo->query($sql);

$sql="
INSERT INTO sales
 (product_id)
   VALUES
 (:product_id)";
$statement=$pdo->prepare($sql);

// this will throw a integrity constraint error
$statement->execute(Array(":product_id"=>1));


Expected result:
----------------
I do not expect to see an exception thrown, i expect PDO::execute() to not quote integers in SQLite. Thus there should be no output.

Actual result:
--------------
Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 19 constraint failed'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-15 15:38 UTC] face at dfhu dot org
The version number was not accurate. 5.2.6-2ubuntu4.2 is the version as shown by phpinfo();
 [2009-08-15 16:36 UTC] scottmac@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.


This was fixed in 5.3.0 already, see bug #42443
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 09:01:28 2024 UTC