Vergleich inc/db_sqlite.php - 1.8.0 - 1.8.26

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 8Zeile 8
 *
*/


 *
*/


class DB_SQLite

class DB_SQLite implements DB_Base

{
/**
* The title of this layer.

{
/**
* The title of this layer.

Zeile 30Zeile 30
	 * @var string
*/
public $type;

	 * @var string
*/
public $type;

 

/**
* PDOStatement objects of performed queries.
*
* @var array
*/
public $query_objects = array();


/**
* A count of the number of queries.


/**
* A count of the number of queries.

Zeile 61Zeile 68

/**
* Explanation of a query.


/**
* Explanation of a query.

	 *
* @var string
*/

	 *
* @var string
*/

	public $explain;

	public $explain;





	/**
* The current version of SQLite.
*

	/**
* The current version of SQLite.
*

Zeile 75Zeile 82

/**
* The current table type in use (myisam/innodb)


/**
* The current table type in use (myisam/innodb)

	 *
* @var string

	 *
* @var string

	 */
public $table_type = "myisam";

	 */
public $table_type = "myisam";


/**


/**

	 * The table prefix used for simple select, update, insert and delete queries

	 * The table prefix used for simple select, update, insert and delete queries

	 *
* @var string

	 *
* @var string

	 */
public $table_prefix;

/**
* The extension used to run the SQL database

	 */
public $table_prefix;

/**
* The extension used to run the SQL database

	 *
* @var string

	 *
* @var string

	 */
public $engine = "pdo";

	 */
public $engine = "pdo";


/**


/**

	 * Weather or not this engine can use the search functionality

	 * Weather or not this engine can use the search functionality

	 *

	 *

	 * @var boolean
*/
public $can_search = true;

	 * @var boolean
*/
public $can_search = true;

Zeile 105Zeile 112
	 * The database encoding currently in use (if supported)
*
* @var string

	 * The database encoding currently in use (if supported)
*
* @var string

	 */

	 */

	public $db_encoding = "";

/**

	public $db_encoding = "";

/**

	 * The time spent performing queries








	 * The time spent performing queries
*
* @var float
*/
public $query_time = 0;

/**
* Our pdo implementation

	 *

	 *

	 * @var float

	 * @var dbpdoEngine

	 */

	 */

	public $query_time = 0;

