summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/postgre
diff options
context:
space:
mode:
authorGreg Aker <greg@gregaker.net>2011-12-28 00:11:38 +0100
committerGreg Aker <greg@gregaker.net>2011-12-28 00:11:38 +0100
commit0cbcc1aecab7aaea719eafc58e68e0a81987ceeb (patch)
tree1b558ad1b6570687da1c72b2a0f39262e7ddf2c5 /system/database/drivers/postgre
parentd96f88277c1e9a4c069c2e2ee3d779385549f31a (diff)
Fix #808 Postgresql DBForge Driver errors.
- _process_fields() was missing and add_column(), drop_column() was producing malformed queries.
Diffstat (limited to 'system/database/drivers/postgre')
-rw-r--r--system/database/drivers/postgre/postgre_forge.php106
1 files changed, 51 insertions, 55 deletions
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 */