summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/interbase/interbase_forge.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/drivers/interbase/interbase_forge.php')
-rw-r--r--system/database/drivers/interbase/interbase_forge.php141
1 files changed, 42 insertions, 99 deletions
diff --git a/system/database/drivers/interbase/interbase_forge.php b/system/database/drivers/interbase/interbase_forge.php
index f46043569..3f9967f1f 100644
--- a/system/database/drivers/interbase/interbase_forge.php
+++ b/system/database/drivers/interbase/interbase_forge.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Interbase/Firebird Forge Class
*
@@ -36,18 +34,22 @@
*/
class CI_DB_interbase_forge extends CI_DB_forge {
+ protected $_drop_table = 'DROP TABLE %s';
+
/**
* Create database
*
* @param string the database name
* @return string
*/
- protected function _create_database($filename='')
+ public function create_database($db_name)
{
- // Firebird databases are flat files, so a path is required
+ // Firebird databases are flat files, so a path is required
+
// Hostname is needed for remote access
- return 'CREATE DATABASE "'.$this->hostname.':'.$filename.'"';
-
+ empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name;
+
+ return parent::create_database('"'.$db_name.'"');
}
// --------------------------------------------------------------------
@@ -55,14 +57,20 @@ class CI_DB_interbase_forge extends CI_DB_forge {
/**
* Drop database
*
- * @param string the database name - not used in this driver
- * - the current db is dropped
+ * @param string the database name
+ * - not used in this driver, the current db is dropped
* @return bool
*/
- protected function _drop_database($name='')
+ public function drop_database($db_name = '')
{
- return ibase_drop_db($this->conn_id);
+ if ( ! ibase_drop_db($this->conn_id))
+ {
+ return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
+ }
+
+ return TRUE;
}
+
// --------------------------------------------------------------------
/**
@@ -72,14 +80,14 @@ class CI_DB_interbase_forge extends CI_DB_forge {
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
- * @param boolean should 'IF NOT EXISTS' be added to the SQL
+ * @param bool should 'IF NOT EXISTS' be added to the SQL
* @return string
*/
protected function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
- $sql .= $this->db->protect_identifiers($table)."(";
+ $sql .= $this->db->escape_identifiers($table).'(';
$current_field_count = 0;
foreach ($fields as $field => $attributes)
@@ -89,41 +97,30 @@ class CI_DB_interbase_forge extends CI_DB_forge {
// 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 .= "\n\t".$this->db->escape_identifiers($field).' '.$attributes['TYPE'];
- $sql .= ' '.$attributes['TYPE'];
+ empty($attributes['CONSTRAINT']) OR $sql .= '('.$attributes['CONSTRAINT'].')';
- if (array_key_exists('CONSTRAINT', $attributes))
- {
- $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';
}
@@ -138,42 +135,23 @@ class CI_DB_interbase_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) . ")";
+ $primary_keys = $this->db->escape_identifiers($primary_keys);
+ $sql .= ",\n\tPRIMARY KEY (".implode(', ', $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\tUNIQUE (" . implode(', ', $key) . ")";
+ $sql .= ",\n\tUNIQUE (".implode(', ', $key).')';
}
}
- $sql .= "\n)";
-
- return $sql;
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Drop Table
- *
- * @return string
- */
- protected function _drop_table($table)
- {
- return 'DROP TABLE '.$name;
+ return $sql."\n)";
}
// --------------------------------------------------------------------
@@ -189,54 +167,19 @@ class CI_DB_interbase_forge extends CI_DB_forge {
* @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 string
*/
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 .= " {$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 'ALTER TABLE '.$this->db->escape_identifiers($table).' '.$alter_type.' '.$this->db->escape_identifiers($column_name)
+ .' '.$column_definition
+ .($default_value !== '' ? ' DEFAULT "'.$default_value.'"' : '')
+ .($null === NULL ? ' NULL' : ' NOT NULL')
+ .($after_field !== '' ? ' AFTER '.$this->db->escape_identifiers($after_field) : '');
}
- // --------------------------------------------------------------------
-
- /**
- * Rename a table
- *
- * Generates a platform-specific query so that a table can be renamed
- *
- * @param string the old table name
- * @param string the new table name
- * @return string
- */
- protected function _rename_table($table_name, $new_table_name)
- {
- return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
- }
}
/* End of file interbase_forge.php */