Vergleich inc/db_sqlite2.php - 1.4.0 - 1.4.15

  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 5379 2011-02-21 11:06:42Z Tomm $

 */


 */


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 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'];
}

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.

	 *
* @param string The table name to perform the query on.
* @param array An array of fields and their values.

	 *
* @param string The table name to perform the query on.
* @param array An array of fields and their values.

Zeile 582Zeile 590
		}
$fields = implode(",", array_keys($array));
$values = implode("','", $array);

		}
$fields = implode(",", array_keys($array));
$values = implode("','", $array);

		$this->write_query("
INSERT

		$this->write_query("
INSERT

			INTO {$this->table_prefix}{$table} (".$fields.") 
VALUES ('".$values."')
");
return $this->insert_id();

			INTO {$this->table_prefix}{$table} (".$fields.") 
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 598Zeile 634
	 * @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;
}

		{
return false;
}

Zeile 630Zeile 666
	 * @param string An optional limit clause for the query.
* @return resource The query data.
*/

	 * @param string An optional limit clause for the query.
* @return resource The query data.
*/

	function update_query($table, $array, $where="", $limit="")


































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

	{
if(!is_array($array))

		{

		{

			return false;

			return false;

		}


		}


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


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


Zeile 644Zeile 713
		{
$query .= $comma.$field."='".$value."'";
$comma = ", ";

		{
$query .= $comma.$field."='".$value."'";
$comma = ", ";

		}


		}


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


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


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

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

	}

	}



	

	/**
* Build a delete query.
*

	/**
* Build a delete query.
*

Zeile 675Zeile 744

/**
* 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;
}

Zeile 690Zeile 759
	 *
*/
function free_result($query)

	 *
*/
function free_result($query)

	{
return;

	{
return;

	}

/**

	}

/**

Zeile 737Zeile 806
	 * @param string The name of the table to be analyzed.
*/
function analyze_table($table)

	 * @param string The name of the table to be analyzed.
*/
function analyze_table($table)

	{

	{

		return;
}


		return;
}


Zeile 752Zeile 821
		$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}' 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 = '{$this->table_prefix}{$table}' ORDER BY type DESC, name");

		$this->set_table_prefix($old_tbl_prefix);


		$this->set_table_prefix($old_tbl_prefix);


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


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


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 784Zeile 853
		}

return $field_info;

		}

return $field_info;

	}


	}


	/**
* Returns whether or not the table contains a fulltext index.
*

	/**
* Returns whether or not the table contains a fulltext index.
*

Zeile 800Zeile 869

/**
* 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.
* @return boolean True or false if supported or not.
*/

	 * @param string The table to be checked.
* @return boolean True or false if supported or not.
*/

Zeile 832Zeile 901
	{
return false;
}

	{
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 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 926Zeile 1087
		if(!$total || $table != '')
{
$total = $lang->na;

		if(!$total || $table != '')
{
$total = $lang->na;

		}

		}

		return $total;
}


		return $total;
}


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 955Zeile 1128
				$newcols = array();

for($i = 0; $i < sizeof($oldcols); $i++)

				$newcols = array();

for($i = 0; $i < sizeof($oldcols); $i++)

				{

				{

					$colparts = preg_split("/[\s]+/", $oldcols[$i], -1, PREG_SPLIT_NO_EMPTY);
$oldcols[$i] = $colparts[0];
$newcols[$colparts[0]] = $colparts[0];

					$colparts = preg_split("/[\s]+/", $oldcols[$i], -1, PREG_SPLIT_NO_EMPTY);
$oldcols[$i] = $colparts[0];
$newcols[$colparts[0]] = $colparts[0];

Zeile 990Zeile 1163
							}

$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++)
{
$createtesttableSQL .= ' '.$defparts[$i];
}
$createtesttableSQL .= ')';

							
for($i = 1; $i < sizeof($defparts); $i++)
{
$createtesttableSQL .= ' '.$defparts[$i];
}
$createtesttableSQL .= ')';

							break;

							break;

						case 'change':
if(sizeof($defparts) <= 3)

						case 'change':
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;
}

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

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;

								}


								}


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

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

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


Zeile 1176Zeile 1354
	}
}


	}
}


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

 
?>

?>