Vergleich inc/db_sqlite.php - 1.8.13 - 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']))
{
$query .= " ORDER BY ".$options['order_by'];

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

Zeile 651Zeile 661
		if(isset($options['limit_start']) && isset($options['limit']))
{
$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];

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

		}

		}

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

return $this->query($query);

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

return $this->query($query);

	}


	}


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

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

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)
{
if(isset($mybb->binary_fields[$table][$field]) && $mybb->binary_fields[$table][$field])

	{
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($value[0] != 'X') // Not escaped?
{

Zeile 686Zeile 696
				}

$array[$field] = $value;

				}

$array[$field] = $value;

			}

			}

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

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

Zeile 699Zeile 709
			INSERT
INTO {$this->table_prefix}{$table} (".$fields.")
VALUES (".$values.")

			INSERT
INTO {$this->table_prefix}{$table} (".$fields.")
VALUES (".$values.")

		");

		");

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

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

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

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

				}

				}

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

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

Zeile 781Zeile 791
		{
$quote = "";
}

		{
$quote = "";
}





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

		foreach($array 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);
}

$query .= $comma.$field."=".$value;

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

$query .= $comma.$field."=".$value;

			}

			}

			else
{
$quoted_value = $this->quote_val($value, $quote);

			else
{
$quoted_value = $this->quote_val($value, $quote);

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

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 1131Zeile 1141
				if($value[0] != 'X') // Not escaped?
{
$value = $this->escape_binary($value);

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

				}

				}

				
$values .= $comma.$value;
}

				
$values .= $comma.$value;
}

Zeile 1170Zeile 1180
				if($this->fetch_field($query, "count") == 1)
{
$update = true;

				if($this->fetch_field($query, "count") == 1)
{
$update = true;

				}
}

				}
}

			else
{
$query = $this->write_query("SELECT {$default_field} FROM {$this->table_prefix}{$table}");

			else
{
$query = $this->write_query("SELECT {$default_field} FROM {$this->table_prefix}{$table}");

Zeile 1293Zeile 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 1316Zeile 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 1325Zeile 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 1336Zeile 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 1415Zeile 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 1438Zeile 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 1460Zeile 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}");

	}

/**

	}

/**