Vergleich inc/db_pgsql.php - 1.6.1 - 1.6.12

  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 5028 2010-06-16 05:50:39Z RyanGordon $

 * $Id$

 */

class DB_PgSQL

 */

class DB_PgSQL

Zeile 143Zeile 143
	 * @var float
*/
public $query_time = 0;

	 * @var float
*/
public $query_time = 0;

 

/**
* The last result run on the database (needed for affected_rows)
*
* @var resource
*/
public $last_result;


/**
* Connect to the database server.


/**
* Connect to the database server.

Zeile 199Zeile 206
			foreach($connections[$type] as $single_connection)
{
$connect_function = "pg_connect";

			foreach($connections[$type] as $single_connection)
{
$connect_function = "pg_connect";

				if($single_connection['pconnect'])

				if(isset($single_connection['pconnect']))

				{
$connect_function = "pg_pconnect";
}

				{
$connect_function = "pg_pconnect";
}

Zeile 282Zeile 289
	{
global $pagestarttime, $db, $mybb;


	{
global $pagestarttime, $db, $mybb;


		$string = preg_replace("#LIMIT ([0-9]+),([ 0-9]+)#i", "LIMIT $2 OFFSET $1", $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 321Zeile 328
		$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++;

 
		$this->last_result = $query;

		
if($mybb->debug_mode)
{

		
if($mybb->debug_mode)
{

Zeile 357Zeile 365
				"<td colspan=\"8\" style=\"background-color: #ccc;\"><strong>#".$this->query_count." - Select Query</strong></td>\n".
"</tr>\n".
"<tr>\n".

				"<td colspan=\"8\" style=\"background-color: #ccc;\"><strong>#".$this->query_count." - Select Query</strong></td>\n".
"</tr>\n".
"<tr>\n".

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

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

				"</tr>\n".
"<tr style=\"background-color: #efefef;\">\n".
"<td><strong>Info</strong></td>\n".

				"</tr>\n".
"<tr style=\"background-color: #efefef;\">\n".
"<td><strong>Info</strong></td>\n".

Zeile 433Zeile 441

/**
* Moves internal row pointer to the next row


/**
* Moves internal row pointer to the next row

	 *
* @param resource The query ID.

	 *
* @param resource The query ID.

	 * @param int The pointer to move the row to.
*/
function data_seek($query, $row)

	 * @param int The pointer to move the row to.
*/
function data_seek($query, $row)

Zeile 451Zeile 459
	function num_rows($query)
{
return pg_num_rows($query);

	function num_rows($query)
{
return pg_num_rows($query);

	}


	}


	/**
* Return the last id number of inserted data.
*

	/**
* Return the last id number of inserted data.
*

Zeile 464Zeile 472
		preg_match('#INSERT INTO ([a-zA-Z0-9_\-]+)#i', $this->last_query, $matches);

$table = $matches[1];

		preg_match('#INSERT INTO ([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');

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

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

		{

		{

			return;
}


			return;
}


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

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

		}
}

/**

		}
}

/**

	 * Return an error number.
*
* @return int The error number of the current error.

	 * Return an error number.
*
* @return int The error number of the current error.

Zeile 504Zeile 512
		}

return pg_result_error_field($query, PGSQL_DIAG_SQLSTATE);

		}

return pg_result_error_field($query, PGSQL_DIAG_SQLSTATE);

	}

/**

	}

/**

	 * Return an error string.
*
* @return string The explanation for the current error.

	 * Return an error string.
*
* @return string The explanation for the current error.

Zeile 559Zeile 567
				trigger_error("<strong>[SQL] [".$this->error_number()."] ".$this->error_string()."</strong><br />{$string}", E_USER_ERROR);
}
}

				trigger_error("<strong>[SQL] [".$this->error_number()."] ".$this->error_string()."</strong><br />{$string}", E_USER_ERROR);
}
}

	}


	}



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


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

Zeile 569Zeile 577
	 */
