Vergleich inc/db_pgsql.php - 1.4.2 - 1.4.10

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 6
 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/license.php
*

 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/license.php
*

 * $Id: db_pgsql.php 4067 2008-08-04 03:59:08Z Tikitiki $

 * $Id: db_pgsql.php 4436 2009-08-23 05:34:13Z RyanGordon $

 */

class DB_PgSQL

 */

class DB_PgSQL

Zeile 157Zeile 157
		{
$connections['read'][] = $config;
}

		{
$connections['read'][] = $config;
}

 
		else

		// Connecting to more than one server
{
// Specified multiple servers, but no specific read/write servers
if(!array_key_exists('read', $config))

		// Connecting to more than one server
{
// Specified multiple servers, but no specific read/write servers
if(!array_key_exists('read', $config))

			{

			{

				foreach($config as $key => $settings)
{
if(is_int($key)) $connections['read'][] = $settings;

				foreach($config as $key => $settings)
{
if(is_int($key)) $connections['read'][] = $settings;

Zeile 171Zeile 172
			else
{
$connections = $config;

			else
{
$connections = $config;

			}
}

$this->db_encoding = $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 208Zeile 209
				$this->get_execution_time();

$this->connect_string = "dbname={$single_connection['database']} user={$single_connection['username']}";

				$this->get_execution_time();

$this->connect_string = "dbname={$single_connection['database']} user={$single_connection['username']}";

				

				

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

Zeile 216Zeile 217

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'] != "localhost")

				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 243Zeile 244
				{
$this->connections[] = "<span style=\"color: red\">[FAILED] [".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']}</span>";
}

				{
$this->connections[] = "<span style=\"color: red\">[FAILED] [".strtoupper($type)."] {$single_connection['username']}@{$single_connection['hostname']}</span>";
}

			}
}


			}
}


		// No write server was specified (simple connection or just multiple servers) - mirror write link
if(!array_key_exists('write', $connections))

		// No write server was specified (simple connection or just multiple servers) - mirror write link
if(!array_key_exists('write', $connections))

		{

		{

			$this->write_link = &$this->read_link;

			$this->write_link = &$this->read_link;

		}

		}


// Have no read connection?
if(!$this->read_link)


// Have no read connection?
if(!$this->read_link)

		{

		{

			$this->error("[READ] Unable to connect to PgSQL server");
}
// No write?
else if(!$this->write_link)
{
$this->error("[WRITE] Unable to connect to PgSQL server");

			$this->error("[READ] Unable to connect to PgSQL server");
}
// No write?
else if(!$this->write_link)
{
$this->error("[WRITE] Unable to connect to PgSQL server");

		}


		}


		$this->current_link = &$this->read_link;
return $this->read_link;
}

		$this->current_link = &$this->read_link;
return $this->read_link;
}

Zeile 288Zeile 289
		if(strtolower(substr(ltrim($string), 0, 5)) == 'alter')
{
$string = preg_replace("#\sAFTER\s([a-z_]+?)(;*?)$#i", "", $string);

		if(strtolower(substr(ltrim($string), 0, 5)) == 'alter')
{
$string = preg_replace("#\sAFTER\s([a-z_]+?)(;*?)$#i", "", $string);

 
			if(strstr($string, 'CHANGE') !== false)
{
$string = str_replace(' CHANGE ', ' ALTER ', $string);
}

		}

if($write_query && $this->write_link)

		}

if($write_query && $this->write_link)

Zeile 296Zeile 301
			$this->current_link = &$this->write_link;
pg_send_query($this->current_link, $string);
$query = pg_get_result($this->current_link);

			$this->current_link = &$this->write_link;
pg_send_query($this->current_link, $string);
$query = pg_get_result($this->current_link);

		}

		}

		else
{
while(pg_connection_busy($this->read_link));

		else
{
while(pg_connection_busy($this->read_link));

Zeile 704Zeile 709
		if(isset($options['limit_start']) && isset($options['limit']))
{
$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];

		if(isset($options['limit_start']) && isset($options['limit']))
{
$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];

		}
else if(isset($options['limit']))
{

		}
else if(isset($options['limit']))
{

			$query .= " LIMIT ".$options['limit'];
}

return $this->query($query);

			$query .= " LIMIT ".$options['limit'];
}

return $this->query($query);

	}

