Vergleich inc/db_pgsql_pdo.php - 1.8.32 - 1.8.38

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 180Zeile 180

public function insert_query($table, $array)
{


public function insert_query($table, $array)
{

		global $mybb;


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


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


		foreach ($array as $field => $value) {
if (isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field]) {
$array[$field] = $value;
} else {
$array[$field] = $this->quote_val($value);
}
}


		$values = $this->build_value_string($table, $array);








		$fields = implode(",", array_keys($array));

		$fields = implode(",", array_keys($array));

		$values = implode(",", $array);
$this->write_query("

		$this->write_query("


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

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

Zeile 209Zeile 200
	{
if (is_int($value)) {
return $value;

	{
if (is_int($value)) {
return $value;

		}


		}


		return "{$quote}{$value}{$quote}";
}

public function insert_query_multiple($table, $array)

		return "{$quote}{$value}{$quote}";
}

public function insert_query_multiple($table, $array)

	{
global $mybb;


	{



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

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

Zeile 228Zeile 217

$insert_rows = array();
foreach ($array as $values) {


$insert_rows = array();
foreach ($array as $values) {

			foreach ($values as $field => $value) {
if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field]) {
$values[$field] = $value;
} else {
$values[$field] = $this->quote_val($value);
}
}

$insert_rows[] = "(".implode(",", $values).")";

			$insert_rows[] = "(".$this->build_value_string($table, $values).")";









		}

$insert_rows = implode(", ", $insert_rows);

		}

$insert_rows = implode(", ", $insert_rows);

Zeile 253Zeile 234
		global $mybb;

if (!is_array($array)) {

		global $mybb;

if (!is_array($array)) {

			return false;
}

$comma = "";
$query = "";
$quote = "'";

if ($no_quote == true) {
$quote = "";
}

foreach($array as $field => $value) {
if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field]) {
$query .= "{$comma}{$field}={$value}";
} else {
$quoted_value = $this->quote_val($value, $quote);

$query .= "{$comma}{$field}={$quoted_value}";
}

			return false;
}






















			$comma = ', ';
}

		$query = $this->build_field_value_string($table, $array, $no_quote);



if(!empty($where)) {
$query .= " WHERE {$where}";


if(!empty($where)) {
$query .= " WHERE {$where}";

Zeile 451Zeile 414
				'Key' => $field['_key'],
'Default' => $field['column_default'],
'Extra' => $field['_extra'],

				'Key' => $field['_key'],
'Default' => $field['column_default'],
'Extra' => $field['_extra'],

			);

			);

		}

		}





		return $field_info;
}

function is_fulltext($table, $index = "")

		return $field_info;
}

function is_fulltext($table, $index = "")

	{
return false;

	{
return false;

	}

public function supports_fulltext($table)

	}

public function supports_fulltext($table)

Zeile 475Zeile 438
		$tableName = $this->escape_string("{$this->table_prefix}{$table}");

$query = $this->write_query("SELECT * FROM pg_indexes WHERE tablename = '{$tableName}'");

		$tableName = $this->escape_string("{$this->table_prefix}{$table}");

$query = $this->write_query("SELECT * FROM pg_indexes WHERE tablename = '{$tableName}'");





		$exists = $this->fetch_field($query, $index);
$this->error_reporting = $err;

		$exists = $this->fetch_field($query, $index);
$this->error_reporting = $err;





		return (bool)$exists;
}


		return (bool)$exists;
}


Zeile 487Zeile 450
		return false;
}


		return false;
}


	public function create_fulltext_index($table, $column, $name = "")
{
return false;
}


	public function create_fulltext_index($table, $column, $name = "")
{
return false;
}


	public function drop_index($table, $name)
{
$this->write_query("

	public function drop_index($table, $name)
{
$this->write_query("

Zeile 499Zeile 462
			DROP INDEX {$name}
");
}

			DROP INDEX {$name}
");
}





	public function drop_table($table, $hard = false, $table_prefix = true)
{
if ($table_prefix == false) {

	public function drop_table($table, $hard = false, $table_prefix = true)
{
if ($table_prefix == false) {

Zeile 507Zeile 470
		} else {
$table_prefix = $this->table_prefix;
}

		} else {
$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($this->table_exists($table_prefix.$table))

		$table_prefix_bak = $this->table_prefix;
$this->table_prefix = '';
$fields = array_column($this->show_fields_from($table_prefix.$table), 'Field');

if ($hard == false) {
if($this->table_exists($table_prefix.$table))

			{

			{

				$this->write_query("DROP TABLE {$table_prefix}{$table}");
}
} else {
$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}");

		}


		}


		$this->table_prefix = $table_prefix_bak;

if(!empty($fields)) {
foreach ($fields as &$field) {
$field = "{$table_prefix}{$table}_{$field}_seq";

		$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', '>=')) {

			unset($field);

if (version_compare($this->get_version(), '8.2.0', '>=')) {

Zeile 538Zeile 501
				while ($row = $this->fetch_array($query)) {
$this->write_query("DROP SEQUENCE {$row['field']}");
}

				while ($row = $this->fetch_array($query)) {
$this->write_query("DROP SEQUENCE {$row['field']}");
}

			}
}

			}
}

	}

public function rename_table($old_table, $new_table, $table_prefix = true)
{
if ($table_prefix == false) {
$table_prefix = "";

	}

public function rename_table($old_table, $new_table, $table_prefix = true)
{
if ($table_prefix == false) {
$table_prefix = "";

		} else {

		} else {

			$table_prefix = $this->table_prefix;
}

			$table_prefix = $this->table_prefix;
}





		return $this->write_query("ALTER TABLE {$table_prefix}{$old_table} RENAME TO {$table_prefix}{$new_table}");
}

		return $this->write_query("ALTER TABLE {$table_prefix}{$old_table} RENAME TO {$table_prefix}{$new_table}");
}





	public function replace_query($table, $replacements = array(), $default_field = "", $insert_id = true)
{
global $mybb;

	public function replace_query($table, $replacements = array(), $default_field = "", $insert_id = true)
{
global $mybb;

Zeile 563Zeile 526
		} else {
$main_field = $default_field;
}

		} else {
$main_field = $default_field;
}


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

 

if (!is_array($main_field)) {
$main_field = array($main_field);


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) {
return $this->update_query($table, $replacements, $search_bit);
} else {
return $this->insert_query($table, $replacements);
}












































		}

