Vergleich inc/db_sqlite.php - 1.8.9 - 1.8.30

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 141Zeile 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 325Zeile 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;

	}

/**

	}

/**

Zeile 636Zeile 646
		if(isset($options['group_by']))
{
$query .= " GROUP BY ".$options['group_by'];

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

		}

		}


if(isset($options['order_by']))
{


if(isset($options['order_by']))
{

Zeile 668Zeile 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))
{
return false;
}

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

	{
global $mybb;

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

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

			if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])
{
if($value[0] != 'X') // Not escaped?

			if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])
{
if($value[0] != 'X') // Not escaped?

Zeile 718Zeile 728
		if(!is_array($array))
{
return;

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

		}

		}

		// Field names
$fields = array_keys($array[0]);
$fields = implode(",", $fields);

		// Field names
$fields = array_keys($array[0]);
$fields = implode(",", $fields);

Zeile 800Zeile 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";
}





		$query = $this->query("UPDATE {$this->table_prefix}$table SET $query");
$query->closeCursor();
return $query;

		$query = $this->query("UPDATE {$this->table_prefix}$table SET $query");
$query->closeCursor();
return $query;

Zeile 821Zeile 831
	private function quote_val($value, $quote="'")
{
if(is_int($value))

	private function quote_val($value, $quote="'")
{
if(is_int($value))

		{

		{

			$quoted = $value;
}
else

			$quoted = $value;
}
else

Zeile 841Zeile 851
	 * @return PDOStatement The query data.
*/
function delete_query($table, $where="", $limit="")

	 * @return PDOStatement The query data.
*/
function delete_query($table, $where="", $limit="")

	{

	{

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

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

Zeile 884Zeile 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 922Zeile 932
	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 965Zeile 975
		$field_info = array();
$table_cols = explode(',', trim($matches[1]));
foreach($table_cols as $declaration)

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

		{

		{

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


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


Zeile 1112Zeile 1122
	 *
* @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 1292Zeile 1303
							if(sizeof($defparts) <= 3)
{
$this->error($alterdefs, 'near "'.$defparts[0].($defparts[1] ? ' '.$defparts[1] : '').($defparts[2] ? ' '.$defparts[2] : '').'": syntax error', E_USER_WARNING);

							if(sizeof($defparts) <= 3)
{
$this->error($alterdefs, 'near "'.$defparts[0].($defparts[1] ? ' '.$defparts[1] : '').($defparts[2] ? ' '.$defparts[2] : '').'": syntax error', E_USER_WARNING);

								return false;
}

if($severpos = strpos($createtesttableSQL, ' '.$defparts[1].' '))

								return false;
}

if($severpos = strpos($createtesttableSQL, ' '.$defparts[1].' '))

							{
if($newcols[$defparts[1]] != $defparts[1])

							{
if($newcols[$defparts[1]] != $defparts[1])

								{

								{

									$this->error($alterdefs, 'unknown column "'.$defparts[1].'" in "'.$table.'"');
return false;

									$this->error($alterdefs, 'unknown column "'.$defparts[1].'" in "'.$table.'"');
return false;

								}

								}


$newcols[$defparts[1]] = $defparts[2];
$nextcommapos = strpos($createtesttableSQL, ',', $severpos);
$insertval = '';


$newcols[$defparts[1]] = $defparts[2];
$nextcommapos = strpos($createtesttableSQL, ',', $severpos);
$insertval = '';





								for($i = 2; $i < sizeof($defparts); $i++)
{
$insertval .= ' '.$defparts[$i];

								for($i = 2; $i < sizeof($defparts); $i++)
{
$insertval .= ' '.$defparts[$i];

Zeile 1315Zeile 1326
								if($nextcommapos)
{
$createtesttableSQL = substr($createtesttableSQL, 0, $severpos).$insertval.substr($createtesttableSQL, $nextcommapos);

								if($nextcommapos)
{
$createtesttableSQL = substr($createtesttableSQL, 0, $severpos).$insertval.substr($createtesttableSQL, $nextcommapos);

								}
else

								}
else

								{
$createtesttableSQL = substr($createtesttableSQL, 0, $severpos-(strpos($createtesttableSQL, ',') ? 0 : 1)).$insertval.')';
}

								{
$createtesttableSQL = substr($createtesttableSQL, 0, $severpos-(strpos($createtesttableSQL, ',') ? 0 : 1)).$insertval.')';
}

Zeile 1324Zeile 1335
							else
{
$this->error($fullquery, 'unknown column "'.$defparts[1].'" in "'.$table.'"', E_USER_WARNING);

							else
{
$this->error($fullquery, 'unknown column "'.$defparts[1].'" in "'.$table.'"', E_USER_WARNING);

								return false;

								return false;

							}
break;
case 'drop':

							}
break;
case 'drop':

Zeile 1335Zeile 1346
							}

if($severpos = strpos($createtesttableSQL, ' '.$defparts[1].' '))

							}

if($severpos = strpos($createtesttableSQL, ' '.$defparts[1].' '))

							{
$nextcommapos = strpos($createtesttableSQL, ',', $severpos);

							{
$nextcommapos = strpos($createtesttableSQL, ',', $severpos);


if($nextcommapos)
{


if($nextcommapos)
{

Zeile 1414Zeile 1425

/**
* Drops a column


/**
* Drops a column

	 *
* @param string $table The table
* @param string $column The column name
* @return PDOStatement
*/

	 *
* @param string $table The table
* @param string $column The column name
* @return PDOStatement
*/

	function drop_column($table, $column)
{
return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} DROP {$column}");

	function drop_column($table, $column)
{
return $this->write_query("ALTER TABLE {$this->table_prefix}{$table} DROP {$column}");

Zeile 1437Zeile 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 $table The table

	 * @param string $column The column name

	 * @param string $column The column name

	 * @param string $new_definition the new column 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)

	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 1459Zeile 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}");

	}

/**

	}

/**