From ad4882fef8cdfb5d1795898de34440b001527d37 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 16 Sep 2015 11:29:50 +0300 Subject: Fix #4120 --- system/database/drivers/mssql/mssql_driver.php | 16 +++++++++++++--- user_guide_src/source/changelog.rst | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 8f15d8d69..05e5418c3 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -381,9 +381,19 @@ class CI_DB_mssql_driver extends CI_DB { */ public function error() { - $query = $this->query('SELECT @@ERROR AS code'); - $query = $query->row(); - return array('code' => $query->code, 'message' => mssql_get_last_message()); + // We need this because the error info is discarded by the + // server the first time you request it, and query() already + // calls error() once for logging purposes when a query fails. + static $error = array('code' => 0, 'message' => NULL); + + $message = mssql_get_last_message(); + if ( ! empty($message)) + { + $error['code'] = $this->query('SELECT @@ERROR AS code')->row()->code; + $error['message'] = $message; + } + + return $error; } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index e4250a4e6..31e0b3179 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -30,6 +30,7 @@ Bug fixes for 3.0.2 - Fixed a bug (#4105) - :doc:`Form Validation Library ` didn't allow pipe characters inside "bracket parameters" when using a string ruleset. - Fixed a bug (#4109) - :doc:`Routing ` to *default_controller* didn't work when *enable_query_strings* is set to TRUE. - Fixed a bug (#4044) - :doc:`Cache Library ` 'redis' driver didn't catch ``RedisException`` that could be thrown during authentication. +- Fixed a bug (#4120) - :doc:`Database ` method ``error()`` didn't return error info when called after ``query()`` with the 'mssql' driver. Version 3.0.1 ============= -- cgit v1.2.3-24-g4f1b