Vergleich inc/db_pgsql.php - 1.4.0 - 1.4.14

  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 3902 2008-06-11 02:21:37Z 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'];


Zeile 204Zeile 205
				}

$link = $type."_link";

				}

$link = $type."_link";





				$this->get_execution_time();

				$this->get_execution_time();





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

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

				

				

				if(strpos($single_connection['hostname'], ':') !== false)

				if(strpos($single_connection['hostname'], ':') !== false)

				{

				{

					list($single_connection['hostname'], $single_connection['port']) = explode(':', $single_connection['hostname']);

					list($single_connection['hostname'], $single_connection['port']) = explode(':', $single_connection['hostname']);

				}

				}


if($single_connection['port'])
{


if($single_connection['port'])
{

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

if($single_connection['hostname'] != "localhost")
{
$this->connect_string .= "host={$single_connection['hostname']} ";

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

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

				}

if($single_connection['password'])

				}

if($single_connection['password'])

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 463Zeile 468
		
// Do we not have a primary field?
if(!$field)

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

		{

		{

			return;
}


			return;
}


Zeile 481Zeile 486
		if($this->write_link)
{
@pg_close($this->write_link);

		if($this->write_link)
{
@pg_close($this->write_link);

		}

		}

	}

/**

	}

/**

Zeile 518Zeile 523
		else
{
return pg_last_error();

		else
{
return pg_last_error();

		}		
}

		}		
}


/**
* Output a database error.


/**
* Output a database error.

Zeile 557Zeile 562

/**
* Returns the number of affected rows in a query.


/**
* Returns the number of affected rows in a query.

	 *

	 *

	 * @return int The number of affected rows.

	 * @return int The number of affected rows.

	 */

	 */

	function affected_rows()

	function affected_rows()

	{

	{

		return pg_affected_rows($this->current_link);

		return pg_affected_rows($this->current_link);

	}

/**

	}

/**

	 * Return the number of fields.
*
* @param resource The query ID.

	 * Return the number of fields.
*
* @param resource The query ID.

Zeile 574Zeile 579
	function num_fields($query)
{
return pg_num_fields($query);

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

	}

/**

	}

/**

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

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

Zeile 614Zeile 619
		$this->error_reporting = 0;

// Execute on slave server to ensure if we've just created a table that we get the correct result

		$this->error_reporting = 0;

// Execute on slave 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}'");


		$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');
$this->error_reporting = $err;


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


Zeile 647Zeile 652
		$this->error_reporting = $err;

if($exists > 0)

		$this->error_reporting = $err;

if($exists > 0)

		{
return true;
}
else
{
return false;
}

		{
return true;
}
else
{
return false;
}

	}

/**

	}

/**

Zeile 672Zeile 677
		else
{
$shutdown_queries[] = $query;

		else
{
$shutdown_queries[] = $query;

		}

		}

	}

	}

	

	

	/**
* Performs a simple select query.
*

	/**
* Performs a simple select query.
*

Zeile 690Zeile 695
		if($conditions != "")
{
$query .= " WHERE ".$conditions;

		if($conditions != "")
{
$query .= " WHERE ".$conditions;

		}


		}


		if(isset($options['order_by']))
{
$query .= " ORDER BY ".$options['order_by'];

		if(isset($options['order_by']))
{
$query .= " ORDER BY ".$options['order_by'];

Zeile 718Zeile 723
	 *
* @param string The table name to perform the query on.
* @param array An array of fields and their values.

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

	 * @return int The insert ID if available
*/

	function insert_query($table, $array)

	function insert_query($table, $array, $insert_id=true)

	{
if(!is_array($array))
{

	{
if(!is_array($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 769Zeile 783
	
/**
* Build an insert query from an array.

	
/**
* 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 string The query string.

	 * @param string The table name to perform the query on.
* @param array An array of fields and their values.
* @return string The query string.

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

	{
if(!is_array($array))
{

			return false;

			return false;

		}

		}

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

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

		}

		}

		if(!empty($where))
{
$query .= " WHERE $where";

		if(!empty($where))
{
$query .= " WHERE $where";

Zeile 824Zeile 838
		return $this->write_query("
UPDATE {$this->table_prefix}$table
SET $query

		return $this->write_query("
UPDATE {$this->table_prefix}$table
SET $query

		");
}

		");
}

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

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

Zeile 919Zeile 933
	function escape_string_like($string)
{
return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string));

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

	}

/**

	}

/**

	 * Gets the current version of PgSQL.
*
* @return string Version of PgSQL.

	 * Gets the current version of PgSQL.
*
* @return string Version of PgSQL.

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 1001Zeile 1015
			");

if(!$query2)

			");

if(!$query2)

			{

			{

				unset($row['rowdefault']);
}
else

				unset($row['rowdefault']);
}
else

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;

	}

/**
* Show the "show fields from" command for a specific table.

	}

/**
* Show the "show fields from" command for a specific table.

	 *

	 *

	 * @param string The name of the table.
* @return string Field info for that table
*/

	 * @param string The name of the table.
* @return string Field info for that table
*/

Zeile 1099Zeile 1113
			if($field['field'] == $primary_key)
{
$field['extra'] = 'auto_increment';

			if($field['field'] == $primary_key)
{
$field['extra'] = 'auto_increment';

			}

			}

			
$field_info[] = array('Extra' => $field['extra'], 'Field' => $field['field']);
}

return $field_info;

			
$field_info[] = array('Extra' => $field['extra'], 'Field' => $field['field']);
}

return $field_info;

	}


	}


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

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

Zeile 1115Zeile 1129
	 * @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 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;


Zeile 1219Zeile 1261
			$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->update_query($table, $replacements, "{$main_field}='".$replacements[$main_field]."'");

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

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

		}
else
{
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 == "")

		{

		{

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

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


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

		
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]."'");
}
else
{
return $this->build_insert_query($table, $replacements);

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

		}

		}

	}

