From 0ca9ae6ca109177eb0e80456b097a9d63412517e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 6 Jan 2016 14:51:27 +0200 Subject: Fix #4337 --- system/database/drivers/odbc/odbc_driver.php | 18 ++++++++++++++++++ .../drivers/pdo/subdrivers/pdo_odbc_driver.php | 18 ++++++++++++++++++ .../drivers/pdo/subdrivers/pdo_pgsql_driver.php | 7 ++++++- system/database/drivers/postgre/postgre_driver.php | 7 ++++++- user_guide_src/source/changelog.rst | 3 ++- 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 409284b44..e12ad53bc 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -188,6 +188,24 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); + } + + // -------------------------------------------------------------------- + /** * Platform-dependant string escape * diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php index 51c70b630..4df2de8ba 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php @@ -160,6 +160,24 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- + /** + * Determines if a query is a "write" type. + * + * @param string An SQL query string + * @return bool + */ + public function is_write_type($sql) + { + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); + } + + // -------------------------------------------------------------------- + /** * Show table query * diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php index 2dd41ca87..79c3c7be0 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php @@ -154,7 +154,12 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { */ public function is_write_type($sql) { - return (bool) preg_match('/^\s*"?(SET|INSERT(?![^\)]+\)\s+RETURNING)|UPDATE(?!.*\sRETURNING)|DELETE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s/i', str_replace(array("\r\n", "\r", "\n"), ' ', $sql)); + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index b1df326f7..a7a02496b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -288,7 +288,12 @@ class CI_DB_postgre_driver extends CI_DB { */ public function is_write_type($sql) { - return (bool) preg_match('/^\s*"?(SET|INSERT(?![^\)]+\)\s+RETURNING)|UPDATE(?!.*\sRETURNING)|DELETE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s/i', str_replace(array("\r\n", "\r", "\n"), ' ', $sql)); + if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql)) + { + return FALSE; + } + + return parent::is_write_type($sql); } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index c189767d8..2ac5213ba 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -19,7 +19,7 @@ Bug fixes for 3.0.4 - Fixed a bug where :doc:`Form Helper ` functions :php:func:`set_checkbox()`, :php:func:`set_radio()` didn't "uncheck" inputs on a submitted form if the default state is "checked". - Fixed a bug (#4217) - :doc:`Config Library ` method ``base_url()`` didn't use proper formatting for IPv6 when it falls back to ``$_SERVER['SERVER_ADDR']``. - Fixed a bug where :doc:`CAPTCHA Helper ` entered an infinite loop while generating a random string. -- Fixed a bug (#4223) - :doc:`Database ` method ``simple_query()`` blindly executes queries without checking if the connection was initialized properly. +- Fixed a bug (#4223) - :doc:`Database ` method ``simple_query()`` blindly executes queries without checking if the connection was initialized properly. - Fixed a bug (#4244) - :doc:`Email Library ` could improperly use "unsafe" US-ASCII characters during Quoted-printable encoding. - Fixed a bug (#4245) - :doc:`Database Forge ` couldn't properly handle ``SET`` and ``ENUM`` type fields with string values. - Fixed a bug (#4283) - :doc:`String Helper ` function :php:func:`alternator()` couldn't be called without arguments. @@ -31,6 +31,7 @@ Bug fixes for 3.0.4 - Fixed a bug (#4331) - :doc:`Database ` method ``error()`` didn't really work for connection errors with the 'mysqli' driver. - Fixed a bug (#4343) - :doc:`Email Library ` failing with a *"More than one 'from' person"* message when using *sendmail*. - Fixed a bug (#4350) - :doc:`Loader Library ` method ``model()`` logic directly instantiated the ``CI_Model`` or ``MY_Model`` classes. +- Fixed a bug (#4337) - :doc:`Database ` method ``query()`` didn't return a result set for queries with the ``RETURNING`` statement on PostgreSQL. Version 3.0.3 ============= -- cgit v1.2.3-24-g4f1b