	var $db;


/**
* Connect to the database server.
*


/**
* Connect to the database server.
*

	 * @param array Array of DBMS connection details.
* @return resource The DB connection resource. Returns false on failure.

	 * @param array $config Array of DBMS connection details.
* @return bool Returns false on failure, otherwise true

	 */
function connect($config)
{

	 */
function connect($config)
{

Zeile 136Zeile 150
		$this->connections[] = "[WRITE] {$config['database']} (Connected in ".format_time_duration($query_time).")";

if($this->db)

		$this->connections[] = "[WRITE] {$config['database']} (Connected in ".format_time_duration($query_time).")";

if($this->db)

		{

		{

			$this->query('PRAGMA short_column_names = 1');
return true;
}

			$this->query('PRAGMA short_column_names = 1');
return true;
}

Zeile 149Zeile 163
	/**
* Query the database.
*

	/**
* Query the database.
*

	 * @param string The query SQL.
* @param boolean 1 if hide errors, 0 if not.
* @return resource The query data.


	 * @param string $string The query SQL.
* @param boolean|int $hide_errors 1 if hide errors, 0 if not.
* @param integer $write_query 1 if executes on master database, 0 if not.
* @return PDOStatement The query data.

	 */

	 */

	function query($string, $hide_errors=0)

	function query($string, $hide_errors=0, $write_query=0)

	{

	{

		global $pagestarttime, $db, $mybb;

		global $mybb;


get_execution_time();



get_execution_time();


Zeile 200Zeile 215
				$this->error($error['message'], $error['code']);
}
}

				$this->error($error['message'], $error['code']);
}
}

 

$this->query_objects[] = $query;


if($this->error_number($query) > 0 && !$hide_errors)
{


if($this->error_number($query) > 0 && !$hide_errors)
{

Zeile 219Zeile 236
		if(strtolower(substr(ltrim($string), 0, 6)) == "create")
{
$query->closeCursor();

		if(strtolower(substr(ltrim($string), 0, 6)) == "create")
{
$query->closeCursor();

			return;

			return null;

		}

		}





		return $query;
}

/**
* Explain a query on the database.
*

		return $query;
}

/**
* Explain a query on the database.
*

	 * @param string The query SQL.
* @param string The time it took to perform the query.

	 * @param string $string The query SQL.
* @param string $qtime The time it took to perform the query.

	 */
function explain_query($string, $qtime)
{

	 */
function explain_query($string, $qtime)
{

Zeile 238Zeile 255
			$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".
"<td colspan=\"8\" style=\"background-color: #fefefe;\"><span style=\"font-family: Courier; font-size: 14px;\">".htmlspecialchars_uni($string)."</span></td>\n".
"</tr>\n".

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

Zeile 271Zeile 288
	/**
* Execute a write query on the database
*

	/**
* Execute a write query on the database
*

	 * @param string The query SQL.
* @param boolean 1 if hide errors, 0 if not.
* @return resource The query data.

	 * @param string $query The query SQL.
* @param boolean|int $hide_errors 1 if hide errors, 0 if not.
* @return PDOStatement The query data.

	 */
function write_query($query, $hide_errors=0)

	 */
function write_query($query, $hide_errors=0)

	{

	{

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

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

	}


	}


	/**
* Return a result array for a query.
*

	/**
* Return a result array for a query.
*

	 * @param resource The result data.
* @param constant The type of array to return.

	 * @param PDOStatement $query The result data.
* @param int $resulttype One of PDO's constants: FETCH_ASSOC, FETCH_BOUND, FETCH_CLASS, FETCH_INTO, FETCH_LAZY, FETCH_NAMED, FETCH_NUM, FETCH_OBJ or FETCH_BOTH

	 * @return array The array of results.
*/

	 * @return array The array of results.
*/

	function fetch_array($query)

	function fetch_array($query, $resulttype=PDO::FETCH_BOTH)

	{

	{

		$array = $this->db->fetch_array($query);

		$array = $this->db->fetch_array($query, $resulttype);

		return $array;
}

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

		return $array;
}

/**
* 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 PDOStatement $query The query ID.
* @param string $field The name of the field to return.
* @param int|bool $row The number of the row to fetch it from.
* @return mixed

	 */
function fetch_field($query, $field, $row=false)

	 */
function fetch_field($query, $field, $row=false)

	{

	{

		if($row !== false)
{
$this->data_seek($query, $row);
}
$array = $this->fetch_array($query);
return $array[$field];

		if($row !== false)
{
$this->data_seek($query, $row);
}
$array = $this->fetch_array($query);
return $array[$field];

	}


	}


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

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

	 * @param resource The query ID.
* @param int The pointer to move the row to.

	 * @param PDOStatement $query The query ID.
* @param int $row The pointer to move the row to.

	 */
function data_seek($query, $row)

	 */
function data_seek($query, $row)

	{
return $this->db->seek($query, $row);
}

/**




















	{
$this->db->seek($query, $row);
}

/**
* Closes cursors of registered queries.
*
*/
function close_cursors()
{
$result = true;

foreach($this->query_objects as $query)
{
if(!$query->closeCursor())
{
$result = false;
}
}

return $result;
}

/**

	 * Return the number of rows resulting from a query.
*

	 * Return the number of rows resulting from a query.
*

	 * @param resource The query data.

	 * @param PDOStatement $query The query data.

	 * @return int The number of rows in the result.
*/
function num_rows($query)

	 * @return int The number of rows in the result.
*/
function num_rows($query)

Zeile 335Zeile 372
	/**
* Return the last id number of inserted data.
*

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

 
	 * @param string $name

	 * @return int The id number.
*/
function insert_id($name="")
{
return $this->db->insert_id($name);

	 * @return int The id number.
*/
function insert_id($name="")
{
return $this->db->insert_id($name);

	}

	}


/**
* Close the connection with the DBMS.


/**
* Close the connection with the DBMS.

	 *
*/

	 *
*/

	function close()

	function close()

	{

	{

		return;
}

/**
* Return an error number.
*

		return;
}

/**
* Return an error number.
*

 
	 * @param PDOStatement $query

	 * @return int The error number of the current error.
*/

	 * @return int The error number of the current error.
*/

	function error_number($query="")

	function error_number($query=null)

	{

	{

		if(!$query)

		if($query == null)

		{
$query = $this->db->last_query;
}

		{
$query = $this->db->last_query;
}

Zeile 371Zeile 410
	/**
* Return an error string.
*

	/**
* Return an error string.
*

 
	 * @param PDOStatement $query

	 * @return string The explanation for the current error.
*/

	 * @return string The explanation for the current error.
*/

	function error_string($query="")

	function error_string($query=null)

	{
if($this->error_number != "")
{

	{
if($this->error_number != "")
{

			if(!$query)

			if($query == null)

			{
$query = $this->db->last_query;
}

			{
$query = $this->db->last_query;
}

Zeile 387Zeile 427

return $error_string;
}


return $error_string;
}

 

return '';

	}

/**
* Output a database error.
*

	}

/**
* Output a database error.
*

	 * @param string The string to present as an error.




	 * @param string $string The string to present as an error.
* @param PDOStatement $query
* @param string $error
* @param int $error_no

	 */

	 */

	function error($string="", $query="", $error="", $error_no="")

	function error($string="", $query=null, $error="", $error_no=0)

	{

	{

		$this->db->roll_back();


 
		if($this->error_reporting)
{

		if($this->error_reporting)
{

			if(!$query)

			if($query == null)

			{
$query = $this->db->last_query;
}


			{
$query = $this->db->last_query;
}


			if($error_no == "")

			if($error_no == 0)

			{
$error_no = $this->error_number($query);
}

			{
$error_no = $this->error_number($query);
}

Zeile 424Zeile 467
					require_once MYBB_ROOT."inc/class_error.php";
$error_handler = new errorHandler();
}

					require_once MYBB_ROOT."inc/class_error.php";
$error_handler = new errorHandler();
}





				$error = array(
"error_no" => $error_no,
"error" => $error,

				$error = array(
"error_no" => $error_no,
"error" => $error,

Zeile 441Zeile 484

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


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

	 *


	 *
* @param PDOStatement $query

	 * @return int The number of affected rows.
*/

	 * @return int The number of affected rows.
*/

	function affected_rows($query="")

	function affected_rows($query=null)

	{

	{

		if(!$query)

		if($query == null)

		{
$query = $this->db->last_query;
}

		{
$query = $this->db->last_query;
}





		return $this->db->affected_rows($query);
}

/**
* Return the number of fields.
*

		return $this->db->affected_rows($query);
}

/**
* Return the number of fields.
*

	 * @param resource The query data.

	 * @param PDOStatement $query The query data.

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

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

	{

	{

		if(!$query)
{
$query = $this->db->last_query;

		if(!$query)
{
$query = $this->db->last_query;

Zeile 471Zeile 515
	}

/**

	}

/**

	 * Lists all functions in the database.

	 * Lists all tables in the database.

	 *

	 *

	 * @param string The database name.
* @param string Prefix of the table (optional)

	 * @param string $database The database name.
* @param string $prefix Prefix of the table (optional)

	 * @return array The table list.
*/
function list_tables($database, $prefix='')

	 * @return array The table list.
*/
function list_tables($database, $prefix='')

Zeile 500Zeile 544
	/**
* Check if a table exists in a database.
*

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

	 * @param string The table name.

	 * @param string $table The table name.

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

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

Zeile 522Zeile 566
	/**
* Check if a field exists in a database.
*

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

	 * @param string The field name.
* @param string The table name.

	 * @param string $field The field name.
* @param string $table The table name.

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

Zeile 535Zeile 579
		while($row = $this->fetch_array($query))
{
if($row['name'] == $field)

		while($row = $this->fetch_array($query))
{
if($row['name'] == $field)

			{

			{

				++$exists;
}

				++$exists;
}

		}


		}


		$query->closeCursor();

if($exists > 0)

		$query->closeCursor();

if($exists > 0)

		{

		{

			return true;

			return true;

		}
else
{
return false;
}
}


		}
else
{
return false;
}
}


	/**
* Add a shutdown query.
*

	/**
* Add a shutdown query.
*

	 * @param resource The query data.
* @param string An optional name for the query.

	 * @param PDOStatement $query The query data.
* @param string $name An optional name for the query.

	 */

	 */

	function shutdown_query($query, $name=0)

	function shutdown_query($query, $name="")

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


/**
* Performs a simple select query.
*

	 * @param string The table name to be queried.
* @param string Comma delimetered list of fields to be selected.
* @param string SQL formatted list of conditions to be matched.
* @param array List of options: group by, order by, order direction, limit, limit start.
* @return resource The query data.

	 * @param string $table The table name to be queried.
* @param string $fields Comma delimetered list of fields to be selected.
* @param string $conditions SQL formatted list of conditions to be matched.
* @param array $options List of options: group by, order by, order direction, limit, limit start.
* @return PDOStatement The query data.

	 */
function simple_select($table, $fields="*", $conditions="", $options=array())
{
$query = "SELECT ".$fields." FROM ".$this->table_prefix.$table;

	 */
function simple_select($table, $fields="*", $conditions="", $options=array())
{
$query = "SELECT ".$fields." FROM ".$this->table_prefix.$table;





		if($conditions != "")

		if($conditions != "")

		{

		{

			$query .= " WHERE ".$conditions;
}

			$query .= " WHERE ".$conditions;
}


if(isset($options['group_by']))
{
$query .= " GROUP BY ".$options['group_by'];
}


if(isset($options['group_by']))
{
$query .= " GROUP BY ".$options['group_by'];
}


if(isset($options['order_by']))
{


if(isset($options['order_by']))
{

Zeile 605Zeile 649
		}

if(isset($options['limit_start']) && isset($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_start'].", ".$options['limit'];
}
else if(isset($options['limit']))

Zeile 619Zeile 663
	/**
* 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 int The insert ID if available

	 * @param string $table The table name to perform the query on.
* @param array $array An array of fields and their values.
* @return int|bool The insert ID if available or false if an error is found

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

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

Zeile 645Zeile 689
			}
else
{

			}
else
{

				$array[$field] = "'{$value}'";

				$array[$field] = $this->quote_val($value);

			}
}


			}
}


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

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

	 * @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 $table The table name to perform the query on.
* @param array $array An array of inserts.
* @return void

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

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

Zeile 673Zeile 717

if(!is_array($array))
{


if(!is_array($array))
{

			return false;

			return;

		}
// Field names
$fields = array_keys($array[0]);

		}
// Field names
$fields = array_keys($array[0]);

Zeile 695Zeile 739
				}
else
{

				}
else
{

					$values[$field] = "'{$value}'";

					$values[$field] = $this->quote_val($value);

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

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

Zeile 713Zeile 757
	/**
* 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 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 boolean An option to quote incoming values of the array.
* @return resource The query data.

	 * @param string $table The table name to perform the query on.
* @param array $array An array of fields and their values.
* @param string $where An optional where clause for the query.
* @param string $limit An optional limit clause for the query.
* @param boolean $no_quote An option to quote incoming values of the array.
* @return PDOStatement The query data.

	 */
function update_query($table, $array, $where="", $limit="", $no_quote=false)
{

	 */
function update_query($table, $array, $where="", $limit="", $no_quote=false)
{

Zeile 751Zeile 795
			}
else
{

			}
else
{

				$query .= $comma.$field."={$quote}".$value."{$quote}";



				$quoted_value = $this->quote_val($value, $quote);

$query .= $comma.$field."={$quoted_value}";

			}
$comma = ', ';

			}
$comma = ', ';

		}


		}


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

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





		$query = $this->query("UPDATE {$this->table_prefix}$table SET $query");

		$query = $this->query("UPDATE {$this->table_prefix}$table SET $query");

		$query->closeCursor();
return $query;
}

/**





















		$query->closeCursor();
return $query;
}

/**
* @param int|string $value
* @param string $quote
*
* @return int|string
*/
private function quote_val($value, $quote="'")
{
if(is_int($value))
{
$quoted = $value;
}
else
{
$quoted = $quote . $value . $quote;
}

return $quoted;
}

/**

	 * Build a delete query.
*

	 * Build a delete query.
*

	 * @param string The table name to perform the query on.
* @param string An optional where clause for the query.
* @param string An optional limit clause for the query.
* @return resource The query data.

	 * @param string $table The table name to perform the query on.
* @param string $where An optional where clause for the query.
* @param string $limit An optional limit clause for the query.
* @return PDOStatement The query data.

	 */
function delete_query($table, $where="", $limit="")
{

	 */
function delete_query($table, $where="", $limit="")
{

Zeile 785Zeile 851
		$query = $this->query("DELETE FROM {$this->table_prefix}$table $query");
$query->closeCursor();
return $query;

		$query = $this->query("DELETE FROM {$this->table_prefix}$table $query");
$query->closeCursor();
return $query;

	}

	}


/**
* Escape a string
*


/**
* Escape a string
*

	 * @param string The string to be escaped.

	 * @param string $string The string to be escaped.

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

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

Zeile 802Zeile 868
	/**
* Serves no purposes except compatibility
*

	/**
* Serves no purposes except compatibility
*

 
	 * @param PDOStatement $query
* @return boolean Returns true on success, false on failure

	 */
function free_result($query)
{

	 */
function free_result($query)
{

		return;
}

		return true;
}


/**
* Escape a string used within a like command.
*


/**
* Escape a string used within a like command.
*

	 * @param string The string to be escaped.

	 * @param string $string The string to be escaped.

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

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

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

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


/**
* Gets the current version of SQLLite.


/**
* Gets the current version of SQLLite.

Zeile 838Zeile 906
	/**
* Optimizes a specific table.
*

	/**
* Optimizes a specific table.
*

	 * @param string The name of the table to be optimized.

	 * @param string $table The name of the table to be optimized.

	 */
function optimize_table($table)
{

	 */
function optimize_table($table)
{

Zeile 849Zeile 917
	/**
* Analyzes a specific table.
*

	/**
* Analyzes a specific table.
*

	 * @param string The name of the table to be analyzed.

	 * @param string $table The name of the table to be analyzed.

	 */
function analyze_table($table)
{

	 */
function analyze_table($table)
{

Zeile 860Zeile 928
	/**
* Show the "create table" command for a specific table.
*

	/**
* Show the "create table" command for a specific table.
*

	 * @param string The name of the table.
* @return string The MySQL command to create the specified table.

	 * @param string $table The name of the table.
* @return string The SQLite command to create the specified table.

	 */
function show_create_table($table)
{

	 */
function show_create_table($table)
{

Zeile 879Zeile 947

/**
* 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 $table The name of the table.
* @return array Field info for that table

	 */
function show_fields_from($table)
{

	 */
function show_fields_from($table)
{

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

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

	 * @param string The name of the table.
* @param string Optionally specify the name of the index.

	 * @param string $table The name of the table.
* @param string $index Optionally specify the name of the index.

	 * @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="")

Zeile 921Zeile 989

/**
* 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 $table The table to be checked.
* @return boolean True or false if supported or not.

	 */

function supports_fulltext($table)

	 */

function supports_fulltext($table)

	{
return false;
}

/**

	{
return false;
}

/**

	 * Returns whether or not this database engine supports boolean fulltext matching.
*

	 * Returns whether or not this database engine supports boolean fulltext matching.
*

	 * @param string The table to be checked.

	 * @param string $table The table to be checked.

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

Zeile 944Zeile 1012

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

	 *
* @param string The name of the table.
* @param string Name of the column to be indexed.
* @param string The index name, optional.


	 *
* @param string $table The name of the table.
* @param string $column Name of the column to be indexed.
* @param string $name The index name, optional.
* @return bool

	 */
function create_fulltext_index($table, $column, $name="")

	 */
function create_fulltext_index($table, $column, $name="")

	{

	{

		return false;

		return false;

	}

	}


/**
* 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 $table The name of the table.
* @param string $name The name of the index.

	 */
function drop_index($table, $name)
{

	 */
function drop_index($table, $name)
{

Zeile 968Zeile 1037

/**
* Checks to see if an index exists on a specified table


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


	 *
* @param string $table The name of the table.
* @param string $index The name of the index.
* @return bool Returns whether index exists
*/

	function index_exists($table, $index)
{
return false;

	function index_exists($table, $index)
{
return false;

Zeile 980Zeile 1050
	/**
* Drop an table with the specified table
*

	/**
* Drop an table with the specified table
*

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

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

	 */
function drop_table($table, $hard=false, $table_prefix=true)

	 */
function drop_table($table, $hard=false, $table_prefix=true)

	{
if($table_prefix == false)
{
$table_prefix = "";
}
else
{
$table_prefix = $this->table_prefix;

	{
if($table_prefix == false)
{
$table_prefix = "";
}
else
{
$table_prefix = $this->table_prefix;

		}

if($hard == false)

		}

if($hard == false)

Zeile 1010Zeile 1080
		if(isset($query))
{
$query->closeCursor();

		if(isset($query))
{
$query->closeCursor();

		}
}


		}
}


	/**
* Renames a table
*

	/**
* Renames a table
*

	 * @param string The old table name
* @param string the new table name
* @param boolean use table prefix


	 * @param string $old_table The old table name
* @param string $new_table the new table name
* @param boolean $table_prefix use table prefix
* @return PDOStatement

	 */
function rename_table($old_table, $new_table, $table_prefix=true)
{

	 */
function rename_table($old_table, $new_table, $table_prefix=true)
{

Zeile 1039Zeile 1110
	/**
* Replace contents of table with values
*

	/**
* Replace contents of table with values
*

	 * @param string The table
* @param array The replacements
* @param mixed The default field(s)
* @param boolean Whether or not to return an insert id. True by default


	 * @param string $table The table
* @param array $replacements The replacements
* @param string|array $default_field The default field(s)
* @param boolean $insert_id Whether or not to return an insert id. True by default
* @return int|PDOStatement|bool Returns either the insert id (if a new row is inserted), the query resource (if a row is updated) or false on failure

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

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

Zeile 1057Zeile 1129
			if(isset($mybb->binary_fields[$table][$column]) && $mybb->binary_fields[$table][$column])
{
if($value[0] != 'X') // Not escaped?

			if(isset($mybb->binary_fields[$table][$column]) && $mybb->binary_fields[$table][$column])
{
if($value[0] != 'X') // Not escaped?

				{

				{

					$value = $this->escape_binary($value);
}

$values .= $comma.$value;

					$value = $this->escape_binary($value);
}

$values .= $comma.$value;

			}

			}

			else
{

			else
{

				$values .= $comma."'".$value."'";

				$values .= $comma.$this->quote_val($value);

			}

			}





			$comma = ',';

			$comma = ',';

		}


		}


		if(empty($columns) || empty($values))

		if(empty($columns) || empty($values))

		{

		{

			 return false;
}

if($default_field == "")

			 return false;
}

if($default_field == "")

		{

		{

			$query = $this->query("REPLACE INTO {$this->table_prefix}{$table} ({$columns}) VALUES({$values})");
$query->closeCursor();
return $query;

			$query = $this->query("REPLACE INTO {$this->table_prefix}{$table} ({$columns}) VALUES({$values})");
$query->closeCursor();
return $query;

Zeile 1096Zeile 1168
				$search_bit = implode(" AND ", $search_bit);
$query = $this->write_query("SELECT COUNT(".$default_field[0].") as count FROM {$this->table_prefix}{$table} WHERE {$search_bit} LIMIT 1");
if($this->fetch_field($query, "count") == 1)

				$search_bit = implode(" AND ", $search_bit);
$query = $this->write_query("SELECT COUNT(".$default_field[0].") as count FROM {$this->table_prefix}{$table} WHERE {$search_bit} LIMIT 1");
if($this->fetch_field($query, "count") == 1)

				{

				{

					$update = true;
}
}

					$update = true;
}
}

Zeile 1121Zeile 1193
			}
else
{

			}
else
{

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

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

			}
}
}

			}
}
}

Zeile 1129Zeile 1201
	/**
* 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

	 * @param string $prefix The new table prefix

	 */
function set_table_prefix($prefix)
{
$this->table_prefix = $prefix;

	 */
function set_table_prefix($prefix)
{
$this->table_prefix = $prefix;

	}

/**

	}

/**

	 * Fetched the total size of all mysql tables or a specific table

	 * Fetched the total size of all mysql tables or a specific table

	 *
* @param string The table (optional) (ignored)
* @return integer the total size of all mysql tables or a specific table

	 *
* @param string $table The table (optional) (ignored)
* @return integer the total size of all mysql tables or a specific table

	 */
function fetch_size($table='')
{
global $config, $lang;

	 */
function fetch_size($table='')
{
global $config, $lang;





		$total = @filesize($config['database']['database']);
if(!$total || $table != '')
{

		$total = @filesize($config['database']['database']);
if(!$total || $table != '')
{

Zeile 1157Zeile 1229
	/**
* Perform an "Alter Table" query in SQLite < 3.2.0 - Code taken from http://code.jenseng.com/db/
*

	/**
* Perform an "Alter Table" query in SQLite < 3.2.0 - Code taken from http://code.jenseng.com/db/
*

	 * @param string The table (optional)
* @return integer the total size of all mysql tables or a specific table



	 * @param string $table The table (optional)
* @param string $alterdefs
* @param string $fullquery
* @return bool True on success, false on failure

	 */
function alter_table_parse($table, $alterdefs, $fullquery="")
{

	 */
function alter_table_parse($table, $alterdefs, $fullquery="")
{

Zeile 1182Zeile 1256
				$tmpname = 't'.TIME_NOW;
$origsql = trim(preg_replace("/[\s]+/", " ", str_replace(",", ", ", preg_replace("/[\(]/","( ", $row['sql'], 1))));
$createtemptableSQL = 'CREATE TEMPORARY '.substr(trim(preg_replace("'".$table."'", $tmpname, $origsql, 1)), 6);

				$tmpname = 't'.TIME_NOW;
$origsql = trim(preg_replace("/[\s]+/", " ", str_replace(",", ", ", preg_replace("/[\(]/","( ", $row['sql'], 1))));
$createtemptableSQL = 'CREATE TEMPORARY '.substr(trim(preg_replace("'".$table."'", $tmpname, $origsql, 1)), 6);

				$createindexsql = array();
$i = 0;

 
				$defs = preg_split("/[,]+/", $alterdefs, -1, PREG_SPLIT_NO_EMPTY);
$prevword = $table;
$oldcols = preg_split("/[,]+/", substr(trim($createtemptableSQL), strpos(trim($createtemptableSQL), '(')+1), -1, PREG_SPLIT_NO_EMPTY);

				$defs = preg_split("/[,]+/", $alterdefs, -1, PREG_SPLIT_NO_EMPTY);
$prevword = $table;
$oldcols = preg_split("/[,]+/", substr(trim($createtemptableSQL), strpos(trim($createtemptableSQL), '(')+1), -1, PREG_SPLIT_NO_EMPTY);

Zeile 1199Zeile 1271
				$newcolumns = '';
$oldcolumns = '';
reset($newcols);

				$newcolumns = '';
$oldcolumns = '';
reset($newcols);





				foreach($newcols as $key => $val)
{
$newcolumns .= ($newcolumns ? ', ' : '').$val;

				foreach($newcols as $key => $val)
{
$newcolumns .= ($newcolumns ? ', ' : '').$val;

Zeile 1209Zeile 1281
				$copytotempsql = 'INSERT INTO '.$tmpname.'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$table;
$dropoldsql = 'DROP TABLE '.$table;
$createtesttableSQL = $createtemptableSQL;

				$copytotempsql = 'INSERT INTO '.$tmpname.'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$table;
$dropoldsql = 'DROP TABLE '.$table;
$createtesttableSQL = $createtemptableSQL;





				foreach($defs as $def)
{
$defparts = preg_split("/[\s]+/", $def, -1, PREG_SPLIT_NO_EMPTY);

				foreach($defs as $def)
{
$defparts = preg_split("/[\s]+/", $def, -1, PREG_SPLIT_NO_EMPTY);

Zeile 1219Zeile 1291
					{
case 'change':
if(sizeof($defparts) <= 3)

					{
case 'change':
if(sizeof($defparts) <= 3)

							{

							{

								$this->error($alterdefs, 'near "'.$defparts[0].($defparts[1] ? ' '.$defparts[1] : '').($defparts[2] ? ' '.$defparts[2] : '').'": syntax error', E_USER_WARNING);
return false;
}

								$this->error($alterdefs, 'near "'.$defparts[0].($defparts[1] ? ' '.$defparts[1] : '').($defparts[2] ? ' '.$defparts[2] : '').'": syntax error', E_USER_WARNING);
return false;
}

Zeile 1227Zeile 1299
							if($severpos = strpos($createtesttableSQL, ' '.$defparts[1].' '))
{
if($newcols[$defparts[1]] != $defparts[1])

							if($severpos = strpos($createtesttableSQL, ' '.$defparts[1].' '))
{
if($newcols[$defparts[1]] != $defparts[1])

								{

								{

									$this->error($alterdefs, 'unknown column "'.$defparts[1].'" in "'.$table.'"');
return false;
}

									$this->error($alterdefs, 'unknown column "'.$defparts[1].'" in "'.$table.'"');
return false;
}

Zeile 1239Zeile 1311
								for($i = 2; $i < sizeof($defparts); $i++)
{
$insertval .= ' '.$defparts[$i];

								for($i = 2; $i < sizeof($defparts); $i++)
{
$insertval .= ' '.$defparts[$i];

								}

								}


if($nextcommapos)
{


if($nextcommapos)
{

Zeile 1257Zeile 1329
							}
break;
case 'drop':

							}
break;
case 'drop':

							if(sizeof($defparts) < 2)
{

							if(sizeof($defparts) < 2)
{

								$this->error($fullquery, 'near "'.$defparts[0].($defparts[1] ? ' '.$defparts[1] : '').'": syntax error');
return false;
}

								$this->error($fullquery, 'near "'.$defparts[0].($defparts[1] ? ' '.$defparts[1] : '').'": syntax error');
return false;
}

Zeile 1266Zeile 1338
							if($severpos = strpos($createtesttableSQL, ' '.$defparts[1].' '))
{
$nextcommapos = strpos($createtesttableSQL, ',', $severpos);

							if($severpos = strpos($createtesttableSQL, ' '.$defparts[1].' '))
{
$nextcommapos = strpos($createtesttableSQL, ',', $severpos);





								if($nextcommapos)

								if($nextcommapos)

								{

								{

									$createtesttableSQL = substr($createtesttableSQL, 0, $severpos).substr($createtesttableSQL, $nextcommapos + 1);

									$createtesttableSQL = substr($createtesttableSQL, 0, $severpos).substr($createtesttableSQL, $nextcommapos + 1);

								}

								}

								else
{
$createtesttableSQL = substr($createtesttableSQL, 0, $severpos-(strpos($createtesttableSQL, ',') ? 0 : 1) - 1).')';
}

unset($newcols[$defparts[1]]);

								else
{
$createtesttableSQL = substr($createtesttableSQL, 0, $severpos-(strpos($createtesttableSQL, ',') ? 0 : 1) - 1).')';
}

unset($newcols[$defparts[1]]);

							}

							}

							else
{
$this->error($fullquery, 'unknown column "'.$defparts[1].'" in "'.$table.'"');

							else
{
$this->error($fullquery, 'unknown column "'.$defparts[1].'" in "'.$table.'"');

Zeile 1316Zeile 1388
					$newcolumns .= ($newcolumns ? ', ' : '').$val;
$oldcolumns .= ($oldcolumns ? ', ' : '').$key;
}

					$newcolumns .= ($newcolumns ? ', ' : '').$val;
$oldcolumns .= ($oldcolumns ? ', ' : '').$key;
}





				$copytonewsql = 'INSERT INTO '.$table.'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$tmpname;



				$copytonewsql = 'INSERT INTO '.$table.'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$tmpname;



Zeile 1337Zeile 1409
				$this->error($fullquery, 'no such table: '.$table);
return false;
}

				$this->error($fullquery, 'no such table: '.$table);
return false;
}

			return true;

 
		}

		}

 
		return true;

	}

/**
* Drops a column
*

	}

/**
* Drops a column
*

	 * @param string The table
* @param string The column name


	 * @param string $table The table
* @param string $column The column name
* @return PDOStatement

	 */
function drop_column($table, $column)
{

	 */
function drop_column($table, $column)
{

Zeile 1355Zeile 1428
	/**
* Adds a column
*

	/**
* Adds a column
*

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


	 * @param string $table The table
* @param string $column The column name
* @param string $definition the new column definition
* @return PDOStatement

	 */
function add_column($table, $column, $definition)
{

	 */
function add_column($table, $column, $definition)
{

Zeile 1369Zeile 1443
	/**
* Modifies a column
*

	/**
* Modifies a column
*

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




	 * @param string $table The table
* @param string $column The column name
* @param string $new_definition the new column definition
* @param boolean|string $new_not_null Whether to "drop" or "set" the NOT NULL attribute (no change if false)
* @param boolean|string $new_default_value The new default value, or false to drop the attribute
* @return bool Returns true if all queries are executed successfully or false if one of them failed

	 */

	 */

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

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

	{
// We use a rename query as both need to duplicate the table etc...

	{
// We use a rename query as both need to duplicate the table etc...

		$this->rename_column($table, $column, $column, $new_definition);

		return $this->rename_column($table, $column, $column, $new_definition, $new_not_null, $new_default_value);

	}

/**
* Renames a column
*

	}

/**
* Renames a column
*

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




	 * @param string $table The table
* @param string $old_column The old column name
* @param string $new_column the new column name
* @param string $new_definition the new column definition
* @param boolean|string $new_not_null Whether to "drop" or "set" the NOT NULL attribute (no change if false)
* @param boolean|string $new_default_value The new default value, or false to drop the attribute
* @return bool Returns true if all queries are executed successfully

	 */

	 */

	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)

	{

	{

 
		if($new_not_null !== false)
{
if(strtolower($new_not_null) == "set")
{
$not_null = "NOT NULL";
}
else
{
$not_null = "NULL";
}
}
else
{
$not_null = '';
}

if($new_default_value !== false)
{
$default = "DEFAULT ".$new_default_value;
}
else
{
$default = '';
}


		// This will trigger the "alter_table_parse" function which will copy the table and rename the column

		// This will trigger the "alter_table_parse" function which will copy the table and rename the column

		return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} CHANGE {$old_column} {$new_column} {$new_definition}");

		return (bool) $this->write_query("ALTER TABLE {$this->table_prefix}{$table} CHANGE {$old_column} {$new_column} {$new_definition} {$not_null} {$default}");

	}

/**
* Fetch a list of database character sets this DBMS supports
*

	}

/**
* Fetch a list of database character sets this DBMS supports
*

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

	 * @return array|bool Array of supported character sets with array key being the name, array value being display name. False if unsupported

	 */
function fetch_db_charsets()
{

	 */
function fetch_db_charsets()
{

Zeile 1406Zeile 1511
	/**
* Fetch a database collation for a particular database character set
*

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

	 * @param string The database character set
* @return string The matching database collation, false if unsupported

	 * @param string $charset The database character set
* @return string|bool The matching database collation, false if unsupported

	 */
function fetch_charset_collation($charset)
{

	 */
function fetch_charset_collation($charset)
{

Zeile 1437Zeile 1542
	/**
* Binary database fields require special attention.
*

	/**
* Binary database fields require special attention.
*

	 * @param string Binary value

	 * @param string $string Binary value

	 * @return string Encoded binary value
*/
function escape_binary($string)

	 * @return string Encoded binary value
*/
function escape_binary($string)

Zeile 1448Zeile 1553
	/**
* Unescape binary data.
*

	/**
* Unescape binary data.
*

	 * @param string Binary value

	 * @param string $string Binary value

	 * @return string Encoded binary value
*/
function unescape_binary($string)

	 * @return string Encoded binary value
*/
function unescape_binary($string)