Vergleich inc/db_pgsql.php - 1.8.12 - 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 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 194Zeile 209
			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;
}


				$connections[$type][] = $details;
}


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

				{

				{

					$this->connect_string .= " port={$single_connection['port']}";

					$this->connect_string .= " port={$single_connection['port']}";

				}

				}


if($single_connection['hostname'] != "")


if($single_connection['hostname'] != "")

				{

				{

					$this->connect_string .= " host={$single_connection['hostname']}";

					$this->connect_string .= " host={$single_connection['hostname']}";

				}

				}


if($single_connection['password'])
{


if($single_connection['password'])
{

Zeile 239Zeile 258

$time_spent = get_execution_time();
$this->query_time += $time_spent;


$time_spent = get_execution_time();
$this->query_time += $time_spent;





				// Successful connection? break down brother!
if($this->$link)
{

				// Successful connection? break down brother!
if($this->$link)
{

Zeile 278Zeile 297

/**
* Query the database.


/**
* Query the database.

	 *
* @param string $string The query SQL.

	 *
* @param string $string The query SQL.

	 * @param boolean|int $hide_errors 1 if hide errors, 0 if not.
* @param integer $write_query 1 if executes on slave database, 0 if not.
* @return resource The query data.

	 * @param boolean|int $hide_errors 1 if hide errors, 0 if not.
* @param integer $write_query 1 if executes on slave database, 0 if not.
* @return resource The query data.

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 319Zeile 338
		}

if((pg_result_error($query) && !$hide_errors))

		}

if((pg_result_error($query) && !$hide_errors))

		{

		{

			$this->error($string, $query);
exit;
}

			$this->error($string, $query);
exit;
}

Zeile 378Zeile 397
					"</tr>\n";
}
$this->explain .=

					"</tr>\n";
}
$this->explain .=

				"<tr>\n".

				"<tr>\n".

				"<td colspan=\"8\" style=\"background-color: #fff;\">Query Time: ".format_time_duration($qtime)."</td>\n".
"</tr>\n".
"</table>\n".

				"<td colspan=\"8\" style=\"background-color: #fff;\">Query Time: ".format_time_duration($qtime)."</td>\n".
"</tr>\n".
"</table>\n".

Zeile 421Zeile 440
			default:
$resulttype = PGSQL_ASSOC;
break;

			default:
$resulttype = PGSQL_ASSOC;
break;

		}


		}


		$array = pg_fetch_array($query, NULL, $resulttype);

return $array;

		$array = pg_fetch_array($query, NULL, $resulttype);

return $array;

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

	 * Moves internal row pointer to the next row

	 *
* @param resource $query The query ID.

	 *
* @param resource $query The query ID.

	 * @param int $row The pointer to move the row to.
* @return bool

	 * @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 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];

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

		$table = $matches[1];

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

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

		{
return 0;
}


		{
return 0;
}


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

Zeile 559Zeile 578
	function error($string="", $query=null)
{
if($this->error_reporting)

	function error($string="", $query=null)
{
if($this->error_reporting)

		{

		{

			if(class_exists("errorHandler"))
{
global $error_handler;

			if(class_exists("errorHandler"))
{
global $error_handler;

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
{

		}
else
{

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 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 1165Zeile 1215
	 * @return boolean True or false if the table has a fulltext index or not.
*/
function is_fulltext($table, $index="")

	 * @return boolean True or false if the table has a fulltext index or not.
*/
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 1177Zeile 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 1194Zeile 1244

/**
* Creates a fulltext index on the specified column in the specified table with optional index name.


/**
* Creates a fulltext index on the specified column in the specified table with optional index name.

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

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

	 * @param string $column Name of the column to be indexed.
* @param string $name The index name, optional.
* @return bool

	 * @param string $column Name of the column to be indexed.
* @param string $name The index name, optional.
* @return bool

Zeile 1207Zeile 1257

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


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

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

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

	 * @param string $name The name of the index.
*/
function drop_index($table, $name)

	 * @param string $name The name of the index.
*/
function drop_index($table, $name)

Zeile 1237Zeile 1287
		$this->error_reporting = $err;

if($exists)

		$this->error_reporting = $err;

if($exists)

		{

		{

			return true;
}
else

			return true;
}
else

Zeile 1263Zeile 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 1335Zeile 1406
		$search_bit = array();

if(!is_array($main_field))

		$search_bit = array();

if(!is_array($main_field))

		{

		{

			$main_field = array($main_field);
}


			$main_field = array($main_field);
}


Zeile 1379Zeile 1450
		$comma = $fieldstring = '';

foreach($fields as $key => $field)

		$comma = $fieldstring = '';

foreach($fields as $key => $field)

		{

		{

			$fieldstring .= $comma.$append.$field['Field'];
$comma = ',';
}

return $fieldstring;

			$fieldstring .= $comma.$append.$field['Field'];
$comma = ',';
}

return $fieldstring;

	}

	}


/**
* Drops a column


/**
* Drops a column

Zeile 1401Zeile 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 1418Zeile 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 1436Zeile 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 1462Zeile 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 1556Zeile 1630
	 */
function escape_binary($string)
{

	 */
function escape_binary($string)
{

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

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

	}

/**

	}

/**