Vergleich inc/db_pgsql.php - 1.8.24 - 1.8.37

  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 200Zeile 215

// Shuffle the connections
shuffle($connections[$type]);


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

Zeile 468Zeile 489
	 * @return int The number of rows in the result.
*/
function num_rows($query)

	 * @return int The number of rows in the result.
*/
function num_rows($query)

	{

	{

		return pg_num_rows($query);
}


		return pg_num_rows($query);
}


Zeile 494Zeile 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.

	 *

	 *

	 */
function close()
{

	 */
function close()
{

Zeile 511Zeile 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 521Zeile 542
		{
return 0;
}

		{
return 0;
}





		return pg_result_error_field($query, PGSQL_DIAG_SQLSTATE);
}


		return pg_result_error_field($query, PGSQL_DIAG_SQLSTATE);
}


Zeile 530Zeile 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 601Zeile 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 640Zeile 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 663Zeile 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 688Zeile 709
		if($name)
{
$shutdown_queries[$name] = $query;

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

		}
else

		}
else

		{
$shutdown_queries[] = $query;
}

		{
$shutdown_queries[] = $query;
}

Zeile 747Zeile 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 806Zeile 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 934Zeile 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
{

		}
else
{

Zeile 1117Zeile 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 1137Zeile 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 1161Zeile 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 1181Zeile 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 1219Zeile 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 1230Zeile 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 1257Zeile 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 1557Zeile 1630
	 */
function escape_binary($string)
{

	 */
function escape_binary($string)
{

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

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

	}

/**

	}

/**