Vergleich inc/db_sqlite.php - 1.8.9 - 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 251Zeile 262
	function explain_query($string, $qtime)
{
if(preg_match("#^\s*select#i", $string))

	function explain_query($string, $qtime)
{
if(preg_match("#^\s*select#i", $string))

		{

		{

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

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

				"<tr>\n".

				"<tr>\n".

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

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

				"</tr>\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: #fff;\">Query Time: ".format_time_duration($qtime)."</td>\n".

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

				"</tr>\n".

				"</tr>\n".

				"</table>\n".
"<br />\n";
}

				"</table>\n".
"<br />\n";
}

Zeile 293Zeile 304
	 * @return PDOStatement The query data.
*/
function write_query($query, $hide_errors=0)

	 * @return PDOStatement The query data.
*/
function write_query($query, $hide_errors=0)

	{

	{

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


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


Zeile 303Zeile 314
	 * @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 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;

	}

/**

	}

/**

Zeile 581Zeile 596
			if($row['name'] == $field)
{
++$exists;

			if($row['name'] == $field)
{
++$exists;

			}
}

$query->closeCursor();


			}
}

$query->closeCursor();


		if($exists > 0)
{
return true;

		if($exists > 0)
{
return true;

Zeile 668Zeile 683
	 * @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 714Zeile 729
	function insert_query_multiple($table, $array)
{
global $mybb;

	function insert_query_multiple($table, $array)
{
global $mybb;





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

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

Zeile 736Zeile 751
					}

$values[$field] = $value;

					}

$values[$field] = $value;

				}

				}

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

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

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

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





		$query = $this->write_query("
INSERT
INTO {$this->table_prefix}{$table} ({$fields})

		$query = $this->write_query("
INSERT
INTO {$this->table_prefix}{$table} ({$fields})

Zeile 756Zeile 771

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


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

	 *
* @param string $table The table name to perform the query on.

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

Zeile 800Zeile 815
				$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 844Zeile 859
	{
$query = "";
if(!empty($where))

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

		{

		{

			$query .= " WHERE $where";
}


			$query .= " WHERE $where";
}


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 909Zeile 924
	 * @param string $table The name of the table to be optimized.
*/
function optimize_table($table)

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

/**

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

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

Zeile 932Zeile 947
	 * @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);

$result = $this->fetch_field($query, 'sql');

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

$result = $this->fetch_field($query, 'sql');





		$query->closeCursor();

		$query->closeCursor();





		return $result;
}


		return $result;
}


Zeile 952Zeile 967
	 * @return array Field info for that table
*/
function show_fields_from($table)

	 * @return array Field info for that 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 983Zeile 1007
	 * @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="")

	{

	{

		return false;
}


		return false;
}


Zeile 1025Zeile 1049

/**
* Drop an index with the specified name from the specified table


/**
* Drop an index with the specified name from the specified table

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

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

	 * @param string $name The name of the index.
*/
function drop_index($table, $name)

	 * @param string $name The name of the index.
*/
function drop_index($table, $name)

Zeile 1065Zeile 1089
			$table_prefix = $this->table_prefix;
}


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

			}

			}

		}
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))
{


if(isset($query))
{

Zeile 1112Zeile 1139
	 *
* @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 1445Zeile 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 1459Zeile 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}");

	}

/**

	}

/**