if(version_compare($this->get_version(), '9.5.0', '>='))
{
// ON CONFLICT clause supported

$main_field_csv = implode(',', $main_field);

// INSERT-like list of fields and values
$fields = implode(",", array_keys($replacements));
$values = $this->build_value_string($table, $replacements);

// UPDATE-like SET list, using special EXCLUDED table to avoid passing values twice
$reassignment_values = array();
$true_replacement_keys = array_diff(
array_keys($replacements),
array_flip($main_field)
);
foreach($true_replacement_keys as $key)
{
$reassignment_values[$key] = 'EXCLUDED.' . $key;
}

$reassignments = $this->build_field_value_string($table, $reassignment_values, true);

$this->write_query("
INSERT
INTO {$this->table_prefix}{$table} ({$fields})
VALUES ({$values})
ON CONFLICT ($main_field_csv) DO UPDATE SET {$reassignments}
");
}
else
{
// manual SELECT and UPDATE/INSERT (prone to TOCTOU issues)

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

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) {
return $this->update_query($table, $replacements, $search_bit);
} else {
return $this->insert_query($table, $replacements);
}
}

	}

public function drop_column($table, $column)

	}

public function drop_column($table, $column)

Zeile 606Zeile 609
	public function modify_column($table, $column, $new_definition, $new_not_null = false, $new_default_value = false)
{
$result1 = $result2 = $result3 = true;

	public function modify_column($table, $column, $new_definition, $new_not_null = false, $new_default_value = 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}");
}

		if ($new_definition !== false) {
$result1 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} TYPE {$new_definition}");
}

Zeile 630Zeile 633
		}

return $result1 && $result2 && $result3;

		}

return $result1 && $result2 && $result3;

	}

	}


public function rename_column($table, $old_column, $new_column, $new_definition, $new_not_null = false, $new_default_value = false)
{


public function rename_column($table, $old_column, $new_column, $new_definition, $new_not_null = false, $new_default_value = false)
{

Zeile 649Zeile 652
		}

if (null === $query) {

		}

if (null === $query) {

			return 0;
}

$result = $this->fetch_array($query, PDO::FETCH_NUM);


			return 0;
}

$result = $this->fetch_array($query, PDO::FETCH_NUM);


		if (false === $result) {
return 0;
}

		if (false === $result) {
return 0;
}

Zeile 669Zeile 672
	public function fetch_charset_collation($charset)
{
return false;

	public function fetch_charset_collation($charset)
{
return false;

	}


	}


	public function build_create_table_collation()
{
return '';
}

public function insert_id()

	public function build_create_table_collation()
{
return '';
}

public function insert_id()

	{

	{

		try {
return $this->write_link->lastInsertId();
} catch (PDOException $e) {
// in order to behave the same way as the MySQL driver, we return false if there is no last insert ID
return false;

		try {
return $this->write_link->lastInsertId();
} catch (PDOException $e) {
// in order to behave the same way as the MySQL driver, we return false if there is no last insert ID
return false;

		}
}


		}
}


	public function escape_binary($string)
{
$hex = bin2hex($string);

	public function escape_binary($string)
{
$hex = bin2hex($string);

Zeile 693Zeile 696
	}

public function unescape_binary($string)

	}

public function unescape_binary($string)

	{

	{

		// binary fields are treated as streams
/** @var resource $string */
return fgets($string);

		// binary fields are treated as streams
/** @var resource $string */
return fgets($string);

Zeile 701Zeile 704

/**
* @param string $table


/**
* @param string $table

	 * @param string $append


























































	 * @param string $append
*
* @return string
*/
public function build_fields_string($table, $append="")
{
$fields = $this->show_fields_from($table);
$comma = $fieldstring = '';

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

return $fieldstring;
}

/**
* @param string $table
* @param array $array
* @param bool $no_quote
*
* @return string
*/
protected function build_field_value_string($table, $array, $no_quote = false)
{
global $mybb;

$strings = array();

if ($no_quote == true)
{
$quote = "";
}
else
{
$quote = "'";
}

foreach($array as $field => $value)
{
if(!isset($mybb->binary_fields[$table][$field]) || !$mybb->binary_fields[$table][$field])
{
$value = $this->quote_val($value, $quote);
}

$strings[] = "{$field}={$value}";
}

$string = implode(', ', $strings);

return $string;
}

/**
* @param string $table
* @param array $array

	 *
* @return string
*/

	 *
* @return string
*/

	public function build_fields_string($table, $append="")

	protected function build_value_string($table, $array)

	{

	{

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

foreach($fields as $key => $field)


		global $mybb;

$values = array();

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

		{

		{

			$fieldstring .= "{$comma}{$append}{$field['Field']}";
$comma = ',';





			if(!isset($mybb->binary_fields[$table][$field]) || !$mybb->binary_fields[$table][$field])
{
$value = $this->quote_val($value);
}

$values[$field] = $value;

		}


		}


		return $fieldstring;



		$string = implode(",", $values);

return $string;

	}

public function __set($name, $value)

	}

public function __set($name, $value)