function build_fields_string($table, $append="")

	}

function build_fields_string($table, $append="")

Zeile 1295Zeile 1340
	
/**
* Sets the table prefix used by the simple select, insert, update and delete functions

	
/**
* Sets the table prefix used by the simple select, insert, update and delete functions

	 *

	 *

	 * @param string The new table prefix
*/
function set_table_prefix($prefix)

	 * @param string The new table prefix
*/
function set_table_prefix($prefix)

Zeile 1314Zeile 1359
		if($table != '')
{
$query = $this->query("SELECT reltuples, relpages FROM pg_class WHERE relname = '".$this->table_prefix.$table."'");

		if($table != '')
{
$query = $this->query("SELECT reltuples, relpages FROM pg_class WHERE relname = '".$this->table_prefix.$table."'");

		}

		}

		else
{
$query = $this->query("SELECT reltuples, relpages FROM pg_class");

		else
{
$query = $this->query("SELECT reltuples, relpages FROM pg_class");

Zeile 1333Zeile 1378
	 * @return array Array of supported character sets with array key being the name, array value being display name. False if unsupported
*/
function fetch_db_charsets()

	 * @return array Array of supported character sets with array key being the name, array value being display name. False if unsupported
*/
function fetch_db_charsets()

	{
return false;
}


	{
return false;
}


	/**
* Fetch a database collation for a particular database character set
*

	/**
* Fetch a database collation for a particular database character set
*

Zeile 1352Zeile 1397
	 * Fetch a character set/collation string for use with CREATE TABLE statements. Uses current DB encoding
*
* @return string The built string, empty if unsupported

	 * Fetch a character set/collation string for use with CREATE TABLE statements. Uses current DB encoding
*
* @return string The built string, empty if unsupported

	 */

	 */

	function build_create_table_collation()
{
return '';

	function build_create_table_collation()
{
return '';

Zeile 1387Zeile 1432
	}
}


	}
}


if(!class_exists('databaseEngine'))
{
class databaseEngine extends DB_PgSQL {
}
}

 
?>

?>