Vergleich inc/db_sqlite.php - 1.8.20 - 1.8.37

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 65Zeile 65
	 * @var resource
*/
public $link;

	 * @var resource
*/
public $link;

 

/**
* @var array
*/
public $connections = array();


/**
* Explanation of a query.


/**
* Explanation of a query.

Zeile 110Zeile 115

/**
* The database encoding currently in use (if supported)


/**
* The database encoding currently in use (if supported)

	 *

	 *

	 * @var string
*/
public $db_encoding = "";

	 * @var string
*/
public $db_encoding = "";

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

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





	/**
* Our pdo implementation
*

	/**
* Our pdo implementation
*

Zeile 131Zeile 136

/**
* Connect to the database server.


/**
* Connect to the database server.

	 *

	 *

	 * @param array $config Array of DBMS connection details.
* @return bool Returns false on failure, otherwise true
*/
function connect($config)
{
get_execution_time();

	 * @param array $config Array of DBMS connection details.
* @return bool Returns false on failure, otherwise true
*/
function connect($config)
{
get_execution_time();





		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 197Zeile 208
				{
$query = $this->alter_table_parse($tablename, $alterdefs, $string);
}

				{
$query = $this->alter_table_parse($tablename, $alterdefs, $string);
}

			}

			}

		}
else
{

		}
else
{

Zeile 211Zeile 222
					"message" => $exception->getMessage(),
"code" => $exception->getCode()
);

					"message" => $exception->getMessage(),
"code" => $exception->getCode()
);





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

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

Zeile 219Zeile 230
		$this->query_objects[] = $query;

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

		$this->query_objects[] = $query;

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

		}


		}


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

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

		}

return $query;
}

		}

return $query;
}


/**
* Explain a query on the database.


/**
* Explain a query on the database.

Zeile 261Zeile 272
				"</tr>\n".
"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #fff;\">Query Time: ".format_time_duration($qtime)."</td>\n".

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

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

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

				"<br />\n";
}
else
{
$this->explain .= "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n".

				"<br />\n";
}
else
{
$this->explain .= "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n".

				"<tr>\n".

				"<tr>\n".

				"<td style=\"background-color: #ccc;\"><strong>#".$this->query_count." - Write Query</strong></td>\n".
"</tr>\n".
"<tr style=\"background-color: #fefefe;\">\n".
"<td><span style=\"font-family: Courier; font-size: 14px;\">".htmlspecialchars_uni($string)."</span></td>\n".

				"<td style=\"background-color: #ccc;\"><strong>#".$this->query_count." - Write Query</strong></td>\n".
"</tr>\n".
"<tr style=\"background-color: #fefefe;\">\n".
"<td><span style=\"font-family: Courier; font-size: 14px;\">".htmlspecialchars_uni($string)."</span></td>\n".

				"</tr>\n".

				"</tr>\n".

				"<tr>\n".
"<td bgcolor=\"#ffffff\">Query Time: ".format_time_duration($qtime)."</td>\n".
"</tr>\n".

				"<tr>\n".
"<td bgcolor=\"#ffffff\">Query Time: ".format_time_duration($qtime)."</td>\n".
"</tr>\n".

Zeile 283Zeile 294

$this->querylist[$this->query_count]['query'] = $string;
$this->querylist[$this->query_count]['time'] = $qtime;


$this->querylist[$this->query_count]['query'] = $string;
$this->querylist[$this->query_count]['time'] = $qtime;

	}


	}


	/**
* Execute a write query on the database

	/**
* Execute a write query on the database

	 *

	 *

	 * @param string $query The query SQL.
* @param boolean|int $hide_errors 1 if hide errors, 0 if not.
* @return PDOStatement 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.

Zeile 305Zeile 316
	 * @return array The array of results.
*/
function fetch_array($query, $resulttype=PDO::FETCH_BOTH)

	 * @return array The array of results.
*/
function fetch_array($query, $resulttype=PDO::FETCH_BOTH)

	{

	{

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

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

	}


	}


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

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

Zeile 325Zeile 336
			$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
*
* @param PDOStatement $query The query ID.

	 * Moves internal row pointer to the next row
*
* @param PDOStatement $query The query ID.

Zeile 371Zeile 386

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