/**
* Build an insert query from an array.
*
* @param string The table name to perform the query on.
* @param array An array of fields and their values.
* @return int The insert ID if available
*/
function insert_query($table, $array)
{
if(!is_array($array))
{
return false;


	}

/**
* Build an insert query from an array.
*
* @param string The table name to perform the query on.
* @param array An array of fields and their values.
* @param boolean Whether or not to return an insert id. True by default
* @return int The insert ID if available
*/
function insert_query($table, $array, $insert_id=true)
{
if(!is_array($array))
{
return false;

		}
$fields = implode(",", array_keys($array));
$values = implode("','", $array);

		}
$fields = implode(",", array_keys($array));
$values = implode("','", $array);

Zeile 733Zeile 739
			INTO {$this->table_prefix}{$table} (".$fields.") 
VALUES ('".$values."')
");

			INTO {$this->table_prefix}{$table} (".$fields.") 
VALUES ('".$values."')
");

		return $this->insert_id();









		
if($insert_id != false)
{
return $this->insert_id();
}
else
{
return true;
}

	}

/**

	}

/**

Zeile 742Zeile 756
	 * @param string The table name to perform the query on.
* @param array An array of inserts.
* @return int The insert ID if available

	 * @param string The table name to perform the query on.
* @param array An array of inserts.
* @return int The insert ID if available

	 */

	 */

	function insert_query_multiple($table, $array)
{
if(!is_array($array))

	function insert_query_multiple($table, $array)
{
if(!is_array($array))

Zeile 759Zeile 773
			$insert_rows[] = "('".implode("','", $values)."')";
}
$insert_rows = implode(", ", $insert_rows);

			$insert_rows[] = "('".implode("','", $values)."')";
}
$insert_rows = implode(", ", $insert_rows);





		$this->write_query("
INSERT
INTO {$this->table_prefix}{$table} ({$fields})

		$this->write_query("
INSERT
INTO {$this->table_prefix}{$table} ({$fields})

Zeile 793Zeile 807
		return "INSERT 
INTO ".TABLE_PREFIX.$table." (".$query1.")
VALUES (".$query2.")";

		return "INSERT 
INTO ".TABLE_PREFIX.$table." (".$query1.")
VALUES (".$query2.")";

	}

	}


/**
* Build an update query from an array.


/**
* Build an update query from an array.

Zeile 805Zeile 819
	 * @return resource The query data.
*/
function update_query($table, $array, $where="", $limit="")

	 * @return resource The query data.
