CI_DB_odbc_forge Class Reference

Inheritance diagram for CI_DB_odbc_forge:
Collaboration diagram for CI_DB_odbc_forge:

List of all members.


Public Member Functions

 _create_database ()
 Create database.
 _drop_database ($name)
 Drop database.
 _create_table ($table, $fields, $primary_keys, $keys, $if_not_exists)
 Create Table.
 _drop_table ($table)
 Drop 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.

Detailed Description

Definition at line 25 of file odbc_forge.php.


Member Function Documentation

CI_DB_odbc_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

Parameters:
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
Returns:
object

Definition at line 208 of file odbc_forge.php.

00209         {
00210                 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
00211 
00212                 // DROP has everything it needs now.
00213                 if ($alter_type == 'DROP')
00214                 {
00215                         return $sql;
00216                 }
00217 
00218                 $sql .= " $column_definition";
00219 
00220                 if ($default_value != '')
00221                 {
00222                         $sql .= " DEFAULT \"$default_value\"";
00223                 }
00224 
00225                 if ($null === NULL)
00226                 {
00227                         $sql .= ' NULL';
00228                 }
00229                 else
00230                 {
00231                         $sql .= ' NOT NULL';
00232                 }
00233 
00234                 if ($after_field != '')
00235                 {
00236                         $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
00237                 }
00238                 
00239                 return $sql;
00240                 
00241         }

CI_DB_odbc_forge::_create_database (  ) 

Create database.

private

Parameters:
string the database name
Returns:
bool

Definition at line 34 of file odbc_forge.php.

00035         {
00036                 // ODBC has no "create database" command since it's
00037                 // designed to connect to an existing database
00038                 if ($this->db->db_debug)
00039                 {
00040                         return $this->db->display_error('db_unsuported_feature');
00041                 }
00042                 return FALSE;
00043         }

CI_DB_odbc_forge::_create_table ( table,
fields,
primary_keys,
keys,
if_not_exists 
)

Create Table.

private

Parameters:
string the table name
array the fields
mixed primary key(s)
mixed key(s)
boolean should 'IF NOT EXISTS' be added to the SQL
Returns:
bool

Definition at line 78 of file odbc_forge.php.

References CI_DB_forge::$fields, CI_DB_forge::$keys, and CI_DB_forge::$primary_keys.

00079         {
00080                 $sql = 'CREATE TABLE ';
00081                 
00082                 if ($if_not_exists === TRUE)
00083                 {
00084                         $sql .= 'IF NOT EXISTS ';
00085                 }
00086                 
00087                 $sql .= $this->db->_escape_table($table)." (";
00088                 $current_field_count = 0;
00089 
00090                 foreach ($fields as $field=>$attributes)
00091                 {
00092                         // Numeric field names aren't allowed in databases, so if the key is
00093                         // numeric, we know it was assigned by PHP and the developer manually
00094                         // entered the field information, so we'll simply add it to the list
00095                         if (is_numeric($field))
00096                         {
00097                                 $sql .= "\n\t$attributes";
00098                         }
00099                         else
00100                         {
00101                                 $attributes = array_change_key_case($attributes, CASE_UPPER);
00102                                 
00103                                 $sql .= "\n\t".$this->db->_protect_identifiers($field);
00104                                 
00105                                 $sql .=  ' '.$attributes['TYPE'];
00106         
00107                                 if (array_key_exists('CONSTRAINT', $attributes))
00108                                 {
00109                                         $sql .= '('.$attributes['CONSTRAINT'].')';
00110                                 }
00111         
00112                                 if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
00113                                 {
00114                                         $sql .= ' UNSIGNED';
00115                                 }
00116         
00117                                 if (array_key_exists('DEFAULT', $attributes))
00118                                 {
00119                                         $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
00120                                 }
00121         
00122                                 if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
00123                                 {
00124                                         $sql .= ' NULL';
00125                                 }
00126                                 else
00127                                 {
00128                                         $sql .= ' NOT NULL';                    
00129                                 }
00130         
00131                                 if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
00132                                 {
00133                                         $sql .= ' AUTO_INCREMENT';
00134                                 }
00135                         }
00136                         
00137                         // don't add a comma on the end of the last field
00138                         if (++$current_field_count < count($fields))
00139                         {
00140                                 $sql .= ',';
00141                         }
00142                 }
00143 
00144                 if (count($primary_keys) > 0)
00145                 {
00146                         $primary_keys = $this->db->_protect_identifiers($primary_keys);
00147                         $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
00148                 }
00149                 
00150                 if (is_array($keys) && count($keys) > 0)
00151                 {
00152                         foreach ($keys as $key)
00153                         {
00154                                 if (is_array($key))
00155                                 {
00156                                         $key = $this->db->_protect_identifiers($key);   
00157                                 }
00158                                 else
00159                                 {
00160                                         $key = array($this->db->_protect_identifiers($key));
00161                                 }
00162                                 
00163                                 $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
00164                         }
00165                 }
00166                 
00167                 $sql .= "\n)";
00168 
00169                 return $sql;
00170         }

CI_DB_odbc_forge::_drop_database ( name  ) 

Drop database.

private

Parameters:
string the database name
Returns:
bool

Definition at line 54 of file odbc_forge.php.

00055         {
00056                 // ODBC has no "drop database" command since it's
00057                 // designed to connect to an existing database          
00058                 if ($this->db->db_debug)
00059                 {
00060                         return $this->db->display_error('db_unsuported_feature');
00061                 }
00062                 return FALSE;
00063         }

CI_DB_odbc_forge::_drop_table ( table  ) 

Drop Table.

private

Returns:
bool

Definition at line 180 of file odbc_forge.php.

00181         {
00182                 // Not a supported ODBC feature 
00183                 if ($this->db->db_debug)
00184                 {
00185                         return $this->db->display_error('db_unsuported_feature');
00186                 }
00187                 return FALSE;
00188         }

CI_DB_odbc_forge::_rename_table ( table_name,
new_table_name 
)

Rename a table.

Generates a platform-specific query so that a table can be renamed

private

Parameters:
string the old table name
string the new table name
Returns:
string

Definition at line 256 of file odbc_forge.php.

00257         {
00258                 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
00259                 return $sql;
00260         }


The documentation for this class was generated from the following file: