Vergleich inc/db_pgsql.php - 1.4.0 - 1.4.4

  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 4274 2008-11-19 03:22:50Z Tikitiki $

 */

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

		// Connecting to more than one server
{
// Specified multiple servers, but no specific read/write servers

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)

		{

		{

			while(pg_connection_busy($this->write_link));
$this->current_link = &$this->write_link;
pg_send_query($this->current_link, $string);

			while(pg_connection_busy($this->write_link));
$this->current_link = &$this->write_link;
pg_send_query($this->current_link, $string);

Zeile 303Zeile 308
			$this->current_link = &$this->read_link;
pg_send_query($this->current_link, $string);
$query = pg_get_result($this->current_link);

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

		}


		}


		if((pg_result_error($query) && !$hide_errors))
{
$this->error($string, $query);
exit;

		if((pg_result_error($query) && !$hide_errors))
{
$this->error($string, $query);
exit;

		}


		}


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

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

Zeile 330Zeile 335
	 * @return resource The query data.
*/
function write_query($query, $hide_errors=0)

	 * @return resource The query data.
*/
function write_query($query, $hide_errors=0)

	{

	{

		return $this->query($query, $hide_errors, 1);
}


		return $this->query($query, $hide_errors, 1);
}


Zeile 348Zeile 353
			$this->explain .= "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n".
"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #ccc;\"><strong>#".$this->query_count." - Select Query</strong></td>\n".

			$this->explain .= "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n".
"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #ccc;\"><strong>#".$this->query_count." - Select Query</strong></td>\n".

				"</tr>\n".
"<tr>\n".

				"</tr>\n".
"<tr>\n".

				"<td colspan=\"8\" style=\"background-color: #fefefe;\"><span style=\"font-family: Courier; font-size: 14px;\">".$string."</span></td>\n".
"</tr>\n".
"<tr style=\"background-color: #efefef;\">\n".

				"<td colspan=\"8\" style=\"background-color: #fefefe;\"><span style=\"font-family: Courier; font-size: 14px;\">".$string."</span></td>\n".
"</tr>\n".
"<tr style=\"background-color: #efefef;\">\n".

Zeile 366Zeile 371
			$this->explain .=
"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #fff;\">Query Time: ".$qtime."</td>\n".

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

				"</tr>\n".
"</table>\n".
"<br />\n";

				"</tr>\n".
"</table>\n".
"<br />\n";

		}
else
{

		}
