From 8ba2805c91b7997c860fba160352c9ef05821f32 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sun, 17 May 2009 03:31:36 +0000 Subject: [PATCH] #464878 by chx: Fix SQLite abstraction layer to accept arrays of placeholder values without leading :, for compatibility with PDO. --- includes/database/sqlite/database.inc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/database/sqlite/database.inc b/includes/database/sqlite/database.inc index abfe42c1648..f4ee1704c8e 100644 --- a/includes/database/sqlite/database.inc +++ b/includes/database/sqlite/database.inc @@ -202,11 +202,20 @@ class DatabaseStatement_sqlite extends DatabaseStatementPrefetch implements Iter // Else, this is using named placeholders. foreach ($args as $placeholder => $value) { if (is_numeric($value)) { + // We will remove this placeholder from the query and PDO throws an + // exception if the number of placeholders in the query and the + // arguments does not match. + unset($args[$placeholder]); + // PDO allows placeholders to not be prefixed by a colon. See + // http://marc.info/?l=php-internals&m=111234321827149&w=2 for + // more. + if ($placeholder[0] != ':') { + $placeholder = ":$placeholder"; + } // When replacing the placeholders, make sure we search for the // exact placeholder. For example, if searching for // ':db_placeholder_1', do not replace ':db_placeholder_11'. $query = preg_replace('/' . preg_quote($placeholder) . '\b/', $value, $query); - unset($args[$placeholder]); } } }