From 0cbcc1aecab7aaea719eafc58e68e0a81987ceeb Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 27 Dec 2011 17:11:38 -0600 Subject: Fix #808 Postgresql DBForge Driver errors. - _process_fields() was missing and add_column(), drop_column() was producing malformed queries. --- system/database/drivers/postgre/postgre_forge.php | 106 +++++++++++----------- 1 file changed, 51 insertions(+), 55 deletions(-) (limited to 'system/database') diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index f86ba2dda..7368b9447 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -63,32 +63,13 @@ class CI_DB_postgre_forge extends CI_DB_forge { } // -------------------------------------------------------------------- - + /** - * Create Table - * - * @access private - * @param string the table name - * @param array the fields - * @param mixed primary key(s) - * @param mixed key(s) - * @param boolean should 'IF NOT EXISTS' be added to the SQL - * @return bool + * Process Fields */ - function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + function _process_fields($fields, $primary_keys=array()) { - $sql = 'CREATE TABLE '; - - if ($if_not_exists === TRUE) - { - // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually - if ($this->db->table_exists($table)) - { - return TRUE; - } - } - - $sql .= $this->db->_escape_identifiers($table)." ("; + $sql = ''; $current_field_count = 0; foreach ($fields as $field=>$attributes) @@ -184,6 +165,38 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql .= ','; } } + + return $sql; + } + + // -------------------------------------------------------------------- + + /** + * Create Table + * + * @access private + * @param string the table name + * @param array the fields + * @param mixed primary key(s) + * @param mixed key(s) + * @param boolean should 'IF NOT EXISTS' be added to the SQL + * @return bool + */ + function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) + { + $sql = 'CREATE TABLE '; + + if ($if_not_exists === TRUE) + { + // PostgreSQL doesn't support IF NOT EXISTS syntax so we check if table exists manually + if ($this->db->table_exists($table)) + { + return TRUE; + } + } + + $sql .= $this->db->_escape_identifiers($table)." ("; + $sql .= $this->_process_fields($fields, $primary_keys); if (count($primary_keys) > 0) { @@ -249,40 +262,25 @@ class CI_DB_postgre_forge extends CI_DB_forge { * @param string the field after which we should add the new field * @return object */ - 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); + function _alter_table($alter_type, $table, $fields, $after_field = '') + { + $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type "; - // DROP has everything it needs now. - if ($alter_type == 'DROP') - { - return $sql; - } + // DROP has everything it needs now. + if ($alter_type == 'DROP') + { + return $sql.$this->db->_protect_identifiers($fields); + } - $sql .= " $column_definition"; + $sql .= $this->_process_fields($fields); - if ($default_value != '') - { - $sql .= " DEFAULT \"$default_value\""; - } + if ($after_field != '') + { + $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); + } - if ($null === NULL) - { - $sql .= ' NULL'; - } - else - { - $sql .= ' NOT NULL'; - } - - if ($after_field != '') - { - $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); - } - - return $sql; - - } + return $sql; + } // -------------------------------------------------------------------- @@ -301,8 +299,6 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); return $sql; } - - } /* End of file postgre_forge.php */ -- cgit v1.2.3-24-g4f1b