From 763e2875720bdc0cc5d621d550e0f9d1e536e8b4 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Wed, 28 Apr 2010 14:06:29 +1200 Subject: [PATCH] Handle escaping of ? for old broken PHP::PDO. --- inc/AwlDBDialect.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/inc/AwlDBDialect.php b/inc/AwlDBDialect.php index bbfdaa36..0f21701b 100644 --- a/inc/AwlDBDialect.php +++ b/inc/AwlDBDialect.php @@ -236,9 +236,21 @@ class AwlDBDialect { $rv = "'".str_replace("'", "''", str_replace('\\', '\\x5c', $value))."'"; if ( $this->dialect == 'pgsql' && strpos( $rv, '\\' ) !== false ) { - /** PostgreSQL wants to know when a string might contain escapes */ - $rv = 'E'.$rv; + /** + * PostgreSQL wants to know when a string might contain escapes, and if this + * happens old versions of PHP::PDO need the ? escaped as well... + */ + $rv = 'E'.str_replace('?', '\\x3f', $rv); } + + /** + * This code fails because on some (unspecified) occasions PHP sees a ':name@' and replaces it with $1!!! + $delimiter = '$$'; + while( strpos($value, $delimiter) !== false ) { + $delimiter = sprintf('$%d$'.rand(99999)); + } + $rv = $delimiter . $value . $delimiter; + */ } return $rv;