Vergleich inc/db_sqlite2.php - 1.4.2 - 1.4.10

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 6
 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/license.php
*

 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/license.php
*

 * $Id: db_sqlite2.php 4067 2008-08-04 03:59:08Z Tikitiki $

 * $Id: db_sqlite2.php 4335 2009-03-22 18:34:20Z Tikitiki $

 */


 */


class DB_SQLite

class DB_SQLite2

{
/**
* The title of this layer.

{
/**
* The title of this layer.

Zeile 147Zeile 147

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



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


		sqlite_query('PRAGMA short_column_names = 1', $this->link);

		@sqlite_query('PRAGMA short_column_names = 1', $this->link);

		return $this->link;
}


		return $this->link;
}


Zeile 175Zeile 175
			else
{
$alterdefs = preg_replace("#\sAFTER\s([a-z_]+?)(;*?)$#i", "", $alterdefs);

			else
{
$alterdefs = preg_replace("#\sAFTER\s([a-z_]+?)(;*?)$#i", "", $alterdefs);

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


				$alterdefs = preg_replace("#;$#i", "", $alterdefs);
$query = $this->alter_table_parse($tablename, $alterdefs, $string);

			}
}
else
{

			}
}
else
{

			$query = sqlite_query($this->link, $string, SQLITE_BOTH, $this->error_msg);








			if(version_compare(phpversion(), "5.1.0", ">="))
{
$query = sqlite_query($this->link, $string, SQLITE_BOTH, $this->error_msg);
}
else
{
$query = sqlite_query($this->link, $string, SQLITE_BOTH);
}

		}

if($this->error_msg && !$hide_errors)

		}

if($this->error_msg && !$hide_errors)

		{

		{

			$this->error($string, $this->error_msg, 1);

			$this->error($string, $this->error_msg, 1);

			exit;

			exit;

		}

if($query === false && !$hide_errors)
{
$this->error($string);
exit;

		}

if($query === false && !$hide_errors)
{
$this->error($string);
exit;

		}


		}


		$query_time = $this->get_execution_time();
$this->query_time += $query_time;
$this->query_count++;

		$query_time = $this->get_execution_time();
$this->query_time += $query_time;
$this->query_count++;

Zeile 231Zeile 239
			$this->explain .= "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n".
"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #ccc;\"><strong>#".$this->query_count." - Select Query</strong></td>\n".

			$this->explain .= "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\">\n".
"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #ccc;\"><strong>#".$this->query_count." - Select Query</strong></td>\n".

				"</tr>\n".
"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #fefefe;\"><span style=\"font-family: Courier; font-size: 14px;\">".$string."</span></td>\n".
"</tr>\n".

				"</tr>\n".
"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #fefefe;\"><span style=\"font-family: Courier; font-size: 14px;\">".$string."</span></td>\n".
"</tr>\n".

				"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #fff;\">Query Time: ".$qtime."</td>\n".
"</tr>\n".

				"<tr>\n".
"<td colspan=\"8\" style=\"background-color: #fff;\">Query Time: ".$qtime."</td>\n".
"</tr>\n".

Zeile 287Zeile 295
		if($row !== false)
{
$this->data_seek($query, $row);

		if($row !== false)
{
$this->data_seek($query, $row);

		}

		}

		$array = $this->fetch_array($query);
return $array[$field];
}

		$array = $this->fetch_array($query);
return $array[$field];
}

Zeile 500Zeile 508
		if($exists > 0)
{
return true;

		if($exists > 0)
{
return true;

		}

		}

		else
{
return false;

		else
{
return false;

Zeile 533Zeile 541
	 * @param string Comma delimetered list of fields to be selected.
* @param string SQL formatted list of conditions to be matched.
* @param array List of options, order by, order direction, limit, limit start

	 * @param string Comma delimetered list of fields to be selected.
* @param string SQL formatted list of conditions to be matched.
* @param array List of options, order by, order direction, limit, limit start

	 */

	 */

	
function simple_select($table, $fields="*", $conditions="", $options=array())
{

	
function simple_select($table, $fields="*", $conditions="", $options=array())
{

Zeile 555Zeile 563
		}

if(isset($options['limit_start']) && isset($options['limit']))

		}

if(isset($options['limit_start']) && isset($options['limit']))

		{

		{

			$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];

			$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];

		}

		}

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

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

Zeile 566Zeile 574
		return $this->query($query);
}


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






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

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

Zeile 575Zeile 583
	 * @return int The insert ID if available
*/
function insert_query($table, $array)

	 * @return int The insert ID if available
*/
function insert_query($table, $array)

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

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

		$fields = implode(",", array_keys($array));
