From 19311361d52413746327b590e3ef51e4d718fd82 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Apr 2015 00:02:14 +0300 Subject: Move strtolower() call from PR #3739 out of the loop --- system/database/DB_query_builder.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index a77ed57d0..5005d0163 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -918,6 +918,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver { } is_bool($escape) OR $escape = $this->_protect_identifiers; + // lowercase $side in case somebody writes e.g. 'BEFORE' instead of 'before' (doh) + $side = strtolower($side); foreach ($field as $k => $v) { @@ -925,9 +927,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { ? $this->_group_get_type('') : $this->_group_get_type($type); $v = $this->escape_like_str($v); - - // lowercase $side for in case of UPPERCASE string - $side = strtolower($side); if ($side === 'none') { -- cgit v1.2.3-24-g4f1b From 1924eb37cc5488be7560a8a754663bba6a47a5e4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Apr 2015 17:19:24 +0300 Subject: [ci skip] Fix comment typos https://github.com/bcit-ci/CodeIgniter/pull/3748#issuecomment-90925762 --- system/database/DB_query_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 5005d0163..8251f4558 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2255,7 +2255,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { else { // Cycle through the "select" portion of the query and prep each column name. - // The reason we protect identifiers here rather then in the select() function + // The reason we protect identifiers here rather than in the select() function // is because until the user calls the from() function we don't know if there are aliases foreach ($this->qb_select as $key => $val) { -- cgit v1.2.3-24-g4f1b From 8af87468487101e14e69effb80a166870f1b79be Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 14 Apr 2015 15:59:54 +0300 Subject: Fix #3773 --- .../drivers/pdo/subdrivers/pdo_mysql_driver.php | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'system/database') diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php index 67dc5f5ec..206d83595 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -156,6 +156,30 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- + /** + * Select the database + * + * @param string $database + * @return bool + */ + public function db_select($database = '') + { + if ($database === '') + { + $database = $this->database; + } + + if (FALSE !== $this->simple_query('USE '.$this->escape_identifiers($database))) + { + $this->database = $database; + return TRUE; + } + + return FALSE; + } + + // -------------------------------------------------------------------- + /** * Show table query * -- cgit v1.2.3-24-g4f1b From 0f8509025d2338dc069ddf42b6ade974a5da0ca3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 29 Apr 2015 12:33:11 +0300 Subject: Add list_fields() support for SQLite3 --- system/database/DB_driver.php | 2 +- .../drivers/pdo/subdrivers/pdo_sqlite_driver.php | 30 ++++++++++++++++------ system/database/drivers/sqlite3/sqlite3_driver.php | 30 ++++++++++++++++------ 3 files changed, 45 insertions(+), 17 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 3d35c2d70..64ee880c8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1218,7 +1218,7 @@ abstract class CI_DB_driver { /** * Fetch Field Names * - * @param string the table name + * @param string $table Table name * @return array */ public function list_fields($table) diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php index f07f49f84..d5ca741fd 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlite_driver.php @@ -121,17 +121,31 @@ class CI_DB_pdo_sqlite_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- /** - * Show column query + * Fetch Field Names * - * Generates a platform-specific query string so that the column names can be fetched - * - * @param string $table - * @return string + * @param string $table Table name + * @return array */ - protected function _list_columns($table = '') + public function list_fields($table) { - // Not supported - return FALSE; + // 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(); + foreach ($result as $row) + { + $this->data_cache['field_names'][$table][] = $row['name']; + } + + return $this->data_cache['field_names'][$table]; } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index fdbe94939..a7c6420bb 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -247,17 +247,31 @@ class CI_DB_sqlite3_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Show column query + * Fetch Field Names * - * Generates a platform-specific query string so that the column names can be fetched - * - * @param string $table - * @return string + * @param string $table Table name + * @return array */ - protected function _list_columns($table = '') + public function list_fields($table) { - // Not supported - return FALSE; + // 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(); + foreach ($result as $row) + { + $this->data_cache['field_names'][$table][] = $row['name']; + } + + return $this->data_cache['field_names'][$table]; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4c08ea9c69aeb4acc1fbe47e873a11e82a6d5b79 Mon Sep 17 00:00:00 2001 From: Leandro Mangini Antunes Date: Wed, 13 May 2015 11:15:01 -0300 Subject: Fixed bug - using field_data() on Oracle databases When you're using oracle databases and want to retrieve column information through the function field_data($table) you get the following notice: - Notice: Undefined property: stdClass::$COLUMN_DEFAULT in system/database/drivers/oci8/oci8_driver.php on line 576; This happens because the oci8 driver tries to access a property that does not exist on query used to get field information. Checking the code we see a small validation to set default value, but the variable $default is not used. So we fix this bug by simply changing: $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; to $retval[$i]->default = $default; Bug fixed. No more notices and the properly value is set. --- system/database/drivers/oci8/oci8_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database') diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 4010995a1..b5cf26536 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -573,7 +573,7 @@ class CI_DB_oci8_driver extends CI_DB { { $default = ''; } - $retval[$i]->default = $query[$i]->COLUMN_DEFAULT; + $retval[$i]->default = $default; } return $retval; -- cgit v1.2.3-24-g4f1b