From b76029d8be1f2d98f1668d61e7f7ac3d9274b8f3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 26 Jan 2012 15:13:19 +0200 Subject: Improve the ODBC database driver --- system/database/drivers/odbc/odbc_forge.php | 143 +++++++--------------------- 1 file changed, 37 insertions(+), 106 deletions(-) (limited to 'system/database/drivers/odbc/odbc_forge.php') diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index e0ec687c8..49e5c3e72 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -1,13 +1,13 @@ -db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; + return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE; } // -------------------------------------------------------------------- @@ -59,19 +52,14 @@ class CI_DB_odbc_forge extends CI_DB_forge { /** * Drop database * - * @access private * @param string the database name * @return bool */ - function _drop_database($name) + public function _drop_database($name) { // ODBC has no "drop database" command since it's // designed to connect to an existing database - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; + return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE; } // -------------------------------------------------------------------- @@ -79,7 +67,6 @@ class CI_DB_odbc_forge extends CI_DB_forge { /** * Create Table * - * @access private * @param string the table name * @param array the fields * @param mixed primary key(s) @@ -87,7 +74,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { * @param boolean should 'IF NOT EXISTS' be added to the SQL * @return bool */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) { $sql = 'CREATE TABLE '; @@ -96,54 +83,29 @@ class CI_DB_odbc_forge extends CI_DB_forge { $sql .= 'IF NOT EXISTS '; } - $sql .= $this->db->_escape_identifiers($table)." ("; + $sql .= $this->db->_escape_identifiers($table).' ('; $current_field_count = 0; - foreach ($fields as $field=>$attributes) + foreach ($fields as $field => $attributes) { // Numeric field names aren't allowed in databases, so if the key is // numeric, we know it was assigned by PHP and the developer manually // entered the field information, so we'll simply add it to the list if (is_numeric($field)) { - $sql .= "\n\t$attributes"; + $sql .= "\n\t".$attributes; } else { $attributes = array_change_key_case($attributes, CASE_UPPER); - $sql .= "\n\t".$this->db->_protect_identifiers($field); - - $sql .= ' '.$attributes['TYPE']; - - if (array_key_exists('CONSTRAINT', $attributes)) - { - $sql .= '('.$attributes['CONSTRAINT'].')'; - } - - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) - { - $sql .= ' UNSIGNED'; - } - - if (array_key_exists('DEFAULT', $attributes)) - { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; - } - - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) - { - $sql .= ' AUTO_INCREMENT'; - } + $sql .= "\n\t".$this->db->protect_identifiers($field) + .' '.$attributes['TYPE'] + .( ! empty($attributes['CONSTRAINT']) ? '('.$attributes['CONSTRAINT'].')' : '') + .(( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') + .(isset($attributes['DEFAULT'], $attributes) ? " DEFAULT '".$attributes['DEFAULT']."'" : '') + .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') + .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : ''); } // don't add a comma on the end of the last field @@ -155,8 +117,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $primary_keys = $this->db->_protect_identifiers($primary_keys); - $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; + $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->protect_identifiers($primary_keys)).')'; } if (is_array($keys) && count($keys) > 0) @@ -165,20 +126,18 @@ class CI_DB_odbc_forge extends CI_DB_forge { { if (is_array($key)) { - $key = $this->db->_protect_identifiers($key); + $key = $this->db->protect_identifiers($key); } else { - $key = array($this->db->_protect_identifiers($key)); + $key = array($this->db->protect_identifiers($key)); } - $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; + $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')'; } } - $sql .= "\n)"; - - return $sql; + return $sql."\n)"; } // -------------------------------------------------------------------- @@ -186,17 +145,12 @@ class CI_DB_odbc_forge extends CI_DB_forge { /** * Drop Table * - * @access private * @return bool */ - function _drop_table($table) + public function _drop_table($table) { // Not a supported ODBC feature - if ($this->db->db_debug) - { - return $this->db->display_error('db_unsuported_feature'); - } - return FALSE; + return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE; } // -------------------------------------------------------------------- @@ -207,49 +161,29 @@ class CI_DB_odbc_forge extends CI_DB_forge { * Generates a platform-specific query so that a table can be altered * Called by add_column(), drop_column(), and column_alter(), * - * @access private * @param string the ALTER type (ADD, DROP, CHANGE) * @param string the column name * @param string the table name * @param string the column definition * @param string the default value - * @param boolean should 'NOT NULL' be added + * @param bool should 'NOT NULL' be added * @param string the field after which we should add the new field - * @return object + * @return string */ - function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') + public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); + $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name); // DROP has everything it needs now. - if ($alter_type == 'DROP') + if ($alter_type === 'DROP') { return $sql; } - $sql .= " $column_definition"; - - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } - - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - + return $sql.' '.$column_definition + .($default_value != '' ? ' DEFAULT "'.$default_value.'"' : '') + .($null === NULL ? ' NULL' : ' NOT NULL') + .($after_field != '' ? ' AFTER '.$this->db->protect_identifiers($after_field) : ''); } @@ -260,19 +194,16 @@ class CI_DB_odbc_forge extends CI_DB_forge { * * Generates a platform-specific query so that a table can be renamed * - * @access private * @param string the old table name * @param string the new table name * @return string */ - function _rename_table($table_name, $new_table_name) + public function _rename_table($table_name, $new_table_name) { - $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); - return $sql; + return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name); } - } /* End of file odbc_forge.php */ -/* Location: ./system/database/drivers/odbc/odbc_forge.php */ \ No newline at end of file +/* Location: ./system/database/drivers/odbc/odbc_forge.php */ -- cgit v1.2.3-24-g4f1b From 19aee036c7b9ebc8919dd4d076dfd60fd50bd26f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Mar 2012 15:31:42 +0200 Subject: Remove EOF newlines --- system/database/drivers/odbc/odbc_forge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/database/drivers/odbc/odbc_forge.php') diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 162cef48c..26ff9a0fb 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -206,4 +206,4 @@ class CI_DB_odbc_forge extends CI_DB_forge { } /* End of file odbc_forge.php */ -/* Location: ./system/database/drivers/odbc/odbc_forge.php */ +/* Location: ./system/database/drivers/odbc/odbc_forge.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 48a2baf0e288accd206f5da5031d29076e130792 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:09:54 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/database --- system/database/drivers/odbc/odbc_forge.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/database/drivers/odbc/odbc_forge.php') diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index d59b8a911..ce7a1d2ef 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -163,14 +163,14 @@ class CI_DB_odbc_forge extends CI_DB_forge { $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name); // DROP has everything it needs now. - if ($alter_type == 'DROP') + if ($alter_type === 'DROP') { return $sql; } $sql .= " $column_definition"; - if ($default_value != '') + if ($default_value !== '') { $sql .= " DEFAULT \"$default_value\""; } @@ -184,7 +184,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { $sql .= ' NOT NULL'; } - if ($after_field != '') + if ($after_field !== '') { return $sql.' AFTER '.$this->db->protect_identifiers($after_field); } -- cgit v1.2.3-24-g4f1b From caa04f15096590261093dff2a8b59f266a1dcaf5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Jun 2012 01:39:20 +0300 Subject: Revert back some escape_identifiers() to proect_identifiers() as the first one can't handle arrays --- system/database/drivers/odbc/odbc_forge.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/odbc/odbc_forge.php') diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index b074c5884..5c0b200eb 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -104,7 +104,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->escape_identifiers($primary_keys)).')'; + $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->protect_identifiers($primary_keys)).')'; } if (is_array($keys) && count($keys) > 0) @@ -112,7 +112,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { foreach ($keys as $key) { $key = is_array($key) - ? $this->db->escape_identifiers($key) + ? $this->db->protect_identifiers($key) : array($this->db->escape_identifiers($key)); $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')'; -- cgit v1.2.3-24-g4f1b From 9637b40ca9e9ac1cdce2b895d3db09848a6eef76 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Jun 2012 15:39:24 +0300 Subject: escape_identifiers() to accept arrays as well --- system/database/drivers/odbc/odbc_forge.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/database/drivers/odbc/odbc_forge.php') diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index 5c0b200eb..b074c5884 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -104,7 +104,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->protect_identifiers($primary_keys)).')'; + $sql .= ",\n\tPRIMARY KEY (".implode(', ', $this->escape_identifiers($primary_keys)).')'; } if (is_array($keys) && count($keys) > 0) @@ -112,7 +112,7 @@ class CI_DB_odbc_forge extends CI_DB_forge { foreach ($keys as $key) { $key = is_array($key) - ? $this->db->protect_identifiers($key) + ? $this->db->escape_identifiers($key) : array($this->db->escape_identifiers($key)); $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')'; -- cgit v1.2.3-24-g4f1b From d73d6a88eb6ad34c82dd72026233093907499bfa Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Jul 2012 11:49:13 +0300 Subject: Remove _drop_database property from CI_DB_odbc_forge and CI_DB_pdo_forge (it has the same default in CI_DB_forge) --- system/database/drivers/odbc/odbc_forge.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/database/drivers/odbc/odbc_forge.php') diff --git a/system/database/drivers/odbc/odbc_forge.php b/system/database/drivers/odbc/odbc_forge.php index b074c5884..d17b046ee 100644 --- a/system/database/drivers/odbc/odbc_forge.php +++ b/system/database/drivers/odbc/odbc_forge.php @@ -34,7 +34,6 @@ */ class CI_DB_odbc_forge extends CI_DB_forge { - protected $_drop_database = 'DROP DATABASE %s'; protected $_drop_table = 'DROP TABLE %s'; /** -- cgit v1.2.3-24-g4f1b