From 3dd68c8aadfcc5f701fd6d790f21c4ad475f8a42 Mon Sep 17 00:00:00 2001 From: Andrey Kolchenko Date: Wed, 24 May 2017 17:21:35 +0300 Subject: [PATCH] Fix parseQuery --- src/Che/DBAL/Vertica/ODBCStatement.php | 10 +++++---- tests/ODBCStatementTest.php | 29 +++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Che/DBAL/Vertica/ODBCStatement.php b/src/Che/DBAL/Vertica/ODBCStatement.php index aaacd0c..12e6177 100644 --- a/src/Che/DBAL/Vertica/ODBCStatement.php +++ b/src/Che/DBAL/Vertica/ODBCStatement.php @@ -325,16 +325,18 @@ protected function parseQuery($query) $counter = 1; return preg_replace_callback( - '/(?paramMap[] = $counter++; + + return $name; } else { $this->paramMap[] = substr($name, 1); - } - return '?'; + return '?'; + } }, $query ); diff --git a/tests/ODBCStatementTest.php b/tests/ODBCStatementTest.php index 7f64b04..8be6a88 100644 --- a/tests/ODBCStatementTest.php +++ b/tests/ODBCStatementTest.php @@ -26,11 +26,34 @@ public function testParseQuery() $object = $class->newInstanceWithoutConstructor(); $query = $method->invoke( $object, - 'SELECT :date, ? FROM log WHERE log.date = :date::DATE AND log.hour = :hour GROUP BY 1, ?, 3;' + <<<'SQL' +SELECT REGEXP_SUBSTR(s.url, '^(?:https?:)?//(?:www\.)?([^/]+)/', 1, 1, 'i', 1) +FROM s WHERE s.a IN(?,?, ? ,?) AND s.b IN(:a,:b, :c ,:d) AND s.e = ?; +SQL + ); + self::assertSame( + <<<'SQL' +SELECT REGEXP_SUBSTR(s.url, '^(?:https?:)?//(?:www\.)?([^/]+)/', 1, 1, 'i', 1) +FROM s WHERE s.a IN(?,?, ? ,?) AND s.b IN(?,?, ? ,?) AND s.e = ?; +SQL + , + $query ); - self::assertSame('SELECT ?, ? FROM log WHERE log.date = ?::DATE AND log.hour = ? GROUP BY 1, ?, 3;', $query); $map = $class->getProperty('paramMap'); $map->setAccessible(true); - self::assertSame(['date', 1, 'date', 'hour', 2], $map->getValue($object)); + self::assertSame( + [ + 0 => 1, + 1 => 2, + 2 => 3, + 3 => 4, + 4 => 'a', + 5 => 'b', + 6 => 'c', + 7 => 'd', + 8 => 5, + ], + $map->getValue($object) + ); } }