diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-06-07 21:08:35 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-06-07 21:08:35 +0200 |
commit | 928b9aa6340654b1dbb69af44c41468456f0b7b6 (patch) | |
tree | dcff391139cc5a11904c16fe2f50c71c752adc7d /system/database/drivers/mssql/mssql_forge.php | |
parent | df6aed2e6070b67ace6e52e621a4f14c2cf7578f (diff) | |
parent | c2c361b9c9dcfd94003d97622d74184f01c0615f (diff) |
Merge pull request #972 from narfbg/develop-db-mssql
Improve the MSSQL database driver
Diffstat (limited to 'system/database/drivers/mssql/mssql_forge.php')
-rw-r--r-- | system/database/drivers/mssql/mssql_forge.php | 53 |
1 files changed, 15 insertions, 38 deletions
diff --git a/system/database/drivers/mssql/mssql_forge.php b/system/database/drivers/mssql/mssql_forge.php index e6227e189..d2a30b20f 100644 --- a/system/database/drivers/mssql/mssql_forge.php +++ b/system/database/drivers/mssql/mssql_forge.php @@ -75,26 +75,20 @@ class CI_DB_mssql_forge extends CI_DB_forge { $sql .= '('.$attributes['CONSTRAINT'].')'; } - if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) + if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) { $sql .= ' UNSIGNED'; } - if (array_key_exists('DEFAULT', $attributes)) + if (isset($attributes['DEFAULT'])) { - $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; + $sql .= " DEFAULT '".$attributes['DEFAULT']."'"; } - if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } + $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) + ? ' NULL' : ' NOT NULL'; - if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) { $sql .= ' AUTO_INCREMENT'; } @@ -109,22 +103,16 @@ class CI_DB_mssql_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->db->escape_identifiers($primary_keys)).')'; } if (is_array($keys) && count($keys) > 0) { foreach ($keys as $key) { - if (is_array($key)) - { - $key = $this->db->protect_identifiers($key); - } - else - { - $key = array($this->db->protect_identifiers($key)); - } + $key = is_array($key) + ? $this->db->escape_identifiers($key) + : array($this->db->escape_identifiers($key)); $sql .= ",\n\tFOREIGN KEY (".implode(', ', $key).')'; } @@ -152,7 +140,7 @@ class CI_DB_mssql_forge extends CI_DB_forge { */ protected 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->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name); // DROP has everything it needs now. if ($alter_type === 'DROP') @@ -160,21 +148,10 @@ class CI_DB_mssql_forge extends CI_DB_forge { return $sql; } - $sql .= " ".$column_definition; - - if ($default_value !== '') - { - $sql .= " DEFAULT '".$default_value."'"; - } - - $sql .= ($null === NULL) ? ' NULL' : ' NOT NULL'; - - if ($after_field !== '') - { - return $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) : ''); } } |