From da5cf99321daee9500518f63fcd58e0c57f7d53e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 16 Nov 2018 16:01:34 +0200 Subject: [ci skip] Fix #5624 --- system/database/DB_driver.php | 12 +++--------- system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php | 12 +++--------- system/database/drivers/sqlite3/sqlite3_driver.php | 12 +++--------- user_guide_src/source/changelog.rst | 1 + 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index f8956f069..c397bb723 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1308,19 +1308,13 @@ abstract class CI_DB_driver { */ public function list_fields($table) { - // Is there a cached result? - if (isset($this->data_cache['field_names'][$table])) - { - return $this->data_cache['field_names'][$table]; - } - if (FALSE === ($sql = $this->_list_columns($table))) { return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; } $query = $this->query($sql); - $this->data_cache['field_names'][$table] = array(); + $fields = array(); foreach ($query->result_array() as $row) { @@ -1342,10 +1336,10 @@ abstract class CI_DB_driver { } } - $this->data_cache['field_names'][$table][] = $row[$key]; + $fields[] = $row[$key]; } - return $this->data_cache['field_names'][$table]; + return $fields; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php index 93871a99b..3602c282c 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php @@ -128,24 +128,18 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver { */ public function list_fields($table) { - // Is there a cached result? - if (isset($this->data_cache['field_names'][$table])) - { - return $this->data_cache['field_names'][$table]; - } - if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) { return FALSE; } - $this->data_cache['field_names'][$table] = array(); + $fields = array(); foreach ($result->result_array() as $row) { - $this->data_cache['field_names'][$table][] = $row['name']; + $fields[] = $row['name']; } - return $this->data_cache['field_names'][$table]; + return $fields; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index 41d9d484f..b6deccf68 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -230,24 +230,18 @@ class CI_DB_sqlite3_driver extends CI_DB { */ public function list_fields($table) { - // Is there a cached result? - if (isset($this->data_cache['field_names'][$table])) - { - return $this->data_cache['field_names'][$table]; - } - if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE) { return FALSE; } - $this->data_cache['field_names'][$table] = array(); + $fields = array(); foreach ($result->result_array() as $row) { - $this->data_cache['field_names'][$table][] = $row['name']; + $fields[] = $row['name']; } - return $this->data_cache['field_names'][$table]; + return $fields; } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 5e729828b..dc078810b 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -19,6 +19,7 @@ Bug fixes for 3.1.10 - Fixed a bug (#5571) - :doc:`XML-RPC Library ` had a typo that triggered an ``E_WARNING`` message on PHP 7.2. - Fixed a bug (#5587) - :doc:`Database Forge ` method ``create_table()`` generated an ``E_WARNING`` message. - Fixed a bug (#5590) - :doc:`Form Validation Library ` rule **valid_base64** didn't have a default error message. +- Fixed a bug (#5624) - :doc:`Database Library ` methods ``list_fields()``, ``field_exists()`` returned incorrect results after tables are modified. Version 3.1.9 ============= -- cgit v1.2.3-24-g4f1b