Vergleich inc/db_pgsql_pdo.php - 1.8.30 - 1.8.31

  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 17Zeile 31
	public $explain = '';

protected function getDsn($hostname, $db, $port, $encoding)

	public $explain = '';

protected function getDsn($hostname, $db, $port, $encoding)

	{

	{

		$dsn = "pgsql:host={$hostname};dbname={$db}";

if ($port !== null) {

		$dsn = "pgsql:host={$hostname};dbname={$db}";

if ($port !== null) {

Zeile 32Zeile 46
	}

public function query($string, $hideErrors = false, $writeQuery = false)

	}

public function query($string, $hideErrors = false, $writeQuery = false)

	{

	{

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

return parent::query($string, $hideErrors, $writeQuery);

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

return parent::query($string, $hideErrors, $writeQuery);

Zeile 68Zeile 82
				$this->explain .= <<<HTML
<tr style="background-color: #fff">
<td>{$table['QUERY PLAN']}</td>

				$this->explain .= <<<HTML
<tr style="background-color: #fff">
<td>{$table['QUERY PLAN']}</td>

	</tr>

	</tr>

HTML;
}

$this->explain .= <<<HTML
<tr>
<td colspan="8" style="background-color: #fff;">

HTML;
}

$this->explain .= <<<HTML
<tr>
<td colspan="8" style="background-color: #fff;">

			Query Time: {$duration}
</td>
</tr>
</table>
<br />
HTML;
} else {

			Query Time: {$duration}
</td>
</tr>
</table>
<br />
HTML;
} else {

			$this->explain .= <<<HTML
<table style="background-color: #666;" width="95%" cellpadding="4" cellspacing="1" align="center">
<tr>
<td style="background-color: #ccc;">
<strong>#{$this->query_count} - Write Query</strong>

			$this->explain .= <<<HTML
<table style="background-color: #666;" width="95%" cellpadding="4" cellspacing="1" align="center">
<tr>
<td style="background-color: #ccc;">
<strong>#{$this->query_count} - Write Query</strong>

		</td>
</tr>

		</td>
</tr>

	<tr style="background-color: #fefefe;">
<td>
<span style="font-family: Courier; font-size: 14px;">{$queryText}</span>

	<tr style="background-color: #fefefe;">
<td>
<span style="font-family: Courier; font-size: 14px;">{$queryText}</span>

Zeile 102Zeile 116
</table>
<br />
HTML;

</table>
<br />
HTML;

		}


		}


		$this->querylist[$this->query_count]['query'] = $string;
$this->querylist[$this->query_count]['time'] = $qtime;
}

public function list_tables($database, $prefix = '')

		$this->querylist[$this->query_count]['query'] = $string;
$this->querylist[$this->query_count]['time'] = $qtime;
}

public function list_tables($database, $prefix = '')

	{

	{

		if ($prefix) {
$query = $this->write_query("SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_name LIKE '{$this->escape_string($prefix)}%'");
} else {

		if ($prefix) {
$query = $this->write_query("SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_name LIKE '{$this->escape_string($prefix)}%'");
} else {

Zeile 125Zeile 139

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



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


		return $exists > 0;
}


		return $exists > 0;
}


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

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

return $exists > 0;

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

return $exists > 0;

	}

	}


public function simple_select($table, $fields = "*", $conditions = "", $options = array())
{
$query = "SELECT {$fields} FROM {$this->table_prefix}{$table}";
if ($conditions != "") {
$query .= " WHERE {$conditions}";


public function simple_select($table, $fields = "*", $conditions = "", $options = array())
{
$query = "SELECT {$fields} FROM {$this->table_prefix}{$table}";
if ($conditions != "") {
$query .= " WHERE {$conditions}";

		}

		}


if (isset($options['group_by'])) {
$query .= " GROUP BY {$options['group_by']}";


if (isset($options['group_by'])) {
$query .= " GROUP BY {$options['group_by']}";

Zeile 163Zeile 177

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


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





	public function insert_query($table, $array)
{
global $mybb;

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

	public function insert_query($table, $array)
{
global $mybb;

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

		}

		}


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


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

Zeile 182Zeile 196

$fields = implode(",", array_keys($array));
$values = implode(",", $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})

			VALUES ({$values})
");


			VALUES ({$values})
");


Zeile 402Zeile 416
		$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';
}









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





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

















			// 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 424Zeile 462
		return false;
}


		return false;
}


	public function supports_fulltext($table)
{
return false;
}


	public function supports_fulltext($table)
{
return false;
}


	public function index_exists($table, $index)
{
$err = $this->error_reporting;
$this->error_reporting = 0;

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

	public function index_exists($table, $index)
{
$err = $this->error_reporting;
$this->error_reporting = 0;

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





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

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





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

return (bool)$exists;

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

return (bool)$exists;

	}

	}


public function supports_fulltext_boolean($table)
{


public function supports_fulltext_boolean($table)
{

Zeile 469Zeile 507
		} 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 ($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 521
			$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']}");
}
}

		}
}


		}
}