Vergleich inc/db_sqlite.php - 1.8.6 - 1.8.27

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
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 75Zeile 82

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


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

	 *

	 *

	 * @var string
*/
public $table_type = "myisam";

	 * @var string
*/
public $table_type = "myisam";

Zeile 119Zeile 126
	 * Our pdo implementation
*
* @var dbpdoEngine

	 * Our pdo implementation
*
* @var dbpdoEngine

	 */

	 */

	var $db;

	var $db;





	/**
* Connect to the database server.
*

	/**
* Connect to the database server.
*

Zeile 134Zeile 141

require_once MYBB_ROOT."inc/db_pdo.php";



require_once MYBB_ROOT."inc/db_pdo.php";


		$this->db = new dbpdoEngine("sqlite:{$config['database']}");







		try {
$this->db = new dbpdoEngine("sqlite:{$config['database']}");
} catch (Exception $ex) {
$this->error("[READ] Unable to open the SQLite database");

return false;
}


$query_time = get_execution_time();



$query_time = get_execution_time();


Zeile 164Zeile 177
	function query($string, $hide_errors=0, $write_query=0)
{
global $mybb;

	function query($string, $hide_errors=0, $write_query=0)
{
global $mybb;





		get_execution_time();

if(strtolower(substr(ltrim($string), 0, 5)) == 'alter')

		get_execution_time();

if(strtolower(substr(ltrim($string), 0, 5)) == 'alter')

Zeile 206Zeile 219
				);

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

		{

		{

			$this->error($string, $query);
exit;

			$this->error($string, $query);
exit;

		}

		}


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


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





		if($mybb->debug_mode)
{
$this->explain_query($string, $query_time);

		if($mybb->debug_mode)
{
$this->explain_query($string, $query_time);

Zeile 228Zeile 243
		{
$query->closeCursor();
return null;

		{
$query->closeCursor();
return null;

		}


		}


		return $query;
}


		return $query;
}


Zeile 294Zeile 309
	 * @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.

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

	 */

	 */

	function fetch_array($query, $resulttype=PDO::FETCH_BOTH)
{
$array = $this->db->fetch_array($query, $resulttype);

	function fetch_array($query, $resulttype=PDO::FETCH_BOTH)
{
$array = $this->db->fetch_array($query, $resulttype);

Zeile 316Zeile 331
			$this->data_seek($query, $row);
}
$array = $this->fetch_array($query);

			$this->data_seek($query, $row);
}
$array = $this->fetch_array($query);

		return $array[$field];
}





		if($array !== null && $array !== false)
{
return $array[$field];
}
return null;
}


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


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

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

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

	{

	{

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

	}

/**

	}

/**

Zeile 339Zeile 377
	function num_rows($query)
{
return $this->db->num_rows($query);

	function num_rows($query)
{
return $this->db->num_rows($query);

	}

/**

	}

/**

	 * Return the last id number of inserted data.

	 * Return the last id number of inserted data.

	 *

	 *

	 * @param string $name
* @return int The id number.

	 * @param string $name
* @return int The id number.

	 */

	 */

	function insert_id($name="")

	function insert_id($name="")

	{

	{

		return $this->db->insert_id($name);

		return $this->db->insert_id($name);

	}


	}


	/**
* Close the connection with the DBMS.
*

	/**
* Close the connection with the DBMS.
*

Zeile 359Zeile 397
	function close()
{
return;

	function close()
{
return;

	}

/**

	}

/**

	 * Return an error number.
*
* @param PDOStatement $query

	 * Return an error number.
*
* @param PDOStatement $query

Zeile 375Zeile 413
		}

$this->error_number = $this->db->error_number($query);

		}

$this->error_number = $this->db->error_number($query);





		return $this->error_number;
}

/**
* Return an error string.

		return $this->error_number;
}

/**
* Return an error string.

	 *
* @param PDOStatement $query

	 *
* @param PDOStatement $query

	 * @return string The explanation for the current error.
*/
function error_string($query=null)

	 * @return string The explanation for the current error.
*/
function error_string($query=null)

Zeile 396Zeile 434

$error_string = $this->db->error_string($query);
$this->error_number = "";


$error_string = $this->db->error_string($query);
$this->error_number = "";





			return $error_string;
}

return '';

			return $error_string;
}

