Vergleich inc/db_pgsql.php - 1.4.3 - 1.4.6

  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 4340 2009-04-05 17:10:22Z 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
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'];

// Actually connect to the specified servers

		$this->db_encoding = $config['encoding'];

// Actually connect to the specified servers

Zeile 189Zeile 190
				$details = $connections[$type];
unset($connections);
$connections[$type][] = $details;

				$details = $connections[$type];
unset($connections);
$connections[$type][] = $details;

			}

			}


// Shuffle the connections
shuffle($connections[$type]);


// Shuffle the connections
shuffle($connections[$type]);

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

					$this->connect_string .= "host={$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 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 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]."'");
}