From 5ef194df98294d5427c0e7582ca88b1fc06e1d72 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 8 Jun 2012 01:12:54 +0300 Subject: Resolve formatting differences between DB forge drivers --- system/database/drivers/sqlite3/sqlite3_forge.php | 43 ++++++++++++++--------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'system/database/drivers/sqlite3/sqlite3_forge.php') diff --git a/system/database/drivers/sqlite3/sqlite3_forge.php b/system/database/drivers/sqlite3/sqlite3_forge.php index 0a5dc9211..6df361444 100644 --- a/system/database/drivers/sqlite3/sqlite3_forge.php +++ b/system/database/drivers/sqlite3/sqlite3_forge.php @@ -111,13 +111,27 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { { $attributes = array_change_key_case($attributes, CASE_UPPER); - $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']) ? ' DEFAULT \''.$attributes['DEFAULT'].'\'' : '') - .(( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL') - .(( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) ? ' AUTO_INCREMENT' : ''); + $sql .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE']; + + empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')'; + + if ( ! empty($attributes['UNSIGNED']) && $attributes['UNSIGNED'] === TRUE) + { + $sql .= ' UNSIGNED'; + } + + if (isset($attributes['DEFAULT'])) + { + $sql .= " DEFAULT '".$attributes['DEFAULT']."'"; + } + + $sql .= ( ! empty($attributes['NULL']) && $attributes['NULL'] === TRUE) + ? ' NULL' : ' NOT NULL'; + + if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE) + { + $sql .= ' AUTO_INCREMENT'; + } } // don't add a comma on the end of the last field @@ -129,7 +143,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { if (count($primary_keys) > 0) { - $primary_keys = $this->db->protect_identifiers($primary_keys); + $primary_keys = $this->db->escape_identifiers($primary_keys); $sql .= ",\n\tPRIMARY KEY (".implode(', ', $primary_keys).')'; } @@ -137,14 +151,9 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { { 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\tUNIQUE (".implode(', ', $key).')'; } @@ -182,7 +191,7 @@ class CI_DB_sqlite3_forge extends CI_DB_forge { return FALSE; } - return 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name) + return 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name) .' '.$column_definition .($default_value !== '' ? ' DEFAULT '.$default_value : '') // If NOT NULL is specified, the field must have a DEFAULT value other than NULL -- cgit v1.2.3-24-g4f1b