else
{

Zeile 406Zeile 411

/**
* Return a specific field from a query.


/**
* Return a specific field from a query.

	 *

	 *

	 * @param resource The query ID.
* @param string The name of the field to return.
* @param int The number of the row to fetch it from.

	 * @param resource The query ID.
* @param string The name of the field to return.
* @param int The number of the row to fetch it from.

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

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

		{

		{

			return;

			return;

		}

		}

		
$id = $this->query("SELECT currval('{$table}_{$field}_seq') AS last_value");
return $this->fetch_field($id, 'last_value');

		
$id = $this->query("SELECT currval('{$table}_{$field}_seq') AS last_value");
return $this->fetch_field($id, 'last_value');

	}

	}


/**
* Close the connection with the DBMS.


/**
* Close the connection with the DBMS.

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

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

		}
}


		}
}


	/**
* Return an error number.
*

	/**
* Return an error number.
*

Zeile 518Zeile 523
		else
{
return pg_last_error();

		else
{
return pg_last_error();

		}		
}

/**

		}		
}

/**

	 * Output a database error.
*
* @param string The string to present as an error.

	 * Output a database error.
*
* @param string The string to present as an error.

Zeile 598Zeile 603
		{
$tables[] = $table['table_name'];
}

		{
$tables[] = $table['table_name'];
}





		return $tables;
}


		return $tables;
}


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

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

		$this->error_reporting = $err;

		
if($exists > 0)

		
if($exists > 0)

		{

		{

			return true;

			return true;

		}

		}

		else
{
return false;

		else
{
return false;

Zeile 637Zeile 642
	 * @return boolean True when exists, false if not.
*/
function field_exists($field, $table)

	 * @return boolean True when exists, false if not.
*/
function field_exists($field, $table)

	{

	{

		$err = $this->error_reporting;
$this->error_reporting = 0;

		$err = $this->error_reporting;
$this->error_reporting = 0;

		

		

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

if($exists > 0)

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

if($exists > 0)

		{
return true;
}
else
{
return false;
}
}

/**

		{
return true;
}
else
{
return false;
}
}

/**

	 * Add a shutdown query.
*
* @param resource The query data.

	 * Add a shutdown query.
*
* @param resource The query data.

Zeile 666Zeile 671
	{
global $shutdown_queries;
if($name)

	{
global $shutdown_queries;
if($name)

		{

		{

			$shutdown_queries[$name] = $query;
}
else
{
$shutdown_queries[] = $query;

			$shutdown_queries[$name] = $query;
}
else
{
$shutdown_queries[] = $query;

		}
}

/**

		}
}

/**

	 * Performs a simple select query.
*
* @param string The table name to be queried.

	 * Performs a simple select query.
*
* @param string The table name to be queried.

Zeile 711Zeile 716
		}

return $this->query($query);

		}

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.

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

	 * @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 732Zeile 738
			INSERT 
INTO {$this->table_prefix}{$table} (".$fields.")
VALUES ('".$values."')

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

		");
return $this->insert_id();
}









		");

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

	
/**
* Build one query for multiple inserts from a multidimensional array.

	
/**
* Build one query for multiple inserts from a multidimensional array.

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.

	 */
function build_insert_query($table, $array)
{

	 */
function build_insert_query($table, $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 = "";
$query = "";

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

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

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

		}

		}

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

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

Zeile 829Zeile 843
	
/**
* Build an update query from an array.

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

	 *
* @param string The table name to perform the query on.

	 *
* @param string The table name to perform the query on.

	 * @param array An array of fields and their values.
* @param string An optional where clause for the query.
* @param string An optional limit clause for the query.

	 * @param array An array of fields and their values.
* @param string An optional where clause for the query.
* @param string An optional limit clause for the query.

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

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

			$comma = ", ";
}

			$comma = ", ";
}

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

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

Zeile 887Zeile 901
	 * @return string The escaped string.
*/
function escape_string($string)

	 * @return string The escaped string.
*/
function escape_string($string)

	{

	{

		if(function_exists("pg_escape_string"))
{
$string = pg_escape_string($string);

		if(function_exists("pg_escape_string"))
{
$string = pg_escape_string($string);

Zeile 906Zeile 920
	 * @return boolean Returns true on success, false on faliure
*/
function free_result($query)

	 * @return boolean Returns true on success, false on faliure
*/
function free_result($query)

	{

	{

		return pg_free_result($query);
}


		return pg_free_result($query);
}


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

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

	 */

	 */

	function get_version()
{
if($this->version)

	function get_version()
{
if($this->version)

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

	}

/**
* Analyzes a specific table.
*
* @param string The name of the table to be analyzed.

	}

/**
* Analyzes a specific table.
*
* @param string The name of the table to be analyzed.

	 */

	 */

	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 1003Zeile 1017
			if(!$query2)
{
unset($row['rowdefault']);

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

			}

			}

			else
{
$row['rowdefault'] = $this->fetch_field($query2, 'rowdefault');

			else
{
$row['rowdefault'] = $this->fetch_field($query2, 'rowdefault');

Zeile 1041Zeile 1055
			}

$lines[] = $line;

			}

$lines[] = $line;

		}

		}


// Get the listing of primary keys.
$query = $this->write_query("


// Get the listing of primary keys.
$query = $this->write_query("

Zeile 1080Zeile 1094

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

	 *
* @param string The name of the table.

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

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

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.

	 *
* @param string The table to be checked.

	 *
* @param string The table to be checked.

	 * @return boolean True or false if supported or not.
*/

	 * @return boolean True or false if supported or not.
*/





	function supports_fulltext($table)
{
return false;

	function supports_fulltext($table)
{
return false;

Zeile 1136Zeile 1150
	 *
* @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_boolean($table)
{
return false;

	function supports_fulltext_boolean($table)
{
return false;

Zeile 1174Zeile 1188
	 * @param string The name of the table.
* @param boolean hard drop - no checking
* @param boolean use table prefix

	 * @param string The name of the table.
* @param boolean hard drop - no checking
* @param boolean use table prefix

	 */

	 */

	function drop_table($table, $hard=false, $table_prefix=true)
{
if($table_prefix == false)

	function drop_table($table, $hard=false, $table_prefix=true)
{
if($table_prefix == false)

		{

		{

			$table_prefix = "";
}

			$table_prefix = "";
}

		else
{
$table_prefix = $this->table_prefix;
}

		else
{
$table_prefix = $this->table_prefix;
}

		
if($hard == false)
{
if($this->table_exists($table))
{
$this->write_query('DROP TABLE '.$table_prefix.$table);

		
if($hard == false)
{
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 1218
	 *
* @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 1213Zeile 1229
		{
$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;

		else
{
$main_field = $default_field;

		}

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

		}

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

		
while($column = $this->fetch_array($query))

		
while($column = $this->fetch_array($query))

		{

		{

			if($column[$main_field] == $replacements[$main_field])
{
++$i;
}

			if($column[$main_field] == $replacements[$main_field])
{
++$i;
}

		}

		}

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

		
if($i > 0)
{
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 1244Zeile 1260
	 *
* @param string The table
* @param array The replacements

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

 
	 * @param string The default field

	 */
function build_replace_query($table, $replacements=array(), $default_field="")
{

	 */
function build_replace_query($table, $replacements=array(), $default_field="")
{

Zeile 1387Zeile 1404
	}
}


	}
}


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

 
?>

?>