Vergleich inc/db_pgsql.php - 1.8.10 - 1.8.36

  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 65Zeile 72
	 * @var resource
*/
public $current_link;

	 * @var resource
*/
public $current_link;

 

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


/**
* Explanation of a query.


/**
* Explanation of a query.

	 *
* @var string
*/

	 *
* @var string
*/

	public $explain;

	public $explain;


/**


/**

	 * The current version of PgSQL.

	 * The current version of PgSQL.

	 *

	 *

	 * @var string
*/
public $version;

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

	 * @var string
*/
public $version;

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

	 *
* @var string

	 *
* @var string

	 */
public $table_type = "myisam";

/**
* The table prefix used for simple select, update, insert and delete queries

	 */
public $table_type = "myisam";

/**
* The table prefix used for simple select, update, insert and delete queries

	 *
* @var string

	 *
* @var string

	 */
public $table_prefix;

	 */
public $table_prefix;





	/**
* The temperary connection string used to store connect details

	/**
* The temperary connection string used to store connect details

	 *
* @var string
*/

	 *
* @var string
*/

	public $connect_string;

	public $connect_string;


/**


/**

	 * The last query run on the database
*
* @var string

	 * The last query run on the database
*
* @var string

Zeile 110Zeile 122

/**
* The current value of pconnect (0/1).


/**
* The current value of pconnect (0/1).

	 *
* @var string

	 *
* @var string

	 */
public $pconnect;

	 */
public $pconnect;





	/**
* The engine used to run the SQL database

	/**
* The engine used to run the SQL database

	 *

	 *

	 * @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 133Zeile 145
	 * The database encoding currently in use (if supported)
*
* @var string

	 * The database encoding currently in use (if supported)
*
* @var string

	 */

	 */

	public $db_encoding = "utf8";

/**

	public $db_encoding = "utf8";

/**

Zeile 181Zeile 193
			}
}


			}
}


		$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 288Zeile 307
	{
global $mybb;


	{
global $mybb;


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

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


$this->last_query = $string;



$this->last_query = $string;


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

	}

/**

	}

/**

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 901Zeile 920
		}

return $quoted;

		}

return $quoted;

	}


	}


	/**
* Build a delete query.
*

	/**
* Build a delete query.
*

Zeile 923Zeile 942
			DELETE
FROM {$this->table_prefix}$table
$query

			DELETE
FROM {$this->table_prefix}$table
$query

		");
}

		");
}


/**
* Escape a string according to the pg escape format.


/**
* Escape a string according to the pg escape format.

Zeile 935Zeile 954
	function escape_string($string)
{
if(function_exists("pg_escape_string"))

	function escape_string($string)
{
if(function_exists("pg_escape_string"))

		{
$string = pg_escape_string($string);

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

		}
else
{

		}
else
{

Zeile 947Zeile 966

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


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

	 *

	 *

	 * @param resource $query The query to destroy.
* @return boolean Returns true on success, false on failure
*/

	 * @param resource $query The query to destroy.
* @return boolean Returns true on success, false on failure
*/

Zeile 964Zeile 983
	 */
function escape_string_like($string)
{

	 */
function escape_string_like($string)
{

		return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string));

		return $this->escape_string(str_replace(array('\\', '%', '_') , array('\\\\', '\\%' , '\\_') , $string));

	}

/**

	}

/**

Zeile 1035Zeile 1054
				LEFT JOIN pg_class c ON (c.oid = d.adrelid)
WHERE c.relname = '{$this->table_prefix}{$table}' AND d.adnum = '{$row['attnum']}'
");

				LEFT JOIN pg_class c ON (c.oid = d.adrelid)
WHERE c.relname = '{$this->table_prefix}{$table}' AND d.adnum = '{$row['attnum']}'
");





			if(!$query2)
{
unset($row['rowdefault']);

			if(!$query2)
{
unset($row['rowdefault']);

Zeile 1077Zeile 1096
			}

$lines[] = $line;

			}

$lines[] = $line;

		}


		}


		// Get the listing of primary keys.
$query = $this->write_query("
SELECT ic.relname as index_name, bc.relname as tab_name, ta.attname as column_name, i.indisunique as unique_key, i.indisprimary as primary_key

		// Get the listing of primary keys.
$query = $this->write_query("
SELECT ic.relname as index_name, bc.relname as tab_name, ta.attname as column_name, i.indisunique as unique_key, i.indisprimary as primary_key

Zeile 1093Zeile 1112

$primary_key = array();
$primary_key_name = '';


$primary_key = array();
$primary_key_name = '';

 

$unique_keys = array();


// We do this in two steps. It makes placing the comma easier
while($row = $this->fetch_array($query))


// We do this in two steps. It makes placing the comma easier
while($row = $this->fetch_array($query))

Zeile 1101Zeile 1122
			{
$primary_key[] = $row['column_name'];
$primary_key_name = $row['index_name'];

			{
$primary_key[] = $row['column_name'];
$primary_key_name = $row['index_name'];

 
			}

if($row['unique_key'] == 't')
{
$unique_keys[$row['index_name']][] = $row['column_name'];

			}
}

if(!empty($primary_key))
{
$lines[] = " CONSTRAINT $primary_key_name PRIMARY KEY (".implode(', ', $primary_key).")";

			}
}

if(!empty($primary_key))
{
$lines[] = " CONSTRAINT $primary_key_name PRIMARY KEY (".implode(', ', $primary_key).")";

 
		}

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

		}

$table_lines .= implode(", \n", $lines);

		}

$table_lines .= implode(", \n", $lines);

Zeile 1122Zeile 1153
	 * @return array Field info for that table
*/
function show_fields_from($table)

	 * @return array Field info for that table
