Vergleich inc/db_pgsql.php - 1.8.22 - 1.8.33

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 23Zeile 23
	 * @var string
*/
public $short_title = "PostgreSQL";

	 * @var string
*/
public $short_title = "PostgreSQL";

 

/**
* The type of db software being used.
*
* @var string
*/
public $type;


/**
* A count of the number of queries.


/**
* A count of the number of queries.

Zeile 44Zeile 51
	 * @var boolean
*/
public $error_reporting = 1;

	 * @var boolean
*/
public $error_reporting = 1;





	/**
* The read database connection resource.

	/**
* The read database connection resource.

	 *
* @var resource

	 *
* @var resource

	 */
public $read_link;

	 */
public $read_link;


/**


/**

	 * The write database connection resource

	 * The write database connection resource

	 *
* @var resource
*/

	 *
* @var resource
*/

	public $write_link;

/**
* Reference to the last database connection resource used.

	public $write_link;

/**
* Reference to the last database connection resource used.

	 *
* @var resource
*/

	 *
* @var resource
*/

	public $current_link;

	public $current_link;


/**







/**
* @var array
*/
public $connections = array();

/**

	 * Explanation of a query.

	 * Explanation of a query.

	 *

	 *

	 * @var string
*/
public $explain;

	 * @var string
*/
public $explain;


/**


/**

	 * The current version of PgSQL.
*
* @var string

	 * The current version of PgSQL.
*
* @var string

Zeile 82Zeile 94

/**
* The current table type in use (myisam/innodb)


/**
* The current table type in use (myisam/innodb)

	 *
* @var string

	 *
* @var string

	 */
public $table_type = "myisam";


	 */
public $table_type = "myisam";


Zeile 121Zeile 133
	 * @var string
*/
public $engine = "pgsql";

	 * @var string
*/
public $engine = "pgsql";


/**


/**

	 * Weather or not this engine can use the search functionality
*
* @var boolean

	 * Weather or not this engine can use the search functionality
*
* @var boolean

Zeile 178Zeile 190
			else
{
$connections = $config;

			else
{
$connections = $config;

			}
}

$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 204
			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 223
				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 234
				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 441Zeile 460
		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.
* @param int $row The pointer to move the row to.
* @return bool

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

	 */

	 */

	function data_seek($query, $row)
{
return pg_result_seek($query, $row);

	function data_seek($query, $row)
{
return pg_result_seek($query, $row);

	}

/**

	}

/**

	 * Return the number of rows resulting from a query.
*
* @param resource $query The query ID.

	 * Return the number of rows resulting from a query.
*
* @param resource $query The query ID.

Zeile 479Zeile 500
	 */
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 496Zeile 515

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


$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.
*

	/**
* Close the connection with the DBMS.
*

Zeile 513Zeile 532

/**
* Return an error number.


/**
* Return an error number.

	 *
* @param resource $query

	 *
* @param resource $query

	 * @return int The error number of the current error.
*/
function error_number($query=null)

	 * @return int The error number of the current error.
*/
function error_number($query=null)

Zeile 523Zeile 542
		{
return 0;
}

		{
return 0;
}





		return pg_result_error_field($query, PGSQL_DIAG_SQLSTATE);
}


		return pg_result_error_field($query, PGSQL_DIAG_SQLSTATE);
}


Zeile 532Zeile 551
	 *
* @param resource $query
* @return string The explanation for the current error.

	 *
