Vergleich inc/db_sqlite.php - 1.8.6 - 1.8.36

  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 58Zeile 65
	 * @var resource
*/
public $link;

	 * @var resource
*/
public $link;

 

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


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

/**
* 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 134Zeile 146

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

$this->query_time += $query_time;


$query_time = get_execution_time();

$this->query_time += $query_time;


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



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


		if($this->db)
{
$this->query('PRAGMA short_column_names = 1');

		if($this->db)
{
$this->query('PRAGMA short_column_names = 1');

Zeile 185Zeile 203
				{
$query = $this->db->query($string);
$query->closeCursor();

				{
$query = $this->db->query($string);
$query->closeCursor();

				}

				}

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

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

Zeile 206Zeile 224
				);

$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 296Zeile 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;
}

Zeile 316Zeile 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

	 * Moves internal row pointer to the next row

	 *

	 *

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

	 * @param PDOStatement $query The query ID.
* @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 553Zeile 596
			if($row['name'] == $field)
{
++$exists;

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

			}

			}

		}

$query->closeCursor();

		}

$query->closeCursor();

Zeile 595Zeile 638
	 * @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.

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

Zeile 701Zeile 744
			foreach($values as $field => $value)
{
if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])

			foreach($values as $field => $value)
{
if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])

				{

				{

					if($value[0] != 'X') // Not escaped?
{
$value = $this->escape_binary($value);

					if($value[0] != 'X') // Not escaped?
{
$value = $this->escape_binary($value);

Zeile 717Zeile 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})
VALUES {$insert_rows}
");

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

		$query->closeCursor();
}

/**

		$query->closeCursor();
}

/**

	 * Build an update query from an array.
*
* @param string $table The table name to perform the query on.

	 * Build an update query from an array.
*
* @param string $table The table name to perform the query on.

Zeile 739Zeile 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;
}

$comma = "";

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

$comma = "";

		$query = "";

		$query = "";

		$quote = "'";

if($no_quote == true)

		$quote = "'";

if($no_quote == true)

Zeile 802Zeile 845
		}

return $quoted;

		}

return $quoted;

	}

/**

	}

/**

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

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

Zeile 823Zeile 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


/**
* Escape a string

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

	}

/**
* Gets the current version of SQLLite.
*
* @return string Version of MySQL.

	}

/**
* Gets the current version of SQLLite.
*
* @return string Version of MySQL.

	 */

	 */

	function get_version()
{
if($this->version)

	function get_version()
{
if($this->version)

Zeile 871Zeile 914
			return $this->version;
}
$this->version = $this->db->get_attribute("ATTR_SERVER_VERSION");

			return $this->version;
}
$this->version = $this->db->get_attribute("ATTR_SERVER_VERSION");





		return $this->version;
}


		return $this->version;
}


Zeile 882Zeile 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 925Zeile 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 1037Zeile 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);
}

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

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

 
		$this->table_prefix = $table_prefix_bak;


if(isset($query))
{


if(isset($query))
{

Zeile 1084Zeile 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 1417Zeile 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 1431Zeile 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}");

	}

/**

	}

/**