$values = implode("','", $array);
$this->write_query("

		$fields = implode(",", array_keys($array));
$values = implode("','", $array);
$this->write_query("

Zeile 588Zeile 596
			VALUES ('".$values."')
");
return $this->insert_id();

			VALUES ('".$values."')
");
return $this->insert_id();

 
	}

/**
* Build an insert query from an array.
*
* @param string The table name to perform the query on.
* @param array An array of fields and their values.
* @return string The query string.
*/
function build_insert_query($table, $array)
{
$comma = $query1 = $query2 = "";
if(!is_array($array))
{
return false;
}
$comma = "";
$query1 = "";
$query2 = "";
foreach($array as $field => $value)
{
$query1 .= $comma.$field;
$query2 .= $comma."'".$value."'";
$comma = ", ";
}
return "INSERT
INTO ".TABLE_PREFIX.$table." (".$query1.")
VALUES (".$query2.")";

	}

/**

	}

/**

Zeile 653Zeile 689
		
return $this->query("UPDATE {$this->table_prefix}$table SET $query");
}

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




































	
/**
* Build an update query from an array.
*
* @param string The table name to perform the query on.
* @param array An array of fields and their values.
* @param string An optional where clause for the query.
* @param string An optional limit clause for the query.
* @return string The query string.
*/
function build_update_query($table, $array, $where="", $limit="")
{
if(!is_array($array))
{
return false;
}

$comma = "";
$query = "";

foreach($array as $field => $value)
{
$query .= $comma.$field."='".$value."'";
$comma = ", ";
}

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

return "UPDATE {$this->table_prefix}{$table} SET {$query}";
}


	/**
* Build a delete query.
*

	/**
* Build a delete query.
*

Zeile 767Zeile 836
	{
$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 = '{$this->table_prefix}{$table}'");

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

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



		

		preg_match('#\((.*)\)#s', $table, $matches);

$field_info = array();

		preg_match('#\((.*)\)#s', $table, $matches);

$field_info = array();

Zeile 794Zeile 863
	 * @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;

	}

/**
* Returns whether or not this database engine supports fulltext indexing.

	}

/**
* Returns whether or not this database engine supports fulltext indexing.

	 *
* @param string The table to be checked.

	 *
* @param string The table to be checked.

	 * @return boolean True or false if supported or not.
*/

function supports_fulltext($table)

	 * @return boolean True or false if supported or not.
*/

function supports_fulltext($table)

	{
return false;
}

	{
return false;
}


/**
* Returns whether or not this database engine supports boolean fulltext matching.


/**
* Returns whether or not this database engine supports boolean fulltext matching.

Zeile 821Zeile 890
		return false;
}


		return false;
}


	/**

	/**

	 * Creates a fulltext index on the specified column in the specified table with optional index name.

	 * Creates a fulltext index on the specified column in the specified table with optional index name.

	 *
* @param string The name of the table.

	 *
* @param string The name of the table.

	 * @param string Name of the column to be indexed.
* @param string The index name, optional.
*/
function create_fulltext_index($table, $column, $name="")
{
return false;

	 * @param string Name of the column to be indexed.
* @param string The index name, optional.
*/
function create_fulltext_index($table, $column, $name="")
{
return false;

	}













	}

/**
* Checks to see if an index exists on a specified table
*
* @param string The name of the table.
* @param string The name of the index.
*/
function index_exists($table, $index)
{
return false;
}


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

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

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

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

	{

	{

		$this->query("ALTER TABLE {$this->table_prefix}$table DROP INDEX $name");
}


		$this->query("ALTER TABLE {$this->table_prefix}$table DROP INDEX $name");
}


Zeile 850Zeile 930
	 * @param string The name of the table.
* @param boolean hard drop - no checking
* @param boolean use table prefix

	 * @param string The name of the table.
* @param boolean hard drop - no checking
* @param boolean use table prefix

	 */

	 */

	function drop_table($table, $hard=false, $table_prefix=true)
{
if($table_prefix == false)

	function drop_table($table, $hard=false, $table_prefix=true)
{
if($table_prefix == false)

Zeile 867Zeile 947
			if($this->table_exists($table))
{
$this->query('DROP TABLE '.$table_prefix.$table);

			if($this->table_exists($table))
{
$this->query('DROP TABLE '.$table_prefix.$table);

			}
}
else
{

			}
}
else
{

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

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

Zeile 879Zeile 959
	 * Replace contents of table with values
*
* @param string The table

	 * Replace contents of table with values
*
* @param string The table

	 * @param array The values
























































	 * @param array The values
* @param string The default field
* @param boolean Whether or not to return an insert id. True by default
*/
function replace_query($table, $replacements=array(), $default_field="", $insert_id=true)
{
$columns = '';
$values = '';
$comma = '';
foreach($replacements as $column => $value)
{
$columns .= $comma.$column;
$values .= $comma."'".$value."'";

$comma = ',';
}

if(empty($columns) || empty($values))
{
return false;
}

if($default_field == "")
{
return $this->write_query("REPLACE INTO {$this->table_prefix}{$table} ({$columns}) VALUES({$values})");
}
else
{
$update = false;
$query = $this->write_query("SELECT {$default_field} FROM {$this->table_prefix}{$table}");

while($column = $this->fetch_array($query))
{
if($column[$default_field] == $replacements[$default_field])
{
$update = true;
break;
}
}

if($update === true)
{
return $this->update_query($table, $replacements, "{$default_field}='".$replacements[$default_field]."'");
}
else
{
return $this->insert_query($table, $replacements, $insert_id);
}
}
}

/**
* Replace contents of table with values
*
* @param string The table
* @param array The replacements

	 */

	 */

	function replace_query($table, $replacements=array())

	function build_replace_query($table, $replacements=array(), $default_field="")

	{
$columns = '';
$values = '';

	{
$columns = '';
$values = '';

Zeile 899Zeile 1034
			 return false;
}


			 return false;
}


		return $this->query("REPLACE INTO {$this->table_prefix}{$table} ({$columns}) VALUES({$values})");



























		if($default_field == "")
{
return "REPLACE INTO {$this->table_prefix}{$table} ({$columns}) VALUES({$values})";
}
else
{
$update = false;
$query = $this->write_query("SELECT {$default_field} FROM {$this->table_prefix}{$table}");

while($column = $this->fetch_array($query))
{
if($column[$default_field] == $replacements[$default_field])
{
$update = true;
break;
}
}

if($update === true)
{
return $this->build_update_query($table, $replacements, "{$default_field}='".$replacements[$default_field]."'");
}
else
{
return $this->build_insert_query($table, $replacements, $insert_id);
}
}

	}

/**

	}

/**

Zeile 934Zeile 1095
	 * Perform an "Alter Table" query in SQLite < 3.2.0 - Code taken from http://code.jenseng.com/db/
*
* @param string The table (optional)

	 * Perform an "Alter Table" query in SQLite < 3.2.0 - Code taken from http://code.jenseng.com/db/
*
* @param string The table (optional)

 
	 * @param string The ADD/Change/Drop part of the query
* @param string The full part of the query

	 * @return integer the total size of all mysql tables or a specific table
*/

	 * @return integer the total size of all mysql tables or a specific table
*/

	function alter_table_parse($table, $alterdefs)

	function alter_table_parse($table, $alterdefs, $fullquery="")

	{

	{

 
		if(!$fullquery)
{
$fullquery = " ... {$alterdefs}";
}

if(!defined("TIME_NOW"))
{
define("TIME_NOW", time());
}


		if($alterdefs != '')
{
$result = $this->query("SELECT sql,name,type FROM sqlite_master WHERE tbl_name = '{$table}' ORDER BY type DESC");

		if($alterdefs != '')
{
$result = $this->query("SELECT sql,name,type FROM sqlite_master WHERE tbl_name = '{$table}' ORDER BY type DESC");

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

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

								return false;
}


								return false;
}


							$createtesttableSQL = substr($createtesttableSQL, 0, strlen($createtesttableSQL)-1).',';

							$createtesttableSQL = substr($createtesttableSQL, 0, strlen($createtesttableSQL)-1).',';

 
							
if(strstr($createtesttableSQL, $defparts[1]) !== false)
{
$this->error($fullquery, 'syntax error: '.$defparts[1].' column already exists in '.$table.' table');
}

							
for($i = 1; $i < sizeof($defparts); $i++)
{

							
for($i = 1; $i < sizeof($defparts); $i++)
{

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

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

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

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

									return false;
}


									return false;
}


Zeile 1032Zeile 1210
							}
else
{

							}
else
{

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

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

								return false;
}
break;
case 'drop':
if(sizeof($defparts) < 2)
{

								return false;
}
break;
case 'drop':
if(sizeof($defparts) < 2)
{

								$this->error($alterdefs, 'near "'.$defparts[0].($defparts[1] ? ' '.$defparts[1] : '').'": syntax error');

								$this->error($fullquery, 'near "'.$defparts[0].($defparts[1] ? ' '.$defparts[1] : '').'": syntax error');

								return false;
}


								return false;
}


Zeile 1060Zeile 1238
							}
else
{

							}
else
{

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

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

								return false;
}
break;
default:

								return false;
}
break;
default:

							$this->error($alterdefs, 'near "'.$prevword.'": syntax error');

							$this->error($fullquery, 'near "'.$prevword.'": syntax error');

							return false;
}


							return false;
}