Zeile 414Zeile 429
	 * @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)

	{

	{

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

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

Zeile 759Zeile 774
	 *
* @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 767Zeile 782
	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))
{
return false;

		if(!is_array($array))
{
return false;

Zeile 778Zeile 793
		$quote = "'";

if($no_quote == true)

		$quote = "'";

if($no_quote == true)

		{

		{

			$quote = "";
}


			$quote = "";
}


Zeile 834Zeile 849

/**
* Build a delete query.


/**
* Build a delete query.

	 *

	 *

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

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

Zeile 851Zeile 866
		$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
*
* @param string $string The string to be escaped.
* @return string The escaped string.

	 * Escape a string
*
* @param string $string The string to be escaped.
* @return string The escaped string.

	 */

	 */

	function escape_string($string)
{
$string = $this->db->escape_string($string);

	function escape_string($string)
{
$string = $this->db->escape_string($string);

Zeile 872Zeile 887
	 * @return boolean Returns true on success, false on failure
*/
function free_result($query)

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

	{

	{

		return true;
}


		return true;
}


Zeile 884Zeile 899
	 */
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 910Zeile 925
	 */
function optimize_table($table)
{

	 */
function optimize_table($table)
{

		$query = $this->query("VACUUM ".$this->table_prefix.$table."");
$query->closeCursor();

		// SQLite doesn't support table level optimization.
// Using `VACUUM [main | $db_name]` may also be blocked by any opened query cursor, hence generating an error.

	}

/**

	}

/**

Zeile 953Zeile 968
	 */
function show_fields_from($table)
{

	 */
function show_fields_from($table)
{

		$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}'");
$this->set_table_prefix($old_tbl_prefix);
$table = trim(preg_replace('#CREATE\s+TABLE\s+"?'.$this->table_prefix.$table.'"?#i', '', $this->fetch_field($query, "sql")));
$query->closeCursor();

preg_match('#\((.*)\)#s', $table, $matches);


		$query = $this->write_query("PRAGMA TABLE_INFO('".$this->table_prefix.$table."')");









		$field_info = array();

		$field_info = array();

		$table_cols = explode(',', trim($matches[1]));
foreach($table_cols as $declaration)

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


		{

		{

			$entities = preg_split('#\s+#', trim($declaration));
$column_name = preg_replace('/"?([^"]+)"?/', '\1', $entities[0]);












			if(!empty($field['pk']))
{
$field['_key'] = 'PRI';
$field['_extra'] = 'auto_increment';
}
else
{
$field['_key'] = '';
$field['_extra'] = '';
}

// SQLite allows NULLs in most PRIMARY KEY columns due to a bug in early versions, even in an INTEGER PRIMARY KEY column, read https://sqlite.org/lang_createtable.html for details. We won't fix this for consistency among other database engines.
$field['_nullable'] = $field['notnull'] ? 'NO' : 'YES';





			$field_info[] = array('Extra' => $entities[1], 'Field' => $column_name);








			$field_info[] = array(
'Field' => $field['name'],
'Type' => $field['type'],
'Null' => $field['_nullable'],
'Key' => $field['_key'],
'Default' => $field['dflt_value'],
'Extra' => $field['_extra'],
);

		}

		}



		$query->closeCursor();

		return $field_info;
}


		return $field_info;
}


Zeile 995Zeile 1019
	 */

function supports_fulltext($table)

	 */

function supports_fulltext($table)

	{
return false;
}

/**

	{
return false;
}

/**

	 * Returns whether or not this database engine supports boolean fulltext matching.
*
* @param string $table The table to be checked.

	 * Returns whether or not this database engine supports boolean fulltext matching.
*
* @param string $table The table to be checked.

Zeile 1037Zeile 1061

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


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

	 *

	 *

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

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

	function index_exists($table, $index)

	{

	{

		return false;
}


		return false;
}


Zeile 1055Zeile 1079
	 * @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)
{

	{
if($table_prefix == false)
{

			$table_prefix = "";

			$table_prefix = "";

		}

		}

		else
{
$table_prefix = $this->table_prefix;

		else
{
$table_prefix = $this->table_prefix;

		}




		}

$table_prefix_bak = $this->table_prefix;
$this->table_prefix = '';

		if($hard == false)

		if($hard == false)

		{
if($this->table_exists($table))

		{
if($this->table_exists($table_prefix.$table))

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

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

Zeile 1075Zeile 1101
		else
{
$query = $this->query('DROP TABLE '.$table_prefix.$table);

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

		}



		}
$this->table_prefix = $table_prefix_bak;


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

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

Zeile 1115Zeile 1142
	 * @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

	 * @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)
{
global $mybb;

	function replace_query($table, $replacements=array(), $default_field="", $insert_id=true)
{
global $mybb;

Zeile 1446Zeile 1473
	 * @param string $table The table
* @param string $column The column name
* @param string $new_definition 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);

	}

/**

	}

/**

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

	}

/**

	}

/**