* @param resource $query
* @return string The explanation for the current error.

	 */

	 */

	function error_string($query=null)
{
if($query != null)
{
return pg_result_error($query);

	function error_string($query=null)
{
if($query != null)
{
return pg_result_error($query);

		}


		}


		if($this->current_link)

		if($this->current_link)

		{

		{

			return pg_last_error($this->current_link);

			return pg_last_error($this->current_link);

		}

		}

		else
{
return pg_last_error();

		else
{
return pg_last_error();

		}
}

/**

		}
}

/**

	 * Output a database error.
*
* @param string $string The string to present as an error.

	 * Output a database error.
*
* @param string $string The string to present as an error.

Zeile 603Zeile 622
	function num_fields($query)
{
return pg_num_fields($query);

	function num_fields($query)
{
return pg_num_fields($query);

	}

/**

	}

/**

	 * Lists all tables in the database.
*
* @param string $database The database name.

	 * Lists all tables in the database.
*
* @param string $database The database name.

Zeile 642Zeile 661
	{
// 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;
}

	}

/**

	}

/**

Zeile 665Zeile 684
	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 true;
}
else
{

			return false;
}
}

			return false;
}
}

Zeile 690Zeile 709
		if($name)
{
$shutdown_queries[$name] = $query;

		if($name)
{
$shutdown_queries[$name] = $query;

		}
else

		}
else

		{
$shutdown_queries[] = $query;
}

		{
$shutdown_queries[] = $query;
}

Zeile 749Zeile 768
	 * @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;

	{
global $mybb;


if(!is_array($array))
{


if(!is_array($array))
{

Zeile 808Zeile 827

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

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

Zeile 846Zeile 865
		global $mybb;

if(!is_array($array))

		global $mybb;

if(!is_array($array))

		{

		{

			return false;
}


			return false;
}


Zeile 936Zeile 955
	{
if(function_exists("pg_escape_string"))
{

	{
if(function_exists("pg_escape_string"))
{

			$string = pg_escape_string($string);

			$string = pg_escape_string($this->read_link, $string);

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

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

	}

	}


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


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

Zeile 963Zeile 982
	 * @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 979Zeile 998
			return $this->version;
}


			return $this->version;
}


		$version = pg_version($this->current_link);


		$version = pg_version($this->current_link);


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

return $this->version;

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

return $this->version;

	}


	}


	/**
* Optimizes a specific table.
*

	/**
* Optimizes a specific table.
*

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

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

			}

			}


if($row['type'] == 'bpchar')


if($row['type'] == 'bpchar')

			{

			{

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

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

			}

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

			}

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


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


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

Zeile 1062Zeile 1081
			}

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

			}

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

			{

			{

				$line .= '('.sprintf("%s,%s", (($row['lengthvar'] >> 16) & 0xffff), (($row['lengthvar'] - 4) & 0xffff)).')';
}


				$line .= '('.sprintf("%s,%s", (($row['lengthvar'] >> 16) & 0xffff), (($row['lengthvar'] - 4) & 0xffff)).')';
}


Zeile 1119Zeile 1138
		foreach($unique_keys as $key_name => $key_columns)
{
$lines[] = " CONSTRAINT $key_name UNIQUE (".implode(', ', $key_columns).")";

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


Zeile 1139Zeile 1158
		$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)

			if($field['column_name'] == $primary_key)

			{

			{

				$field['extra'] = 'auto_increment';

























				$field['_key'] = 'PRI';
}
else
{
$field['_key'] = '';
}

if(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('Extra' => $field['extra'], 'Field' => $field['field']);








			$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 1163Zeile 1213
	 * @param string $table The name of the table.
* @param string $index Optionally specify the name of the index.
* @return boolean True or false if the table has a fulltext index or not.

	 * @param string $table The name of the table.
* @param string $index Optionally specify the name of the index.
* @return boolean True or false if the table has a fulltext index or not.

	 */

	 */

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

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

	{
return false;
}


	{
return false;
}


	/**
* Returns whether or not this database engine supports fulltext indexing.
*

	/**
* Returns whether or not this database engine supports fulltext indexing.
*

Zeile 1183Zeile 1233

/**
* Returns whether or not this database engine supports boolean fulltext matching.


/**
* Returns whether or not this database engine supports boolean fulltext matching.

	 *

	 *

	 * @param string $table The table to be checked.
* @return boolean True or false if supported or not.
*/

	 * @param string $table The table to be checked.
* @return boolean True or false if supported or not.
*/

Zeile 1221Zeile 1271

/**
* Checks to see if an index exists on a specified table


/**
* Checks to see if an index exists on a specified table

	 *

	 *

	 * @param string $table The name of the table.
* @param string $index The name of the index.
* @return bool Returns whether index exists

	 * @param string $table The name of the table.
* @param string $index The name of the index.
* @return bool Returns whether index exists

Zeile 1232Zeile 1282
		$this->error_reporting = 0;

$query = $this->write_query("SELECT * FROM pg_indexes WHERE tablename='".$this->escape_string($this->table_prefix.$table)."'");

		$this->error_reporting = 0;

$query = $this->write_query("SELECT * FROM pg_indexes WHERE tablename='".$this->escape_string($this->table_prefix.$table)."'");





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

if($exists)
{
return true;

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

if($exists)
{
return true;

		}
else
{

		}
else
{

			return false;
}
}

			return false;
}
}

Zeile 1259Zeile 1309
		{
$table_prefix = "";
}

		{
$table_prefix = "";
}

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

			}

			}

		}
else
{
$this->write_query('DROP TABLE '.$table_prefix.$table);
}


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

// Do we not have a primary field?
if($field)

		$this->table_prefix = $table_prefix_bak;

if(!empty($fields))



		{

		{

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




















			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 1559Zeile 1630
	 */
function escape_binary($string)
{

	 */
function escape_binary($string)
{

		return "'".pg_escape_bytea($string)."'";

		return "'".pg_escape_bytea($this->read_link, $string)."'";

	}

/**

	}

/**