

Public Member Functions | |
| _create_database ($name) | |
| Create database. | |
| _drop_database ($name) | |
| Drop database. | |
| _drop_table ($table) | |
| Drop Table. | |
| _create_table ($table, $fields, $primary_keys, $keys, $if_not_exists) | |
| Create Table. | |
| _alter_table ($alter_type, $table, $column_name, $column_definition= '', $default_value= '', $null= '', $after_field= '') | |
| Alter table query. | |
| _rename_table ($table_name, $new_table_name) | |
| Rename a table. | |
Definition at line 25 of file mssql_forge.php.
| CI_DB_mssql_forge::_alter_table | ( | $ | alter_type, | |
| $ | table, | |||
| $ | column_name, | |||
| $ | column_definition = '', |
|||
| $ | default_value = '', |
|||
| $ | null = '', |
|||
| $ | after_field = '' | |||
| ) |
Alter table query.
Generates a platform-specific query so that a table can be altered Called by add_column(), drop_column(), and column_alter(),
private
| string | the ALTER type (ADD, DROP, CHANGE) | |
| string | the column name | |
| string | the table name | |
| string | the column definition | |
| string | the default value | |
| boolean | should 'NOT NULL' be added | |
| string | the field after which we should add the new field |
Definition at line 191 of file mssql_forge.php.
00192 { 00193 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); 00194 00195 // DROP has everything it needs now. 00196 if ($alter_type == 'DROP') 00197 { 00198 return $sql; 00199 } 00200 00201 $sql .= " $column_definition"; 00202 00203 if ($default_value != '') 00204 { 00205 $sql .= " DEFAULT \"$default_value\""; 00206 } 00207 00208 if ($null === NULL) 00209 { 00210 $sql .= ' NULL'; 00211 } 00212 else 00213 { 00214 $sql .= ' NOT NULL'; 00215 } 00216 00217 if ($after_field != '') 00218 { 00219 $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); 00220 } 00221 00222 return $sql; 00223 00224 }
| CI_DB_mssql_forge::_create_database | ( | $ | name | ) |
Create database.
private
| string | the database name |
Definition at line 34 of file mssql_forge.php.
| CI_DB_mssql_forge::_create_table | ( | $ | table, | |
| $ | fields, | |||
| $ | primary_keys, | |||
| $ | keys, | |||
| $ | if_not_exists | |||
| ) |
Create Table.
private
| string | the table name | |
| array | the fields | |
| mixed | primary key(s) | |
| mixed | key(s) | |
| boolean | should 'IF NOT EXISTS' be added to the SQL |
Definition at line 79 of file mssql_forge.php.
References CI_DB_forge::$fields, CI_DB_forge::$keys, and CI_DB_forge::$primary_keys.
00080 { 00081 $sql = 'CREATE TABLE '; 00082 00083 if ($if_not_exists === TRUE) 00084 { 00085 $sql .= 'IF NOT EXISTS '; 00086 } 00087 00088 $sql .= $this->db->_escape_table($table)." ("; 00089 $current_field_count = 0; 00090 00091 foreach ($fields as $field=>$attributes) 00092 { 00093 // Numeric field names aren't allowed in databases, so if the key is 00094 // numeric, we know it was assigned by PHP and the developer manually 00095 // entered the field information, so we'll simply add it to the list 00096 if (is_numeric($field)) 00097 { 00098 $sql .= "\n\t$attributes"; 00099 } 00100 else 00101 { 00102 $attributes = array_change_key_case($attributes, CASE_UPPER); 00103 00104 $sql .= "\n\t".$this->db->_protect_identifiers($field); 00105 00106 $sql .= ' '.$attributes['TYPE']; 00107 00108 if (array_key_exists('CONSTRAINT', $attributes)) 00109 { 00110 $sql .= '('.$attributes['CONSTRAINT'].')'; 00111 } 00112 00113 if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) 00114 { 00115 $sql .= ' UNSIGNED'; 00116 } 00117 00118 if (array_key_exists('DEFAULT', $attributes)) 00119 { 00120 $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; 00121 } 00122 00123 if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) 00124 { 00125 $sql .= ' NULL'; 00126 } 00127 else 00128 { 00129 $sql .= ' NOT NULL'; 00130 } 00131 00132 if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) 00133 { 00134 $sql .= ' AUTO_INCREMENT'; 00135 } 00136 } 00137 00138 // don't add a comma on the end of the last field 00139 if (++$current_field_count < count($fields)) 00140 { 00141 $sql .= ','; 00142 } 00143 } 00144 00145 if (count($primary_keys) > 0) 00146 { 00147 $primary_keys = $this->db->_protect_identifiers($primary_keys); 00148 $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; 00149 } 00150 00151 if (is_array($keys) && count($keys) > 0) 00152 { 00153 foreach ($keys as $key) 00154 { 00155 if (is_array($key)) 00156 { 00157 $key = $this->db->_protect_identifiers($key); 00158 } 00159 else 00160 { 00161 $key = array($this->db->_protect_identifiers($key)); 00162 } 00163 00164 $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")"; 00165 } 00166 } 00167 00168 $sql .= "\n)"; 00169 00170 return $sql; 00171 }
| CI_DB_mssql_forge::_drop_database | ( | $ | name | ) |
Drop database.
private
| string | the database name |
Definition at line 48 of file mssql_forge.php.
| CI_DB_mssql_forge::_drop_table | ( | $ | table | ) |
| CI_DB_mssql_forge::_rename_table | ( | $ | table_name, | |
| $ | new_table_name | |||
| ) |
Rename a table.
Generates a platform-specific query so that a table can be renamed
private
| string | the old table name | |
| string | the new table name |
Definition at line 238 of file mssql_forge.php.
00239 { 00240 // I think this syntax will work, but can find little documentation on renaming tables in MSSQL 00241 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); 00242 return $sql; 00243 }