Vergleich inc/db_sqlite.php - 1.8.22 - 1.8.34

  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 75Zeile 80

/**
* The current version of SQLite.


/**
* The current version of SQLite.

	 *
* @var string

	 *
* @var string

	 */
public $version;


	 */
public $version;


Zeile 93Zeile 98
	 * @var string
*/
public $table_prefix;

	 * @var string
*/
public $table_prefix;


/**


/**

	 * The extension used to run the SQL database
*
* @var string

	 * The extension used to run the SQL database
*
* @var string

Zeile 103Zeile 108

/**
* 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 121Zeile 126
	 * @var float
*/
public $query_time = 0;

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


/**


/**

	 * Our pdo implementation
*
* @var dbpdoEngine

	 * Our pdo implementation
*
* @var dbpdoEngine

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



$query_time = get_execution_time();


Zeile 290Zeile 301
	 *
* @param string $query The query SQL.
* @param boolean|int $hide_errors 1 if hide errors, 0 if not.

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

	 * @return PDOStatement The query data.
*/

	 * @return PDOStatement The query data.
*/

	function write_query($query, $hide_errors=0)
{
return $this->query($query, $hide_errors);

	function write_query($query, $hide_errors=0)
{
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 341Zeile 356

/**
* Closes cursors of registered queries.


/**
* Closes cursors of registered queries.

	 *
*/

	 *
*/

	function close_cursors()
{
$result = true;

	function close_cursors()
{
$result = true;

Zeile 367Zeile 382
	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.
*
* @param string $name

	 * Return the last id number of inserted data.
*
* @param string $name

Zeile 382Zeile 397

/**
* Close the connection with the DBMS.


/**
* Close the connection with the DBMS.

	 *

	 *

	 */
function close()
{

	 */
function close()
{

Zeile 396Zeile 411
	 * @return int The error number of the current error.
*/
function error_number($query=null)

	 * @return int The error number of the current error.
*/
function error_number($query=null)

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

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


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

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


		return $this->error_number;
}


		return $this->error_number;
}


Zeile 627Zeile 642
	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']))


if(isset($options['group_by']))

		{

		{

			$query .= " GROUP BY ".$options['group_by'];
}

if(isset($options['order_by']))
{
$query .= " ORDER BY ".$options['order_by'];

			$query .= " GROUP BY ".$options['group_by'];
}

if(isset($options['order_by']))
{
$query .= " ORDER BY ".$options['order_by'];





			if(isset($options['order_dir']))
{
$query .= " ".strtoupper($options['order_dir']);

			if(isset($options['order_dir']))
{
$query .= " ".strtoupper($options['order_dir']);

Zeile 655Zeile 670
		else if(isset($options['limit']))
{
$query .= " LIMIT ".$options['limit'];

		else if(isset($options['limit']))
{
$query .= " LIMIT ".$options['limit'];

		}


		}


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


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


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;

	{
global $mybb;


if(!is_array($array))
{


if(!is_array($array))
{

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

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

				}

				}

				
$array[$field] = $value;
}

				
$array[$field] = $value;
}

Zeile 738Zeile 753
					$values[$field] = $value;
}
else

					$values[$field] = $value;
}
else

				{

				{

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

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

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.

	}

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

	 */

	 */

	function analyze_table($table)
{
$query = $this->query("ANALYZE ".$this->table_prefix.$table."");

	function analyze_table($table)
{
$query = $this->query("ANALYZE ".$this->table_prefix.$table."");

		$query->closeCursor();
}


		$query->closeCursor();
}


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

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

Zeile 936Zeile 951
		$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");

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


		$this->set_table_prefix($old_tbl_prefix);


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

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





		$query->closeCursor();

return $result;
}

		$query->closeCursor();

return $result;
}





	/**
* Show the "show fields from" command for a specific table.
*

	/**
* Show the "show fields from" command for a specific table.
*

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

Zeile 1076Zeile 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))
{