*/
function show_fields_from($table)

	{

	{

		$query = $this->write_query("SELECT column_name FROM information_schema.constraint_column_usage WHERE table_name = '{$this->table_prefix}{$table}' and constraint_name = '{$this->table_prefix}{$table}_pkey' LIMIT 1");
$primary_key = $this->fetch_field($query, 'column_name');

		$query = $this->write_query("SELECT column_name FROM information_schema.constraint_column_usage WHERE table_name = '{$this->table_prefix}{$table}' and constraint_name = '{$this->table_prefix}{$table}_pkey' LIMIT 1");
$primary_key = $this->fetch_field($query, 'column_name');





		$query = $this->write_query("

		$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 1147Zeile 1209

/**
* Returns whether or not the table contains a fulltext index.


/**
* Returns whether or not the table contains a fulltext index.

	 *
* @param string $table The name of the table.

	 *
* @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 $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 1165Zeile 1227
	 */

function supports_fulltext($table)

	 */

function supports_fulltext($table)

	{
return false;
}

/**

	{
return false;
}

/**

	 * Returns whether or not this database engine supports boolean fulltext matching.
*
* @param string $table The table to be checked.

	 * Returns whether or not this database engine supports boolean fulltext matching.
*
* @param string $table The table to be checked.

Zeile 1191Zeile 1253
	function create_fulltext_index($table, $column, $name="")
{
return false;

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

	}

	}


/**
* Drop an index with the specified name from the specified table


/**
* Drop an index with the specified name from the specified table

Zeile 1213Zeile 1275
	 * @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

	 */

	 */

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

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

Zeile 1251Zeile 1313
		{
$table_prefix = $this->table_prefix;
}

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

		}
else

		{

		{

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

// 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 1280Zeile 1363
	 * @param string $old_table The old table name
* @param string $new_table the new table name
* @param boolean $table_prefix use table prefix

	 * @param string $old_table The old table name
* @param string $new_table the new table name
* @param boolean $table_prefix use table prefix

	 * @return resource
*/

	 * @return resource
*/

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

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

Zeile 1346Zeile 1429
		}

if($update === true)

		}

if($update === true)

		{

		{

			return $this->update_query($table, $replacements, $search_bit);
}
else

			return $this->update_query($table, $replacements, $search_bit);
}
else

Zeile 1389Zeile 1472

/**
* Adds a column


/**
* Adds a column

	 *

	 *

	 * @param string $table The table
* @param string $column The column name
* @param string $definition the new column definition

	 * @param string $table The table
* @param string $column The column name
* @param string $definition the new column definition

Zeile 1406Zeile 1489
	 * @param string $table The table
* @param string $column The column name
* @param string $new_definition the new column definition

	 * @param string $table The table
* @param string $column The column name
* @param string $new_definition the new column definition

	 * @param boolean $new_not_null Whether to drop or set a column
* @param boolean $new_default_value The new default value (if one is to be set)

	 * @param boolean|string $new_not_null Whether to "drop" or "set" the NOT NULL attribute (no change if false)
* @param boolean|string $new_default_value The new default value, or false to drop the attribute

	 * @return bool Returns true if all queries are executed successfully or false if one of them failed
*/
function modify_column($table, $column, $new_definition, $new_not_null=false, $new_default_value=false)
{
$result1 = $result2 = $result3 = true;

	 * @return bool Returns true if all queries are executed successfully or false if one of them failed
*/
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 1424Zeile 1507
			$set_drop = "DROP";

if(strtolower($new_not_null) == "set")

			$set_drop = "DROP";

if(strtolower($new_not_null) == "set")

			{

			{

				$set_drop = "SET";

				$set_drop = "SET";

			}


			}


			$result2 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} {$set_drop} NOT NULL");
}


			$result2 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} {$set_drop} NOT NULL");
}


		if($new_default_value !== false)

		if($new_default_value !== null)

		{

		{

			$result3 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} SET DEFAULT {$new_default_value}");
}
else
{
$result3 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} DROP DEFAULT");




			if($new_default_value !== false)
{
$result3 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} SET DEFAULT {$new_default_value}");
}
else
{
$result3 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} DROP DEFAULT");
}

		}

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

		}

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

Zeile 1450Zeile 1536
	 * @param string $old_column The old column name
* @param string $new_column the new column name
* @param string $new_definition the new column definition

	 * @param string $old_column The old column name
* @param string $new_column the new column name
* @param string $new_definition the new column definition

	 * @param boolean $new_not_null Whether to drop or set a column
* @param boolean $new_default_value The new default value (if one is to be set)

	 * @param boolean|string $new_not_null Whether to "drop" or "set" the NOT NULL attribute (no change if false)
* @param boolean|string $new_default_value The new default value, or false to drop the attribute

	 * @return bool Returns true if all queries are executed successfully
*/
function rename_column($table, $old_column, $new_column, $new_definition, $new_not_null=false, $new_default_value=false)

	 * @return bool Returns true if all queries are executed successfully
*/
function rename_column($table, $old_column, $new_column, $new_definition, $new_not_null=false, $new_default_value=false)

Zeile 1544Zeile 1630
	 */
function escape_binary($string)
{

	 */
function escape_binary($string)
{

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

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

	}

/**

	}

/**