php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52746 PDO SQLite error "bind or column index out of range" with some placeholders
Submitted: 2010-08-30 20:20 UTC Modified: 2011-01-06 01:32 UTC
Votes:3
Avg. Score:3.3 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: damien at tournoud dot net Assigned:
Status: Open Package: SQLite related
PHP Version: 5.3.3 OS:
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-08-30 20:20 UTC] damien at tournoud dot net
Description:
------------
The following snippet results in a PDOException with message "SQLSTATE[HY000]: General error: 25 bind or column index out of range".

For some reasons, relatively similar queries work (for example, without the aggregation, as in: "SELECT * FROM (SELECT :value value FROM sqlite_master) my_table" or without the table as in "SELECT COUNT(*) expression FROM (SELECT :value value) my_table").



Test script:
---------------
<?php
$db = new PDO('sqlite:/tmp/sqlite.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$query = $db->prepare('SELECT COUNT(*) expression FROM (SELECT :value value FROM sqlite_master) my_table');
$query->execute(array(':value' => 'my_value'));
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-31 10:46 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2010-08-31 10:46 UTC] pajoye@php.net
hi Damien,

Do you use the bundled sqlite or a system version? If the latter, which version is it?
 [2010-08-31 11:15 UTC] damien at tournoud dot net
-Status: Feedback +Status: Open
 [2010-08-31 11:15 UTC] damien at tournoud dot net
That's on Debian, so it is using the system library. I'm able to reproduce that behavior on a wide range of PHP and SQLite versions:

PHP 5.2.6-1+lenny9 -- SQLite 3.5.9 (external)
PHP 5.3.2-0.dotdeb.2 -- SQLite 3.6.21 (external)
PHP trunk -- SQLite 3.7.0.1 (bundled)
 [2010-08-31 11:33 UTC] damien at tournoud dot net
This seems to work properly with unnamed placeholders.

For named placeholders, it seems to only fail when the placeholder is part of a branch of the query that is deadcode, and could potentially be removed by the optimizer:

FAILS: SELECT SUM(1) expression FROM (SELECT :value value FROM sqlite_master) my_table
PASS: SELECT SUM(value) expression FROM (SELECT :value value FROM sqlite_master) my_table
 [2011-01-06 01:32 UTC] scottmac@php.net
-Summary: SQLite error "bind or column index out of range" with some placeholders +Summary: PDO SQLite error "bind or column index out of range" with some placeholders
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 24 21:01:55 2014 UTC