Vergleich inc/db_sqlite3.php - 1.4.1 - 1.4.11

  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_sqlite3.php 4067 2008-08-04 03:59:08Z Tikitiki $

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

 */

class DB_SQLite3

 */

class DB_SQLite3

Zeile 180Zeile 180
				}
else
{

				}
else
{

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

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

				}
}
}

				}
}
}

Zeile 616Zeile 616
			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 624Zeile 652
	 * @param string The table name to perform the query on.
* @param array An array of inserts.
* @return int The insert ID if available

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

	 */

	 */

	function insert_query_multiple($table, $array)

	function insert_query_multiple($table, $array)

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

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

		}
// Field names
$fields = array_keys($array[0]);

		}
// Field names
$fields = array_keys($array[0]);

Zeile 656Zeile 684
	 * @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.

	 * @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 resource The query data.


































	 * @return resource The query data.
*/
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 update_query($table, $array, $where="", $limit="")

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

	{
if(!is_array($array))

	{
if(!is_array($array))

		{

		{

			return false;
}

$comma = "";

			return false;
}

$comma = "";

		$query = "";

		$query = "";

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

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

/**

		}

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

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

/**

	 * Build a delete query.
*
* @param string The table name to perform the query on.

	 * Build a delete query.
*
* @param string The table name to perform the query on.

Zeile 703Zeile 764

/**
* Escape a string


/**
* Escape a string

	 *
* @param string The string to be escaped.

	 *
* @param string The string to be escaped.

	 * @return string The escaped string.
*/
function escape_string($string)

	 * @return string The escaped string.
*/
function escape_string($string)

Zeile 715Zeile 776
	
/**
* Serves no purposes except compatibility

	
/**
* Serves no purposes except compatibility

	 *

	 *

	 */
function free_result($query)
{

	 */
function free_result($query)
{

Zeile 747Zeile 808
		$this->version = $this->db->get_attribute("ATTR_SERVER_VERSION");

return $this->version;

		$this->version = $this->db->get_attribute("ATTR_SERVER_VERSION");

return $this->version;

	}

	}


/**
* Optimizes a specific table.
*
* @param string The name of the table to be optimized.


/**
* Optimizes a specific table.
*
* @param string The name of the table to be optimized.

	 */

	 */

	function optimize_table($table)
{
$this->query("VACUUM ".$this->table_prefix.$table."");

	function optimize_table($table)
{
$this->query("VACUUM ".$this->table_prefix.$table."");

Zeile 767Zeile 828
	function analyze_table($table)
{
$this->query("ANALYZE ".$this->table_prefix.$table."");

	function analyze_table($table)
{
$this->query("ANALYZE ".$this->table_prefix.$table."");

	}

/**

	}

/**

	 * Show the "create table" command for a specific table.
*
* @param string The name of the table.

	 * Show the "create table" command for a specific table.
*
* @param string The name of the table.

Zeile 790Zeile 851
	 *
* @param string The name of the table.
* @return string Field info for that table

	 *
* @param string The name of the table.
* @return string Field info for that table

	 */

	 */

	function show_fields_from($table)
{
$old_tbl_prefix = $this->table_prefix;
$this->set_table_prefix("");

	function show_fields_from($table)
{
$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")));


Zeile 812Zeile 873
		}

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 834Zeile 895
	 */

function supports_fulltext($table)

	 */

function supports_fulltext($table)

	{

	{

		return false;
}


		return false;
}


Zeile 843Zeile 904
	 *
* @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.

	 */

	 */

	function supports_fulltext_boolean($table)

	function supports_fulltext_boolean($table)

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

	 * @param string Name of the column to be indexed.
* @param string The index name, optional.
*/

Zeile 861Zeile 922
		return false;
}


		return false;
}


	/**

	/**

	 * Drop an index with the specified name from the specified table
*
* @param string The name of the table.
* @param string The name of the index.
*/

	 * Drop an index with the specified name from the specified table
*
* @param string The name of the table.
* @param string The name of the index.
*/

	function drop_index($table, $name)












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

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

	{

	{

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

		return false;

	}

/**

	}

/**

Zeile 908Zeile 980
	 *
* @param string The table
* @param array The values

	 *
* @param string The table
* @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())






















































	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 build_replace_query($table, $replacements=array(), $default_field="")

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

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

Zeile 925Zeile 1052
		if(empty($columns) || empty($values))
{
return false;

		if(empty($columns) || empty($values))
{
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);
}
}
}

	
/**
* Sets the table prefix used by the simple select, insert, update and delete functions

	
/**
* Sets the table prefix used by the simple select, insert, update and delete functions

Zeile 938Zeile 1091
	function set_table_prefix($prefix)
{
$this->table_prefix = $prefix;

	function set_table_prefix($prefix)
{
$this->table_prefix = $prefix;

	}

	}

	
/**
* Fetched the total size of all mysql tables or a specific table

	
/**
* Fetched the total size of all mysql tables or a specific table

Zeile 949Zeile 1102
	function fetch_size($table='')
{
global $config, $lang;

	function fetch_size($table='')
{
global $config, $lang;

		

		

		$total = @filesize($config['database']['database']);
if(!$total || $table != '')
{
$total = $lang->na;

		$total = @filesize($config['database']['database']);
if(!$total || $table != '')
{
$total = $lang->na;

		}

		}

		return $total;
}


		return $total;
}


Zeile 964Zeile 1117
	 * @param string The table (optional)
* @return integer the total size of all mysql tables or a specific table
*/

	 * @param string The table (optional)
* @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 1045Zeile 1208
							}
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 1073Zeile 1236
							}
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 1122Zeile 1285
			}
else
{

			}
else
{

				$this->error($alterdefs, 'no such table: '.$table);

				$this->error($fullquery, 'no such table: '.$table);

				return false;
}
return true;

				return false;
}
return true;