Vergleich inc/db_pgsql.php - 1.8.9 - 1.8.28

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 181Zeile 181
			}
}


			}
}


		$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 189Zeile 192
			if(!isset($connections[$type]) || !is_array($connections[$type]))
{
break;

			if(!isset($connections[$type]) || !is_array($connections[$type]))
{
break;

			}


			}


			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;
}

// Shuffle the connections
shuffle($connections[$type]);

				$connections[$type][] = $details;
}

// Shuffle the connections
shuffle($connections[$type]);





			// Loop-de-loop
foreach($connections[$type] as $single_connection)
{

			// Loop-de-loop
foreach($connections[$type] as $single_connection)
{

Zeile 208Zeile 211
				if(isset($single_connection['pconnect']))
{
$connect_function = "pg_pconnect";

				if(isset($single_connection['pconnect']))
{
$connect_function = "pg_pconnect";

				}


				}


				$link = $type."_link";

get_execution_time();

				$link = $type."_link";

get_execution_time();

Zeile 219Zeile 222
				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'])

Zeile 288Zeile 295
	{
global $mybb;


	{
global $mybb;


		$string = preg_replace("#LIMIT (\s*)([0-9]+),(\s*)([0-9]+)$#im", "LIMIT $4 OFFSET $2", trim($string));

		$string = preg_replace("#LIMIT (\s*)([0-9]+),(\s*)([0-9]+);?$#im", "LIMIT $4 OFFSET $2", trim($string));


$this->last_query = $string;



$this->last_query = $string;


Zeile 441Zeile 448
		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 479Zeile 488
	 */
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 642Zeile 649
	{
// 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)
{
return true;
}
else
{
return false;
}
}

/**


$exists = $this->fetch_field($query, 'table_names');

if($exists > 0)
{
return true;
}
else
{
return false;
}
}

/**

	 * Check if a field exists in a database.
*
* @param string $field The field name.

	 * Check if a field exists in a database.
*
* @param string $field The field name.

Zeile 665Zeile 672
	function field_exists($field, $table)
{
$query = $this->write_query("SELECT COUNT(column_name) as column_names FROM information_schema.columns WHERE table_name='{$this->table_prefix}{$table}' AND column_name='{$field}'");

	function field_exists($field, $table)
{
$query = $this->write_query("SELECT COUNT(column_name) as column_names FROM information_schema.columns WHERE table_name='{$this->table_prefix}{$table}' AND column_name='{$field}'");





		$exists = $this->fetch_field($query, "column_names");

if($exists > 0)

		$exists = $this->fetch_field($query, "column_names");

if($exists > 0)

		{
return true;
}
else
{
return false;
}

		{
return true;
}
else
{
return false;
}

	}

/**

	}

/**

Zeile 694Zeile 701
		else
{
$shutdown_queries[] = $query;

		else
{
$shutdown_queries[] = $query;

		}

		}

	}

/**

	}

/**

Zeile 731Zeile 738
		if(isset($options['limit_start']) && isset($options['limit']))
{
$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];

		if(isset($options['limit_start']) && isset($options['limit']))
{
$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];

		}
else if(isset($options['limit']))
{

		}
else if(isset($options['limit']))
{

			$query .= " LIMIT ".$options['limit'];
}

return $this->query($query);
}

			$query .= " LIMIT ".$options['limit'];
}

return $this->query($query);
}





	/**
* Build an insert query from an array.
*

	/**
* Build an insert query from an array.
*

Zeile 749Zeile 756
	 * @return int|bool The insert ID if available. False on failure and true if $insert_id is false
*/
function insert_query($table, $array, $insert_id=true)

	 * @return int|bool The insert ID if available. False on failure and true if $insert_id is false
*/
function insert_query($table, $array, $insert_id=true)

	{
global $mybb;

if(!is_array($array))

	{
global $mybb;

if(!is_array($array))

		{
return false;
}

		{
return false;
}

Zeile 810Zeile 817
		foreach($array as $values)
{
foreach($values as $field => $value)

		foreach($array as $values)
{
foreach($values as $field => $value)

			{

			{

				if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])
{
$values[$field] = $value;

				if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])
{
$values[$field] = $value;

Zeile 828Zeile 835
			INSERT
INTO {$this->table_prefix}{$table} ({$fields})
VALUES {$insert_rows}

			INSERT
INTO {$this->table_prefix}{$table} ({$fields})
VALUES {$insert_rows}

		");
}

		");
}


/**
* Build an update query from an array.


/**
* Build an update query from an array.

Zeile 848Zeile 855
		if(!is_array($array))
{
return false;

		if(!is_array($array))
{
return false;

		}

		}


$comma = "";
$query = "";


$comma = "";
$query = "";

Zeile 886Zeile 893
	/**
* @param int|string $value
* @param string $quote

	/**
* @param int|string $value
* @param string $quote

	 *

	 *

	 * @return int|string
*/
private function quote_val($value, $quote="'")

	 * @return int|string
*/
private function quote_val($value, $quote="'")

Zeile 905Zeile 912

/**
* Build a delete query.


/**
* Build a delete query.

	 *

	 *

	 * @param string $table The table name to perform the query on.
* @param string $where An optional where clause for the query.
* @param string $limit An optional limit clause for the query.

	 * @param string $table The table name to perform the query on.
* @param string $where An optional where clause for the query.
* @param string $limit An optional limit clause for the query.

Zeile 924Zeile 931
			FROM {$this->table_prefix}$table
$query
");

			FROM {$this->table_prefix}$table
$query
");

	}

	}


/**
* Escape a string according to the pg escape format.


/**
* Escape a string according to the pg escape format.

Zeile 935Zeile 942
	function escape_string($string)
{
if(function_exists("pg_escape_string"))

	function escape_string($string)
{
if(function_exists("pg_escape_string"))

		{

		{

			$string = pg_escape_string($string);
}
else

			$string = pg_escape_string($string);
}
else

Zeile 943Zeile 950
			$string = addslashes($string);
}
return $string;

			$string = addslashes($string);
}
return $string;

	}

	}


/**
* Frees the resources of a PgSQL query.


/**
* Frees the resources of a PgSQL query.

Zeile 954Zeile 961
	function free_result($query)
{
return pg_free_result($query);

	function free_result($query)
{
return pg_free_result($query);

	}


	}


	/**
* Escape a string used within a like command.
*

	/**
* Escape a string used within a like command.
*

Zeile 963Zeile 970
	 * @return string The escaped string.
*/
function escape_string_like($string)

	 * @return string The escaped string.
*/
function escape_string_like($string)

	{
return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string));
}


	{
return $this->escape_string(str_replace(array('\\', '%', '_') , array('\\\\', '\\%' , '\\_') , $string));
}


	/**
* Gets the current version of PgSQL.
*

	/**
* Gets the current version of PgSQL.
*

Zeile 984Zeile 991
  		$this->version = $version['server'];

return $this->version;

  		$this->version = $version['server'];

return $this->version;

	}

/**

	}

/**

	 * Optimizes a specific table.
*
* @param string $table The name of the table to be optimized.

	 * Optimizes a specific table.
*
* @param string $table The name of the table to be optimized.

Zeile 1004Zeile 1011
	function analyze_table($table)
{
$this->write_query("ANALYZE ".$this->table_prefix.$table."");

	function analyze_table($table)
{
$this->write_query("ANALYZE ".$this->table_prefix.$table."");

	}


	}


	/**
* Show the "create table" command for a specific table.
*

	/**
* Show the "create table" command for a specific table.
*

Zeile 1025Zeile 1032

$lines = array();
$table_lines = "CREATE TABLE {$this->table_prefix}{$table} (\n";


$lines = array();
$table_lines = "CREATE TABLE {$this->table_prefix}{$table} (\n";





		while($row = $this->fetch_array($query))
{
// Get the data from the table

		while($row = $this->fetch_array($query))
{
// Get the data from the table

Zeile 1043Zeile 1050
			else
{
$row['rowdefault'] = $this->fetch_field($query2, 'rowdefault');

			else
{
$row['rowdefault'] = $this->fetch_field($query2, 'rowdefault');

			}


			}


			if($row['type'] == 'bpchar')
{
// Stored in the engine as bpchar, but in the CREATE TABLE statement it's char
$row['type'] = 'char';

			if($row['type'] == 'bpchar')
{
// Stored in the engine as bpchar, but in the CREATE TABLE statement it's char
$row['type'] = 'char';

			}

			}


$line = " {$row['field']} {$row['type']}";

if(strpos($row['type'], 'char') !== false)


$line = " {$row['field']} {$row['type']}";

if(strpos($row['type'], 'char') !== false)

			{

			{

				if($row['lengthvar'] > 0)
{
$line .= '('.($row['lengthvar'] - 4).')';

				if($row['lengthvar'] > 0)
{
$line .= '('.($row['lengthvar'] - 4).')';

Zeile 1064Zeile 1071
			if(strpos($row['type'], 'numeric') !== false)
{
$line .= '('.sprintf("%s,%s", (($row['lengthvar'] >> 16) & 0xffff), (($row['lengthvar'] - 4) & 0xffff)).')';

			if(strpos($row['type'], 'numeric') !== false)
{
$line .= '('.sprintf("%s,%s", (($row['lengthvar'] >> 16) & 0xffff), (($row['lengthvar'] - 4) & 0xffff)).')';

			}

			}


if(!empty($row['rowdefault']))
{


if(!empty($row['rowdefault']))
{

Zeile 1093Zeile 1100

$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))
{
if($row['primary_key'] == 't')


// We do this in two steps. It makes placing the comma easier
while($row = $this->fetch_array($query))
{
if($row['primary_key'] == 't')

			{

			{

				$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))
{
$lines[] = " CONSTRAINT $primary_key_name PRIMARY KEY (".implode(', ', $primary_key).")";


if(!empty($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 .= "\n)\n";

		}

$table_lines .= implode(", \n", $lines);
$table_lines .= "\n)\n";





		return $table_lines;
}


		return $table_lines;
}


Zeile 1122Zeile 1141
	 * @return array Field info for that table
*/
function show_fields_from($table)

	 * @return array Field info for that table
*/
function show_fields_from($table)

	{

	{

		$query = $this->write_query("SELECT column_name FROM information_schema.constraint_column_usage WHERE table_name = '{$this->table_prefix}{$table}' and constraint_name = '{$this->table_prefix}{$table}_pkey' LIMIT 1");
$primary_key = $this->fetch_field($query, 'column_name');


		$query = $this->write_query("SELECT column_name FROM information_schema.constraint_column_usage WHERE table_name = '{$this->table_prefix}{$table}' and constraint_name = '{$this->table_prefix}{$table}_pkey' LIMIT 1");
$primary_key = $this->fetch_field($query, 'column_name');


Zeile 1406Zeile 1425
	 * @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 1431Zeile 1450
			$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 1450Zeile 1472
	 * @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)