function affected_rows()
{

	 */
function affected_rows()
{

		return pg_affected_rows($this->current_link);

		return pg_affected_rows($this->last_result);

	}

/**

	}

/**

Zeile 579Zeile 587
	 * @return int The number of fields.
*/
function num_fields($query)

	 * @return int The number of fields.
*/
function num_fields($query)

	{

	{

		return pg_num_fields($query);
}


		return pg_num_fields($query);
}


Zeile 595Zeile 603
		if($prefix)
{
$query = $this->query("SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_name LIKE '".$this->escape_string($prefix)."%'");

		if($prefix)
{
$query = $this->query("SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_name LIKE '".$this->escape_string($prefix)."%'");

		}
else

		}
else

		{
$query = $this->query("SELECT table_name FROM information_schema.tables WHERE table_schema='public'");
}

		{
$query = $this->query("SELECT table_name FROM information_schema.tables WHERE table_schema='public'");
}

Zeile 611Zeile 619

/**
* Check if a table exists in a database.


/**
* Check if a table exists in a database.

	 *
* @param string The table name.
* @return boolean True when exists, false if not.
*/

	 *
* @param string The table name.
* @return boolean True when exists, false if not.
*/

	function table_exists($table)
{
// Execute on master 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}'");

	function table_exists($table)
{
// Execute on master 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}'");

		

		

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

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

		
if($exists > 0)
{
return true;
}
else
{
return false;
}
}

/**

		
if($exists > 0)
{
return true;
}
else
{
return false;
}
}

/**

	 * Check if a field exists in a database.
*
* @param string The field name.

	 * Check if a field exists in a database.
*
* @param string The field name.

Zeile 648Zeile 656
		if($exists > 0)
{
return true;

		if($exists > 0)
{
return true;

		}
else

		}
else

		{
return false;
}

		{
return false;
}

Zeile 667Zeile 675
		if($name)
{
$shutdown_queries[$name] = $query;

		if($name)
{
$shutdown_queries[$name] = $query;

		}

		}

		else
{
$shutdown_queries[] = $query;

		else
{
$shutdown_queries[] = $query;

Zeile 703Zeile 711
		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']))
{
$query .= " LIMIT ".$options['limit'];

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

Zeile 721Zeile 729
	 * @return int The insert ID if available
*/
function insert_query($table, $array, $insert_id=true)

	 * @return int The insert ID if available
*/
function insert_query($table, $array, $insert_id=true)

	{
if(!is_array($array))
{

	{
if(!is_array($array))
{

			return false;

			return false;

		}

		}

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

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

Zeile 738Zeile 746
		if($insert_id != false)
{
return $this->insert_id();

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

		}
else
{

		}
else
{

			return true;
}
}

			return true;
}
}

Zeile 773Zeile 781
			INSERT 
INTO {$this->table_prefix}{$table} ({$fields})
VALUES {$insert_rows}

			INSERT 
INTO {$this->table_prefix}{$table} ({$fields})
VALUES {$insert_rows}

		");
}

/**

		");
}

/**

	 * Build an update query from an array.
*
* @param string The table name to perform the query on.

	 * Build an update query from an array.
*
* @param string The table name to perform the query on.

Zeile 794Zeile 802
		}

$comma = "";

		}

$comma = "";

		$query = "";

		$query = "";

		$quote = "'";

if($no_quote == true)

		$quote = "'";

if($no_quote == true)

Zeile 866Zeile 874
	 * @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 902Zeile 910

/**
* Optimizes a specific table.


/**
* Optimizes a specific table.

	 *

	 *

	 * @param string The name of the table to be optimized.
*/
function optimize_table($table)

	 * @param string The name of the table to be optimized.
*/
function optimize_table($table)

Zeile 973Zeile 981
				{
$line .= '('.($row['lengthvar'] - 4).')';
}

				{
$line .= '('.($row['lengthvar'] - 4).')';
}

			}


			}


			if(strpos($row['type'], 'numeric') !== false)
{
$line .= '('.sprintf("%s,%s", (($row['lengthvar'] >> 16) & 0xffff), (($row['lengthvar'] - 4) & 0xffff)).')';

			if(strpos($row['type'], 'numeric') !== false)
{
$line .= '('.sprintf("%s,%s", (($row['lengthvar'] >> 16) & 0xffff), (($row['lengthvar'] - 4) & 0xffff)).')';

			}


			}


			if(!empty($row['rowdefault']))

			if(!empty($row['rowdefault']))

			{

			{

				$line .= " DEFAULT {$row['rowdefault']}";

				$line .= " DEFAULT {$row['rowdefault']}";

			}

			}


if($row['notnull'] == 't')
{


if($row['notnull'] == 't')
{

Zeile 992Zeile 1000
			
$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 1009Zeile 1017

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

		{

		{

			if($row['primary_key'] == 't')
{
$primary_key[] = $row['column_name'];

			if($row['primary_key'] == 't')
{
$primary_key[] = $row['column_name'];

Zeile 1295Zeile 1303
	 * @param string The table
* @param string The column name
* @param string the new column definition

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

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

	 */

	 */

	function modify_column($table, $column, $new_definition)

	function modify_column($table, $column, $new_definition, $new_not_null=false, $new_default_value=false)

	{

	{

		return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ALTER COLUMN {$column} TYPE {$new_definition}");





























		$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_not_null !== false)
{
$set_drop = "DROP";

if(strtolower($new_not_null) == "set")
{
$set_drop = "SET";
}

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

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;

	}

/**

	}

/**

Zeile 1308Zeile 1346
	 * @param string The old column name
* @param string the new column name
* @param string the new column definition

	 * @param string The old column name
* @param string the new column name
* @param string the new column definition

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

	 */

	 */

	function rename_column($table, $old_column, $new_column, $new_definition)

	function rename_column($table, $old_column, $new_column, $new_definition, $new_not_null=false, $new_default_value=false)

	{
$result1 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} RENAME COLUMN {$old_column} TO {$new_column}");

	{
$result1 = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} RENAME COLUMN {$old_column} TO {$new_column}");

		$result2 = $this->modify_column($table, $new_column, $new_definition);

		$result2 = $this->modify_column($table, $new_column, $new_definition, $new_not_null, $new_default_value);

		return ($result1 && $result2);
}


		return ($result1 && $result2);
}