Vergleich inc/db_pgsql.php - 1.8.8 - 1.8.29

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

/**

	 * Moves internal row pointer to the next row
*
* @param resource $query The query ID.

	 * Moves internal row pointer to the next row
*
* @param resource $query The query ID.

Zeile 463Zeile 472

/**
* Return the number of rows resulting from a query.


/**
* Return the number of rows resulting from a query.

	 *

	 *

	 * @param resource $query The query ID.
* @return int The number of rows in the result.
*/

	 * @param resource $query The query ID.
* @return int The number of rows in the result.
*/

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 493Zeile 500
		{
return 0;
}

		{
return 0;
}





		$id = $this->write_query("SELECT currval(pg_get_serial_sequence('{$table}', '{$field}')) AS last_value");
return $this->fetch_field($id, 'last_value');
}

/**
* Close the connection with the DBMS.

		$id = $this->write_query("SELECT currval(pg_get_serial_sequence('{$table}', '{$field}')) AS last_value");
return $this->fetch_field($id, 'last_value');
}

/**
* Close the connection with the DBMS.

	 *

	 *

	 */
function close()
{

	 */
function close()
{

Zeile 964Zeile 971
	 */
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 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))

		foreach($unique_keys as $key_name => $key_columns)

		{

		{

			$lines[] = "  CONSTRAINT $primary_key_name PRIMARY KEY (".implode(', ', $primary_key).")";

			$lines[] = "  CONSTRAINT $key_name UNIQUE (".implode(', ', $key_columns).")";

		}

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

		}

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

Zeile 1280Zeile 1299
	 * @param string $old_table The old table name
* @param string $new_table the new table name
* @param boolean $table_prefix use table prefix

	 * @param string $old_table The old table name
* @param string $new_table the new table name
* @param boolean $table_prefix use table prefix

	 * @return resource

	 * @return resource

	 */
function rename_table($old_table, $new_table, $table_prefix=true)
{
if($table_prefix == false)

	 */
function rename_table($old_table, $new_table, $table_prefix=true)
{
if($table_prefix == false)

		{

		{

			$table_prefix = "";

			$table_prefix = "";

		}

		}

		else
{
$table_prefix = $this->table_prefix;

		else
{
$table_prefix = $this->table_prefix;

Zeile 1298Zeile 1317

/**
* Replace contents of table with values


/**
* Replace contents of table with values

	 *

	 *

	 * @param string $table The table
* @param array $replacements The replacements
* @param string|array $default_field The default field(s)

	 * @param string $table The table
* @param array $replacements The replacements
* @param string|array $default_field The default field(s)

Zeile 1321Zeile 1340

$update = false;
$search_bit = array();


$update = false;
$search_bit = array();

		if(is_array($main_field) && !empty($main_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($column[$main_field] == $replacements[$main_field])
{
$update = true;
break;
}
}
}


if(!is_array($main_field))
{
$main_field = array($main_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;
}













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
{

		}
else
{

Zeile 1380Zeile 1381
	 * @return string
*/
function build_fields_string($table, $append="")

	 * @return string
*/
function build_fields_string($table, $append="")

	{

	{

		$fields = $this->show_fields_from($table);
$comma = $fieldstring = '';

		$fields = $this->show_fields_from($table);
$comma = $fieldstring = '';





		foreach($fields as $key => $field)
{
$fieldstring .= $comma.$append.$field['Field'];
$comma = ',';
}

		foreach($fields as $key => $field)
{
$fieldstring .= $comma.$append.$field['Field'];
$comma = ',';
}





		return $fieldstring;
}

/**
* Drops a column

		return $fieldstring;
}

/**
* Drops a column

	 *
* @param string $table The table
* @param string $column The column name
* @return resource

	 *
* @param string $table The table
* @param string $column The column name
* @return resource

	 */
function drop_column($table, $column)
{

	 */
function drop_column($table, $column)
{

Zeile 1424Zeile 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 1435Zeile 1436
		if($new_definition !== false)
{
$result1 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} TYPE {$new_definition}");

		if($new_definition !== false)
{
$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";

Zeile 1449Zeile 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 1468Zeile 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)