return '';

	}


	}


	/**
* Output a database error.
*

	/**
* Output a database error.
*

Zeile 416Zeile 454
		if($this->error_reporting)
{
if($query == null)

		if($this->error_reporting)
{
if($query == null)

			{

			{

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

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

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

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

			}

			}


if($error == "")
{


if($error == "")
{

Zeile 463Zeile 501
	function affected_rows($query=null)
{
if($query == null)

	function affected_rows($query=null)
{
if($query == null)

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

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

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

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


/**
* Return the number of fields.


/**
* Return the number of fields.

Zeile 488Zeile 526

/**
* Lists all tables in the database.


/**
* Lists all tables in the database.

	 *

	 *

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

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

Zeile 500Zeile 538
			$query = $this->query("SELECT tbl_name FROM sqlite_master WHERE type = 'table' AND tbl_name LIKE '".$this->escape_string($prefix)."%'");
}
else

			$query = $this->query("SELECT tbl_name FROM sqlite_master WHERE type = 'table' AND tbl_name LIKE '".$this->escape_string($prefix)."%'");
}
else

		{

		{

			$query = $this->query("SELECT tbl_name FROM sqlite_master WHERE type = 'table'");

			$query = $this->query("SELECT tbl_name FROM sqlite_master WHERE type = 'table'");

		}

		}


$tables = array();
while($table = $this->fetch_array($query))
{
$tables[] = $table['tbl_name'];


$tables = array();
while($table = $this->fetch_array($query))
{
$tables[] = $table['tbl_name'];

		}
$query->closeCursor();

		}
$query->closeCursor();

		return $tables;
}

		return $tables;
}





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

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

Zeile 526Zeile 564
		$query->closeCursor();

if($exists > 0)

		$query->closeCursor();

if($exists > 0)

		{

		{

			return true;
}
else
{

			return true;
}
else
{

			return false;

			return false;

		}
}

		}
}





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

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

Zeile 545Zeile 583
	function field_exists($field, $table)
{
$query = $this->query("PRAGMA table_info('{$this->table_prefix}{$table}')");

	function field_exists($field, $table)
{
$query = $this->query("PRAGMA table_info('{$this->table_prefix}{$table}')");





		$exists = 0;

		$exists = 0;





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

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

			}
}

$query->closeCursor();


			}
}

$query->closeCursor();


		if($exists > 0)
{
return true;

		if($exists > 0)
{
return true;

Zeile 601Zeile 639
		$query = "SELECT ".$fields." FROM ".$this->table_prefix.$table;

if($conditions != "")

		$query = "SELECT ".$fields." FROM ".$this->table_prefix.$table;

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'];

Zeile 623Zeile 661
		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.
*

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

Zeile 640Zeile 678
	 * @return int|bool The insert ID if available or false if an error is found
*/
function insert_query($table, $array)

	 * @return int|bool The insert ID if available or false if an error is found
*/
function insert_query($table, $array)

	{
global $mybb;

if(!is_array($array))
{

	{
global $mybb;

if(!is_array($array))
{

			return false;
}


			return false;
}


Zeile 688Zeile 726
		global $mybb;

if(!is_array($array))

		global $mybb;

if(!is_array($array))

		{

		{

			return;
}
// Field names

			return;
}
// Field names

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

	 *
* @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 $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.

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

Zeile 739Zeile 777
	function update_query($table, $array, $where="", $limit="", $no_quote=false)
{
global $mybb;

	function update_query($table, $array, $where="", $limit="", $no_quote=false)
{
global $mybb;





		if(!is_array($array))

		if(!is_array($array))

		{

		{

			return false;

			return false;

		}


		}


		$comma = "";
$query = "";
$quote = "'";

		$comma = "";
$query = "";
$quote = "'";

Zeile 752Zeile 790
		if($no_quote == true)
{
$quote = "";

		if($no_quote == true)
{
$quote = "";

		}

		}


foreach($array as $field => $value)
{


foreach($array as $field => $value)
{

Zeile 764Zeile 802
				}

$query .= $comma.$field."=".$value;

				}

$query .= $comma.$field."=".$value;

			}

			}

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

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

Zeile 772Zeile 810
				$query .= $comma.$field."={$quoted_value}";
}
$comma = ', ';

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

		}


		}


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

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

Zeile 795Zeile 833
		if(is_int($value))
{
$quoted = $value;

		if(is_int($value))
{
$quoted = $value;

		}

		}

		else

		else

		{

		{

			$quoted = $quote . $value . $quote;
}

			$quoted = $quote . $value . $quote;
}





		return $quoted;
}


		return $quoted;
}


