Vergleich inc/db_pgsql_pdo.php - 1.8.30 - 1.8.37

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

class PostgresPdoDbDriver extends AbstractPdoDbDriver
{


class PostgresPdoDbDriver extends AbstractPdoDbDriver
{

 
	/**
* The title of this layer.
*
* @var string
*/
public $title = "PostgreSQL (PDO)";

/**
* The short title of this layer.
*
* @var string
*/
public $short_title = "PostgreSQL (PDO)";


	/**
* Explanation of a query.
*

	/**
* Explanation of a query.
*

Zeile 162Zeile 176
		}

return $this->query($query);

		}

return $this->query($query);

	}

	}


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("
INSERT
INTO {$this->table_prefix}{$table} ({$fields})

		$this->write_query("
INSERT
INTO {$this->table_prefix}{$table} ({$fields})

Zeile 192Zeile 197
	}

private function quote_val($value, $quote = "'")

	}

private function quote_val($value, $quote = "'")

	{

	{

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

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





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

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

	}


	}


	public function insert_query_multiple($table, $array)
{

	public function insert_query_multiple($table, $array)
{

		global $mybb;


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

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

Zeile 214Zeile 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);

$this->write_query("

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

$this->write_query("

Zeile 239Zeile 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}";
}

$comma = ', ';

			return false;





















		}

		}

 

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


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


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

Zeile 402Zeile 379
		$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) {
$field['extra'] = 'auto_increment';
}

$field_info[] = array('Extra' => $field['extra'], 'Field' => $field['field']);
}

























			if ($field['column_name'] == $primary_key) {
$field['_key'] = 'PRI';
} else {
$field['_key'] = '';
}

if (!is_null($field['column_default']) && 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(
'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 442Zeile 443
		$this->error_reporting = $err;

return (bool)$exists;

		$this->error_reporting = $err;

return (bool)$exists;

	}


	}


	public function supports_fulltext_boolean($table)

	public function supports_fulltext_boolean($table)

	{
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 463Zeile 464
	}

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

	}

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

	{

	{

		if ($table_prefix == false) {
$table_prefix = "";
} else {
$table_prefix = $this->table_prefix;
}

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

Zeile 479Zeile 484
			$this->write_query("DROP TABLE {$table_prefix}{$table}");
}


			$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');

		$this->table_prefix = $table_prefix_bak;






		if ($field) {
$this->write_query('DROP SEQUENCE {$table}_{$field}_id_seq');















		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']}");
}
}

		}
}


		}
}


Zeile 496Zeile 514
		}

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)
{


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

Zeile 507Zeile 525
			$main_field = $this->fetch_field($query, 'column_name');
} else {
$main_field = $default_field;

			$main_field = $this->fetch_field($query, 'column_name');
} 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];

























































		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 {

			} else {

				$search_bit[] = "{$field} = ".$this->quote_val($replacements[$field]);

				return $this->insert_query($table, $replacements);

			}

			}

		}

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

 
		}
}


		}
}


Zeile 662Zeile 720
		}

return $fieldstring;

		}

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
*/
protected function build_value_string($table, $array)
{
global $mybb;

$values = array();

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

$values[$field] = $value;
}

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

return $string;

	}

public function __set($name, $value)

	}

public function __set($name, $value)