*/
function update_query($table, $array, $where="", $limit="")

	{
if(!is_array($array))
{
return false;
}
$comma = "";

	{
if(!is_array($array))
{
return false;
}
$comma = "";

		$query = "";
foreach($array as $field => $value)
{

		$query = "";
foreach($array as $field => $value)
{

Zeile 844Zeile 858
		}

$comma = "";

		}

$comma = "";

		$query = "";

		$query = "";

		foreach($array as $field => $value)
{
$query .= $comma.$field."='".$value."'";

		foreach($array as $field => $value)
{
$query .= $comma.$field."='".$value."'";

Zeile 937Zeile 951
		{
$version = pg_version($this->current_link);


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


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

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

		}
else
{

		}
else
{

Zeile 957Zeile 971
	 */
function optimize_table($table)
{

	 */
function optimize_table($table)
{

		$this->write_query("OPTIMIZE TABLE ".$this->table_prefix.$table."");

		$this->write_query("VACUUM ".$this->table_prefix.$table."");

	}

/**

	}

/**

Zeile 967Zeile 981
	 */
function analyze_table($table)
{

	 */
function analyze_table($table)
{

		$this->write_query("ANALYZE TABLE ".$this->table_prefix.$table."");

		$this->write_query("ANALYZE ".$this->table_prefix.$table."");

	}

/**

	}

/**

Zeile 988Zeile 1002
		");

$lines = array();

		");

$lines = array();

		$lines[] = "CREATE TABLE {$this->table_prefix}{$table} (\n";

		$table_lines = "CREATE TABLE {$this->table_prefix}{$table} (\n";

		
while($row = $this->fetch_array($query))
{

		
while($row = $this->fetch_array($query))
{

Zeile 1072Zeile 1086
			$lines[] = "  CONSTRAINT $primary_key_name PRIMARY KEY (".implode(', ', $primary_key).")";
}


			$lines[] = "  CONSTRAINT $primary_key_name PRIMARY KEY (".implode(', ', $primary_key).")";
}


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

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

		

		

		return $table;

		return $table_lines;

	}

/**

	}

/**

Zeile 1121Zeile 1135

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


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

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

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


function supports_fulltext($table)
{


function supports_fulltext($table)
{

Zeile 1138Zeile 1152
	 * @return boolean True or false if supported or not.
*/
function supports_fulltext_boolean($table)

	 * @return boolean True or false if supported or not.
*/
function supports_fulltext_boolean($table)

	{
return false;
}


	{
return false;
}


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

Zeile 1156Zeile 1170

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


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

	 *
* @param string The name of the table.
* @param string The name of the index.
*/

	 *
* @param string The name of the table.
* @param string The name of the index.
*/

	function drop_index($table, $name)

	function drop_index($table, $name)

	{

	{

		$this->write_query("
ALTER TABLE {$this->table_prefix}$table
DROP INDEX $name
");

		$this->write_query("
ALTER TABLE {$this->table_prefix}$table
DROP INDEX $name
");

 
	}

/**
* Checks to see if an index exists on a specified table
*
* @param string The name of the table.
* @param string The name of the index.
*/
function index_exists($table, $index)
{
$err = $this->error_reporting;
$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;
}
else
{
return false;
}

	}

/**

	}

/**

Zeile 1191Zeile 1231
			if($this->table_exists($table))
{
$this->write_query('DROP TABLE '.$table_prefix.$table);

			if($this->table_exists($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);
}
}

Zeile 1204Zeile 1244
	 *
* @param string The table
* @param array The replacements

	 *
* @param string The table
* @param array The replacements

 
	 * @param string The default field
* @param boolean Whether or not to return an insert id. True by default

	 */

	 */

	function replace_query($table, $replacements=array(), $default_field="")

	function replace_query($table, $replacements=array(), $default_field="", $insert_id=true)

	{
$i = 0;

	{
$i = 0;

		
if($default_field == "")
{
$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");
$main_field = $this->fetch_field($query, 'column_name');
}
else
{
$main_field = $default_field;
}

$query = $this->write_query("SELECT {$main_field} FROM {$this->table_prefix}{$table}");

while($column = $this->fetch_array($query))
{
if($column[$main_field] == $replacements[$main_field])
{
++$i;
}
}

if($i > 0)



		
if($default_field == "")
{
$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");
$main_field = $this->fetch_field($query, 'column_name');
}
else
{
$main_field = $default_field;
}

$update = false;
$query = $this->write_query("SELECT {$main_field} FROM {$this->table_prefix}{$table}");

while($column = $this->fetch_array($query))
{
if($column[$main_field] == $replacements[$main_field])
{
$update = true;
break;
}
}

if($update === true)

		{
return $this->update_query($table, $replacements, "{$main_field}='".$replacements[$main_field]."'");

		{
return $this->update_query($table, $replacements, "{$main_field}='".$replacements[$main_field]."'");

		}

		}

		else
{

		else
{

			return $this->insert_query($table, $replacements);

			return $this->insert_query($table, $replacements, $insert_id);

		}
}


		}
}


Zeile 1246Zeile 1290
	 * @param array The replacements
*/
function build_replace_query($table, $replacements=array(), $default_field="")

	 * @param array The replacements
*/
function build_replace_query($table, $replacements=array(), $default_field="")

	{
$i = 0;

	{	


		
if($default_field == "")
{

		
if($default_field == "")
{

Zeile 1259Zeile 1302
			$main_field = $default_field;
}


			$main_field = $default_field;
}


 
		$update = false;

		$query = $this->write_query("SELECT {$main_field} FROM {$this->table_prefix}{$table}");

while($column = $this->fetch_array($query))
{
if($column[$main_field] == $replacements[$main_field])
{

		$query = $this->write_query("SELECT {$main_field} FROM {$this->table_prefix}{$table}");

while($column = $this->fetch_array($query))
{
if($column[$main_field] == $replacements[$main_field])
{

				++$i;


				$update = true;
break;

			}
}


			}
}


		if($i > 0)

		if($update === true)

		{
return $this->build_update_query($table, $replacements, "{$main_field}='".$replacements[$main_field]."'");
}

		{
return $this->build_update_query($table, $replacements, "{$main_field}='".$replacements[$main_field]."'");
}