Zeile 23 | Zeile 23 |
---|
* @var string */ public $short_title = "PostgreSQL";
|
* @var string */ public $short_title = "PostgreSQL";
|
| /** * The type of db software being used. * * @var string */ public $type;
|
/** * A count of the number of queries.
| /** * A count of the number of queries.
|
Zeile 44 | Zeile 51 |
---|
* @var boolean */ public $error_reporting = 1;
|
* @var boolean */ public $error_reporting = 1;
|
|
|
/** * The read database connection resource.
|
/** * The read database connection resource.
|
* * @var resource
| * * @var resource
|
*/ public $read_link;
|
*/ public $read_link;
|
/**
| /**
|
* The write database connection resource
|
* The write database connection resource
|
* * @var resource */
| * * @var resource */
|
public $write_link;
/** * Reference to the last database connection resource used.
|
public $write_link;
/** * Reference to the last database connection resource used.
|
* * @var resource */
| * * @var resource */
|
public $current_link;
|
public $current_link;
|
/**
| /** * @var array */ public $connections = array();
/**
|
* Explanation of a query.
|
* Explanation of a query.
|
*
| *
|
* @var string */ public $explain;
|
* @var string */ public $explain;
|
/**
| /**
|
* The current version of PgSQL. * * @var string
| * The current version of PgSQL. * * @var string
|
Zeile 82 | Zeile 94 |
---|
/** * The current table type in use (myisam/innodb)
|
/** * The current table type in use (myisam/innodb)
|
* * @var string
| * * @var string
|
*/ public $table_type = "myisam";
| */ public $table_type = "myisam";
|
Zeile 121 | Zeile 133 |
---|
* @var string */ public $engine = "pgsql";
|
* @var string */ public $engine = "pgsql";
|
/**
| /**
|
* Weather or not this engine can use the search functionality * * @var boolean
| * Weather or not this engine can use the search functionality * * @var boolean
|
Zeile 181 | Zeile 193 |
---|
} }
|
} }
|
$this->db_encoding = $config['encoding'];
| if(isset($config['encoding'])) { $this->db_encoding = $config['encoding']; }
|
// Actually connect to the specified servers foreach(array('read', 'write') as $type)
| // Actually connect to the specified servers foreach(array('read', 'write') as $type)
|
Zeile 194 | Zeile 209 |
---|
if(array_key_exists('hostname', $connections[$type])) { $details = $connections[$type];
|
if(array_key_exists('hostname', $connections[$type])) { $details = $connections[$type];
|
unset($connections);
| unset($connections[$type]);
|
$connections[$type][] = $details; }
| $connections[$type][] = $details; }
|
Zeile 219 | Zeile 234 |
---|
if(strpos($single_connection['hostname'], ':') !== false) { list($single_connection['hostname'], $single_connection['port']) = explode(':', $single_connection['hostname']);
|
if(strpos($single_connection['hostname'], ':') !== false) { list($single_connection['hostname'], $single_connection['port']) = explode(':', $single_connection['hostname']);
|
| } else { $single_connection['port'] = null;
|
}
if($single_connection['port'])
|
}
if($single_connection['port'])
|
{
| {
|
$this->connect_string .= " port={$single_connection['port']}";
|
$this->connect_string .= " port={$single_connection['port']}";
|
}
| }
|
if($single_connection['hostname'] != "")
|
if($single_connection['hostname'] != "")
|
{
| {
|
$this->connect_string .= " host={$single_connection['hostname']}";
|
$this->connect_string .= " host={$single_connection['hostname']}";
|
}
| }
|
if($single_connection['password']) {
| if($single_connection['password']) {
|
Zeile 239 | Zeile 258 |
---|
$time_spent = get_execution_time(); $this->query_time += $time_spent;
|
$time_spent = get_execution_time(); $this->query_time += $time_spent;
|
|
|
// Successful connection? break down brother! if($this->$link) { $this->connections[] = "[".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']} (Connected in ".format_time_duration($time_spent).")"; break;
|
// Successful connection? break down brother! if($this->$link) { $this->connections[] = "[".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']} (Connected in ".format_time_duration($time_spent).")"; break;
|
}
| }
|
else { $this->connections[] = "<span style=\"color: red\">[FAILED] [".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']}</span>"; } }
|
else { $this->connections[] = "<span style=\"color: red\">[FAILED] [".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']}</span>"; } }
|
}
| }
|
// No write server was specified (simple connection or just multiple servers) - mirror write link if(!array_key_exists('write', $connections)) { $this->write_link = &$this->read_link;
|
// No write server was specified (simple connection or just multiple servers) - mirror write link if(!array_key_exists('write', $connections)) { $this->write_link = &$this->read_link;
|
}
| }
|
// Have no read connection? if(!$this->read_link)
|
// Have no read connection? if(!$this->read_link)
|
{
| {
|
$this->error("[READ] Unable to connect to PgSQL server");
|
$this->error("[READ] Unable to connect to PgSQL server");
|
return false;
| return false;
|
} // No write? else if(!$this->write_link)
| } // No write? else if(!$this->write_link)
|
Zeile 271 | Zeile 290 |
---|
$this->error("[WRITE] Unable to connect to PgSQL server"); return false; }
|
$this->error("[WRITE] Unable to connect to PgSQL server"); return false; }
|
|
|
$this->current_link = &$this->read_link; return $this->read_link; }
/** * Query the database.
|
$this->current_link = &$this->read_link; return $this->read_link; }
/** * Query the database.
|
*
| *
|
* @param string $string The query SQL. * @param boolean|int $hide_errors 1 if hide errors, 0 if not. * @param integer $write_query 1 if executes on slave database, 0 if not.
| * @param string $string The query SQL. * @param boolean|int $hide_errors 1 if hide errors, 0 if not. * @param integer $write_query 1 if executes on slave database, 0 if not.
|
Zeile 288 | Zeile 307 |
---|
{ global $mybb;
|
{ global $mybb;
|
$string = preg_replace("#LIMIT (\s*)([0-9]+),(\s*)([0-9]+)$#im", "LIMIT $4 OFFSET $2", trim($string));
$this->last_query = $string;
| $string = preg_replace("#LIMIT (\s*)([0-9]+),(\s*)([0-9]+);?$#im", "LIMIT $4 OFFSET $2", trim($string));
$this->last_query = $string;
|
get_execution_time();
if(strtolower(substr(ltrim($string), 0, 5)) == 'alter') { $string = preg_replace("#\sAFTER\s([a-z_]+?)(;*?)$#i", "", $string); if(strstr($string, 'CHANGE') !== false)
|
get_execution_time();
if(strtolower(substr(ltrim($string), 0, 5)) == 'alter') { $string = preg_replace("#\sAFTER\s([a-z_]+?)(;*?)$#i", "", $string); if(strstr($string, 'CHANGE') !== false)
|
{
| {
|
$string = str_replace(' CHANGE ', ' ALTER ', $string); } }
| $string = str_replace(' CHANGE ', ' ALTER ', $string); } }
|
Zeile 376 | Zeile 395 |
---|
"<tr bgcolor=\"#ffffff\">\n". "<td>".$table['QUERY PLAN']."</td>\n". "</tr>\n";
|
"<tr bgcolor=\"#ffffff\">\n". "<td>".$table['QUERY PLAN']."</td>\n". "</tr>\n";
|
}
| }
|
$this->explain .= "<tr>\n". "<td colspan=\"8\" style=\"background-color: #fff;\">Query Time: ".format_time_duration($qtime)."</td>\n".
|
$this->explain .= "<tr>\n". "<td colspan=\"8\" style=\"background-color: #fff;\">Query Time: ".format_time_duration($qtime)."</td>\n".
|
"</tr>\n". "</table>\n". "<br />\n";
| "</tr>\n". "</table>\n". "<br />\n";
|
} else { $this->explain .= "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n".
|
} else { $this->explain .= "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n".
|
"<tr>\n".
| "<tr>\n".
|
"<td style=\"background-color: #ccc;\"><strong>#".$this->query_count." - Write Query</strong></td>\n". "</tr>\n". "<tr style=\"background-color: #fefefe;\">\n".
| "<td style=\"background-color: #ccc;\"><strong>#".$this->query_count." - Write Query</strong></td>\n". "</tr>\n". "<tr style=\"background-color: #fefefe;\">\n".
|
Zeile 398 | Zeile 417 |
---|
"</tr>\n". "</table>\n". "<br />\n";
|
"</tr>\n". "</table>\n". "<br />\n";
|
}
| }
|
$this->querylist[$this->query_count]['query'] = $string; $this->querylist[$this->query_count]['time'] = $qtime;
| $this->querylist[$this->query_count]['query'] = $string; $this->querylist[$this->query_count]['time'] = $qtime;
|
Zeile 441 | Zeile 460 |
---|
if($row === false) { $array = $this->fetch_array($query);
|
if($row === false) { $array = $this->fetch_array($query);
|
return $array[$field]; } else { return pg_fetch_result($query, $row, $field);
| if($array !== null && $array !== false) { return $array[$field]; } return null;
|
}
|
}
|
| return pg_fetch_result($query, $row, $field);
|
}
/**
| }
/**
|
Zeile 479 | Zeile 500 |
---|
*/ function insert_id() {
|
*/ function insert_id() {
|
$this->last_query = str_replace(array("\r", "\t"), '', $this->last_query); $this->last_query = str_replace("\n", ' ', $this->last_query); preg_match('#INSERT INTO ([a-zA-Z0-9_\-]+)#i', $this->last_query, $matches);
| preg_match('#INSERT\s+INTO\s+([a-zA-Z0-9_\-]+)#i', $this->last_query, $matches);
|
$table = $matches[1];
| $table = $matches[1];
|
Zeile 490 | Zeile 509 |
---|
// Do we not have a primary field? if(!$field)
|
// Do we not have a primary field? if(!$field)
|
{
| {
|
return 0; }
| return 0; }
|
Zeile 555 | Zeile 574 |
---|
* * @param string $string The string to present as an error. * @param resource $query
|
* * @param string $string The string to present as an error. * @param resource $query
|
*/
| */
|
function error($string="", $query=null) { if($this->error_reporting)
| function error($string="", $query=null) { if($this->error_reporting)
|
Zeile 599 | Zeile 618 |
---|
* * @param resource $query The query ID. * @return int The number of fields.
|
* * @param resource $query The query ID. * @return int The number of fields.
|
*/
| */
|
function num_fields($query) { return pg_num_fields($query);
| function num_fields($query) { return pg_num_fields($query);
|
Zeile 621 | Zeile 640 |
---|
else { $query = $this->query("SELECT table_name FROM information_schema.tables WHERE table_schema='public'");
|
else { $query = $this->query("SELECT table_name FROM information_schema.tables WHERE table_schema='public'");
|
}
| }
|
$tables = array(); while($table = $this->fetch_array($query))
| $tables = array(); while($table = $this->fetch_array($query))
|
Zeile 642 | Zeile 661 |
---|
{ // Execute on master server to ensure if we've just created a table that we get the correct result $query = $this->write_query("SELECT COUNT(table_name) as table_names FROM information_schema.tables WHERE table_schema = 'public' AND table_name='{$this->table_prefix}{$table}'");
|
{ // Execute on master server to ensure if we've just created a table that we get the correct result $query = $this->write_query("SELECT COUNT(table_name) as table_names FROM information_schema.tables WHERE table_schema = 'public' AND table_name='{$this->table_prefix}{$table}'");
|
|
|
$exists = $this->fetch_field($query, 'table_names');
if($exists > 0)
| $exists = $this->fetch_field($query, 'table_names');
if($exists > 0)
|
Zeile 729 | Zeile 748 |
---|
}
if(isset($options['limit_start']) && isset($options['limit']))
|
}
if(isset($options['limit_start']) && isset($options['limit']))
|
{
| {
|
$query .= " LIMIT ".$options['limit_start'].", ".$options['limit']; } else if(isset($options['limit']))
| $query .= " LIMIT ".$options['limit_start'].", ".$options['limit']; } else if(isset($options['limit']))
|
Zeile 936 | Zeile 955 |
---|
{ if(function_exists("pg_escape_string")) {
|
{ if(function_exists("pg_escape_string")) {
|
$string = pg_escape_string($string);
| $string = pg_escape_string($this->read_link, $string);
|
} else {
| } else {
|
Zeile 964 | Zeile 983 |
---|
*/ function escape_string_like($string) {
|
*/ function escape_string_like($string) {
|
return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string));
| return $this->escape_string(str_replace(array('\\', '%', '_') , array('\\\\', '\\%' , '\\_') , $string));
|
}
/**
| }
/**
|
Zeile 1080 | Zeile 1099 |
---|
}
// Get the listing of primary keys.
|
}
// Get the listing of primary keys.
|
$query = $this->write_query("
| $query = $this->write_query("
|
SELECT ic.relname as index_name, bc.relname as tab_name, ta.attname as column_name, i.indisunique as unique_key, i.indisprimary as primary_key FROM pg_class bc LEFT JOIN pg_index i ON (bc.oid = i.indrelid)
| SELECT ic.relname as index_name, bc.relname as tab_name, ta.attname as column_name, i.indisunique as unique_key, i.indisprimary as primary_key FROM pg_class bc LEFT JOIN pg_index i ON (bc.oid = i.indrelid)
|
Zeile 1093 | Zeile 1112 |
---|
$primary_key = array(); $primary_key_name = '';
|
$primary_key = array(); $primary_key_name = '';
|
| $unique_keys = array();
|
// We do this in two steps. It makes placing the comma easier while($row = $this->fetch_array($query))
| // We do this in two steps. It makes placing the comma easier while($row = $this->fetch_array($query))
|
Zeile 1101 | Zeile 1122 |
---|
{ $primary_key[] = $row['column_name']; $primary_key_name = $row['index_name'];
|
{ $primary_key[] = $row['column_name']; $primary_key_name = $row['index_name'];
|
} }
| }
if($row['unique_key'] == 't') { $unique_keys[$row['index_name']][] = $row['column_name']; } }
|
if(!empty($primary_key))
|
if(!empty($primary_key))
|
{
| {
|
$lines[] = " CONSTRAINT $primary_key_name PRIMARY KEY (".implode(', ', $primary_key).")";
|
$lines[] = " CONSTRAINT $primary_key_name PRIMARY KEY (".implode(', ', $primary_key).")";
|
| }
foreach($unique_keys as $key_name => $key_columns) { $lines[] = " CONSTRAINT $key_name UNIQUE (".implode(', ', $key_columns).")";
|
}
$table_lines .= implode(", \n", $lines);
| }
$table_lines .= implode(", \n", $lines);
|
Zeile 1127 | Zeile 1158 |
---|
$primary_key = $this->fetch_field($query, 'column_name');
$query = $this->write_query("
|
$primary_key = $this->fetch_field($query, 'column_name');
$query = $this->write_query("
|
SELECT column_name as Field, data_type as Extra
| SELECT column_name, data_type, is_nullable, column_default, character_maximum_length, numeric_precision, numeric_precision_radix, numeric_scale
|
FROM information_schema.columns WHERE table_name = '{$this->table_prefix}{$table}' "); $field_info = array(); while($field = $this->fetch_array($query)) {
|
FROM information_schema.columns WHERE table_name = '{$this->table_prefix}{$table}' "); $field_info = array(); while($field = $this->fetch_array($query)) {
|
if($field['field'] == $primary_key)
| if($field['column_name'] == $primary_key)
|
{
|
{
|
$field['extra'] = 'auto_increment';
| $field['_key'] = 'PRI'; } else { $field['_key'] = ''; }
if(stripos($field['column_default'], 'nextval') !== false) { $field['_extra'] = 'auto_increment'; } else { $field['_extra'] = ''; }
// bit, character, text fields. if(!is_null($field['character_maximum_length'])) { $field['data_type'] .= '('.(int)$field['character_maximum_length'].')'; } // numeric/decimal fields. else if($field['numeric_precision_radix'] == 10 && !is_null($field['numeric_precision']) && !is_null($field['numeric_scale'])) { $field['data_type'] .= '('.(int)$field['numeric_precision'].','.(int)$field['numeric_scale'].')';
|
}
|
}
|
$field_info[] = array('Extra' => $field['extra'], 'Field' => $field['field']);
| $field_info[] = array( 'Field' => $field['column_name'], 'Type' => $field['data_type'], 'Null' => $field['is_nullable'], 'Key' => $field['_key'], 'Default' => $field['column_default'], 'Extra' => $field['_extra'], );
|
}
return $field_info;
| }
return $field_info;
|
Zeile 1171 | Zeile 1233 |
---|
/** * Returns whether or not this database engine supports boolean fulltext matching.
|
/** * Returns whether or not this database engine supports boolean fulltext matching.
|
*
| *
|
* @param string $table The table to be checked. * @return boolean True or false if supported or not. */ function supports_fulltext_boolean($table)
|
* @param string $table The table to be checked. * @return boolean True or false if supported or not. */ function supports_fulltext_boolean($table)
|
{ return false; }
/**
| { return false; }
/**
|
* Creates a fulltext index on the specified column in the specified table with optional index name. * * @param string $table The name of the table.
| * Creates a fulltext index on the specified column in the specified table with optional index name. * * @param string $table The name of the table.
|
Zeile 1191 | Zeile 1253 |
---|
function create_fulltext_index($table, $column, $name="") { return false;
|
function create_fulltext_index($table, $column, $name="") { return false;
|
}
/**
| }
/**
|
* Drop an index with the specified name from the specified table
|
* Drop an index with the specified name from the specified table
|
* * @param string $table The name of the table.
| * * @param string $table The name of the table.
|
* @param string $name The name of the index. */ function drop_index($table, $name)
| * @param string $name The name of the index. */ function drop_index($table, $name)
|
Zeile 1215 | Zeile 1277 |
---|
* @return bool Returns whether index exists */ function index_exists($table, $index)
|
* @return bool Returns whether index exists */ function index_exists($table, $index)
|
{
| {
|
$err = $this->error_reporting; $this->error_reporting = 0;
| $err = $this->error_reporting; $this->error_reporting = 0;
|
Zeile 1251 | Zeile 1313 |
---|
{ $table_prefix = $this->table_prefix; }
|
{ $table_prefix = $this->table_prefix; }
|
| $table_prefix_bak = $this->table_prefix; $this->table_prefix = ''; $fields = array_column($this->show_fields_from($table_prefix.$table), 'Field');
|
if($hard == false) {
|
if($hard == false) {
|
if($this->table_exists($table))
| if($this->table_exists($table_prefix.$table))
|
{ $this->write_query('DROP TABLE '.$table_prefix.$table);
|
{ $this->write_query('DROP TABLE '.$table_prefix.$table);
|
} } else { $this->write_query('DROP TABLE '.$table_prefix.$table); }
$query = $this->query("SELECT column_name FROM information_schema.constraint_column_usage WHERE table_name = '{$table}' and constraint_name = '{$table}_pkey' LIMIT 1"); $field = $this->fetch_field($query, 'column_name');
// Do we not have a primary field? if($field) { $this->write_query('DROP SEQUENCE {$table}_{$field}_id_seq'); } }
| } } else { $this->write_query('DROP TABLE '.$table_prefix.$table); }
$this->table_prefix = $table_prefix_bak;
if(!empty($fields)) { foreach($fields as &$field) { $field = "{$table_prefix}{$table}_{$field}_seq"; } unset($field);
if(version_compare($this->get_version(), '8.2.0', '>=')) { $fields = implode(', ', $fields); $this->write_query("DROP SEQUENCE IF EXISTS {$fields}"); } else { $fields = "'".implode("', '", $fields)."'"; $query = $this->query("SELECT sequence_name as field FROM information_schema.sequences WHERE sequence_name in ({$fields}) AND sequence_schema = 'public'"); while($row = $this->fetch_array($query)) { $this->write_query("DROP SEQUENCE {$row['field']}"); } } } }
|
/** * Renames a table *
| /** * Renames a table *
|
Zeile 1287 | Zeile 1370 |
---|
if($table_prefix == false) { $table_prefix = "";
|
if($table_prefix == false) { $table_prefix = "";
|
}
| }
|
else { $table_prefix = $this->table_prefix; }
return $this->write_query("ALTER TABLE {$table_prefix}{$old_table} RENAME TO {$table_prefix}{$new_table}");
|
else { $table_prefix = $this->table_prefix; }
return $this->write_query("ALTER TABLE {$table_prefix}{$old_table} RENAME TO {$table_prefix}{$new_table}");
|
}
| }
|
/** * Replace contents of table with values *
| /** * Replace contents of table with values *
|
Zeile 1321 | Zeile 1404 |
---|
$update = false; $search_bit = array();
|
$update = false; $search_bit = array();
|
if(is_array($main_field) && !empty($main_field))
| if(!is_array($main_field)) { $main_field = array($main_field); }
foreach($main_field as $field)
|
{
|
{
|
foreach($main_field as $field) { if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field]) { $search_bit[] = "{$field} = ".$replacements[$field]; } else { $search_bit[] = "{$field} = ".$this->quote_val($replacements[$field]); } }
$search_bit = implode(" AND ", $search_bit); $query = $this->write_query("SELECT COUNT(".$main_field[0].") as count FROM {$this->table_prefix}{$table} WHERE {$search_bit} LIMIT 1"); if($this->fetch_field($query, "count") == 1) { $update = true; } } else { $query = $this->write_query("SELECT {$main_field} FROM {$this->table_prefix}{$table}");
while($column = $this->fetch_array($query))
| if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])
|
{
|
{
|
if($column[$main_field] == $replacements[$main_field]) { $update = true; break; }
| $search_bit[] = "{$field} = ".$replacements[$field]; } else { $search_bit[] = "{$field} = ".$this->quote_val($replacements[$field]);
|
}
|
}
|
| } $search_bit = implode(" AND ", $search_bit); $query = $this->write_query("SELECT COUNT(".$main_field[0].") as count FROM {$this->table_prefix}{$table} WHERE {$search_bit} LIMIT 1"); if($this->fetch_field($query, "count") == 1) { $update = true;
|
}
if($update === true)
|
}
if($update === true)
|
{ if(is_array($main_field)) { return $this->update_query($table, $replacements, $search_bit); } else { return $this->update_query($table, $replacements, "{$main_field}=".$this->quote_val($replacements[$main_field])); } }
| { return $this->update_query($table, $replacements, $search_bit); }
|
else { return $this->insert_query($table, $replacements, $insert_id); } }
|
else { return $this->insert_query($table, $replacements, $insert_id); } }
|
|
|
/** * @param string $table * @param string $append
| /** * @param string $table * @param string $append
|
Zeile 1388 | Zeile 1453 |
---|
{ $fieldstring .= $comma.$append.$field['Field']; $comma = ',';
|
{ $fieldstring .= $comma.$append.$field['Field']; $comma = ',';
|
}
| }
|
return $fieldstring;
|
return $fieldstring;
|
}
| }
|
/** * Drops a column
|
/** * Drops a column
|
* * @param string $table The table * @param string $column The column name
| * * @param string $table The table * @param string $column The column name
|
* @return resource */ function drop_column($table, $column)
| * @return resource */ function drop_column($table, $column)
|
Zeile 1407 | Zeile 1472 |
---|
/** * Adds a column
|
/** * Adds a column
|
* * @param string $table The table * @param string $column The column name
| * * @param string $table The table * @param string $column The column name
|
* @param string $definition the new column definition * @return resource
|
* @param string $definition the new column definition * @return resource
|
*/
| */
|
function add_column($table, $column, $definition) { return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ADD {$column} {$definition}");
| function add_column($table, $column, $definition) { return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ADD {$column} {$definition}");
|
Zeile 1424 | Zeile 1489 |
---|
* @param string $table The table * @param string $column The column name * @param string $new_definition the new column definition
|
* @param string $table The table * @param string $column The column name * @param string $new_definition the new column definition
|
* @param boolean $new_not_null Whether to drop or set a column * @param boolean $new_default_value The new default value (if one is to be set)
| * @param boolean|string $new_not_null Whether to "drop" or "set" the NOT NULL attribute (no change if false) * @param boolean|string $new_default_value The new default value, or false to drop the attribute
|
* @return bool Returns true if all queries are executed successfully or false if one of them failed */ function modify_column($table, $column, $new_definition, $new_not_null=false, $new_default_value=false)
| * @return bool Returns true if all queries are executed successfully or false if one of them failed */ function modify_column($table, $column, $new_definition, $new_not_null=false, $new_default_value=false)
|
Zeile 1433 | Zeile 1498 |
---|
$result1 = $result2 = $result3 = true;
if($new_definition !== false)
|
$result1 = $result2 = $result3 = true;
if($new_definition !== false)
|
{
| {
|
$result1 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} TYPE {$new_definition}");
|
$result1 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} TYPE {$new_definition}");
|
}
| }
|
if($new_not_null !== false) { $set_drop = "DROP";
|
if($new_not_null !== false) { $set_drop = "DROP";
|
|
|
if(strtolower($new_not_null) == "set")
|
if(strtolower($new_not_null) == "set")
|
{
| {
|
$set_drop = "SET";
|
$set_drop = "SET";
|
}
| }
|
$result2 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} {$set_drop} NOT NULL"); }
|
$result2 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} {$set_drop} NOT NULL"); }
|
if($new_default_value !== false)
| if($new_default_value !== null)
|
{
|
{
|
$result3 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} SET DEFAULT {$new_default_value}"); } else { $result3 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} DROP DEFAULT");
| if($new_default_value !== false) { $result3 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} SET DEFAULT {$new_default_value}"); } else { $result3 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} DROP DEFAULT"); }
|
}
return $result1 && $result2 && $result3;
| }
return $result1 && $result2 && $result3;
|
Zeile 1468 | Zeile 1536 |
---|
* @param string $old_column The old column name * @param string $new_column the new column name * @param string $new_definition the new column definition
|
* @param string $old_column The old column name * @param string $new_column the new column name * @param string $new_definition the new column definition
|
* @param boolean $new_not_null Whether to drop or set a column * @param boolean $new_default_value The new default value (if one is to be set)
| * @param boolean|string $new_not_null Whether to "drop" or "set" the NOT NULL attribute (no change if false) * @param boolean|string $new_default_value The new default value, or false to drop the attribute
|
* @return bool Returns true if all queries are executed successfully */ function rename_column($table, $old_column, $new_column, $new_definition, $new_not_null=false, $new_default_value=false)
| * @return bool Returns true if all queries are executed successfully */ function rename_column($table, $old_column, $new_column, $new_definition, $new_not_null=false, $new_default_value=false)
|
Zeile 1562 | Zeile 1630 |
---|
*/ function escape_binary($string) {
|
*/ function escape_binary($string) {
|
return "'".pg_escape_bytea($string)."'";
| return "'".pg_escape_bytea($this->read_link, $string)."'";
|
}
/**
| }
/**
|