Zeile 816Zeile 854
	{
$query = "";
if(!empty($where))

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

		{

		{

			$query .= " WHERE $where";
}


			$query .= " WHERE $where";
}


Zeile 856Zeile 894
	 */
function escape_string_like($string)
{

	 */
function escape_string_like($string)
{

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

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

	}

/**

	}

/**

Zeile 904Zeile 942
	 * @return string The SQLite command to create the specified table.
*/
function show_create_table($table)

	 * @return string The SQLite command to create the specified table.
*/
function show_create_table($table)

	{
$old_tbl_prefix = $this->table_prefix;
$this->set_table_prefix("");

	{
$old_tbl_prefix = $this->table_prefix;
$this->set_table_prefix("");

		$query = $this->simple_select("sqlite_master", "sql", "type = 'table' AND name = '{$old_tbl_prefix}{$table}' ORDER BY type DESC, name");
$this->set_table_prefix($old_tbl_prefix);


		$query = $this->simple_select("sqlite_master", "sql", "type = 'table' AND name = '{$old_tbl_prefix}{$table}' ORDER BY type DESC, name");
$this->set_table_prefix($old_tbl_prefix);


Zeile 949Zeile 987

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


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

	 *
* @param string $table The name of the table.

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

	 * @param string $index Optionally specify the name of the index.
* @return boolean True or false if the table has a fulltext index or not.
*/

Zeile 991Zeile 1029
	 * @return bool
*/
function create_fulltext_index($table, $column, $name="")

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

Zeile 1027Zeile 1065
	 * @param boolean $table_prefix use table prefix
*/
function drop_table($table, $hard=false, $table_prefix=true)

	 * @param boolean $table_prefix use table prefix
*/
function drop_table($table, $hard=false, $table_prefix=true)

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

if($hard == false)
{

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

if($hard == false)
{

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

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

Zeile 1081Zeile 1119

/**
* Replace contents of table with values


/**
* Replace contents of table with values

	 *

	 *

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

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

	 * @param mixed $default_field The default field(s)


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

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

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

	{
global $mybb;


	{
global $mybb;


Zeile 1105Zeile 1144
				}

$values .= $comma.$value;

				}

$values .= $comma.$value;

			}

			}

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

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

Zeile 1149Zeile 1188
				$search_bit = "{$default_field}='".$replacements[$default_field]."'";

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

				$search_bit = "{$default_field}='".$replacements[$default_field]."'";

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

				{

				{

					if($column[$default_field] == $replacements[$default_field])
{
$update = true;

					if($column[$default_field] == $replacements[$default_field])
{
$update = true;

Zeile 1257Zeile 1296
				{
$defparts = preg_split("/[\s]+/", $def, -1, PREG_SPLIT_NO_EMPTY);
$action = strtolower($defparts[0]);

				{
$defparts = preg_split("/[\s]+/", $def, -1, PREG_SPLIT_NO_EMPTY);
$action = strtolower($defparts[0]);





					switch($action)
{
case 'change':

					switch($action)
{
case 'change':

Zeile 1300Zeile 1339
							}
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 1344Zeile 1383
				if($query === false)
{
return false;

				if($query === false)
{
return false;

				}

				}

				$query->closeCursor();
// End block


				$query->closeCursor();
// End block


Zeile 1386Zeile 1425

/**
* Drops a column


/**
* Drops a column

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

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

	 * @return PDOStatement
*/
function drop_column($table, $column)

	 * @return PDOStatement
*/
function drop_column($table, $column)

Zeile 1409Zeile 1448
		$query = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ADD {$column} {$definition}");
$query->closeCursor();
return $query;

		$query = $this->write_query("ALTER TABLE {$this->table_prefix}{$table} ADD {$column} {$definition}");
$query->closeCursor();
return $query;

	}


	}


	/**
* Modifies a column

	/**
* Modifies a column

	 *

	 *

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

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

	 * @param string $new_definition the new column definition
*/
function modify_column($table, $column, $new_definition)
{




	 * @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, $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
*

Zeile 1431Zeile 1473
	 * @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 string $old_column The old column name
* @param string $new_column the new column name
* @param string $new_definition the new column definition

	 * @return PDOStatement



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

	}

/**

	}

/**