Vergleich inc/db_sqlite2.php - 1.4.0 - 1.4.4

  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 3902 2008-06-11 02:21:37Z Tikitiki $

 * $Id: db_sqlite2.php 4279 2008-11-26 00:01:25Z 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)

Zeile 212Zeile 220
	 * @param string The query SQL.
* @param boolean 1 if hide errors, 0 if not.
* @return resource The query data.

	 * @param string The query SQL.
* @param boolean 1 if hide errors, 0 if not.
* @return resource The query data.

	 */

	 */

	function write_query($query, $hide_errors=0)

	function write_query($query, $hide_errors=0)

	{

	{

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


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


Zeile 227Zeile 235
	function explain_query($string, $qtime)
{
if(preg_match("#^\s*select#i", $string))

	function explain_query($string, $qtime)
{
if(preg_match("#^\s*select#i", $string))

		{

		{

			$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".

Zeile 259Zeile 267

$this->querylist[$this->query_count]['query'] = $string;
$this->querylist[$this->query_count]['time'] = $qtime;


$this->querylist[$this->query_count]['query'] = $string;
$this->querylist[$this->query_count]['time'] = $qtime;

	}


	}



/**
* Return a result array for a query.


/**
* Return a result array for a query.

Zeile 273Zeile 281
	{
$array = sqlite_fetch_array($query, SQLITE_ASSOC);
return $array;

	{
$array = sqlite_fetch_array($query, SQLITE_ASSOC);
return $array;

	}


	}


	/**
* Return a specific field from a query.
*

	/**
* Return a specific field from a query.
*

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

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

	}

/**

	}

/**

	 * Moves internal row pointer to the next row
*
* @param resource The query ID.

	 * Moves internal row pointer to the next row
*
* @param resource The query ID.

Zeile 305Zeile 313

/**
* Return the number of rows resulting from a query.


/**
* Return the number of rows resulting from a query.

	 *

	 *

	 * @param resource The query data.
* @return int The number of rows in the result.
*/

	 * @param resource The query data.
* @return int The number of rows in the result.
*/

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

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

			}
}


			}
}


		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.

	 *

	 *

	 * @param string The table name to perform the query on.
* @param array An array of fields and their values.
* @return int The insert ID if available

	 * @param string The table name to perform the query on.
* @param array An array of fields and their values.
* @return int The insert ID if available

Zeile 598Zeile 606
	 * @return int The insert ID if available
*/
function insert_query_multiple($table, $array)

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

	{
if(!is_array($array))
{

	{
if(!is_array($array))
{

			return false;
}
// Field names

			return false;
}
// Field names

Zeile 631Zeile 639
	 * @return resource The query data.
*/
function update_query($table, $array, $where="", $limit="")

	 * @return resource The query data.
*/
function update_query($table, $array, $where="", $limit="")

	{

	{

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

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

		}

		}

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

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

		

		

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

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

		}

if(!empty($where))

		}

if(!empty($where))

		{
$query .= " WHERE $where";
}

		{
$query .= " WHERE $where";
}

Zeile 675Zeile 683

/**
* Escape a string according to the MySQL escape format.


/**
* Escape a string according to the MySQL escape format.

	 *
* @param string The string to be escaped.
* @return string The escaped string.
*/

	 *
* @param string The string to be escaped.
* @return string The escaped string.
*/

	function escape_string($string)

	function escape_string($string)

	{

	{

		$string = sqlite_escape_string($string);
return $string;

		$string = sqlite_escape_string($string);
return $string;

	}


	}


	/**
* Serves no purposes except compatibility
*
*/
function free_result($query)

	/**
* Serves no purposes except compatibility
*
*/
function free_result($query)

	{
return;
}


	{
return;
}


	/**
* Escape a string used within a like command.
*

	/**
* Escape a string used within a like command.
*

Zeile 739Zeile 747
	function analyze_table($table)
{
return;

	function analyze_table($table)
{
return;

	}

	}


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


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

Zeile 755Zeile 763
		$this->set_table_prefix($old_tbl_prefix);

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

		$this->set_table_prefix($old_tbl_prefix);

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

	}

	}


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


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

Zeile 770Zeile 778
		$query = $this->simple_select("sqlite_master", "sql", "type = 'table' AND name = '{$this->table_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 = $this->simple_select("sqlite_master", "sql", "type = 'table' AND name = '{$this->table_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")));



		

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

$field_info = array();

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

$field_info = array();

Zeile 784Zeile 792
		}

return $field_info;

		}

return $field_info;

	}

/**

	}

/**

	 * Returns whether or not the table contains a fulltext index.
*
* @param string The name of the table.

	 * Returns whether or not the table contains a fulltext index.
*
* @param string The name of the table.

Zeile 800Zeile 808

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


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


Zeile 934Zeile 942
	 * 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 1006
							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 1033
							{
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 1057
							}
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 1085
							}
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;
}


Zeile 1176Zeile 1201
	}
}


	}
}


if(!class_exists('databaseEngine'))
{
class databaseEngine extends DB_SQLite {
}
}

 
?>

?>