Zeile 6 | Zeile 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 3902 2008-06-11 02:21:37Z Tikitiki $
| * $Id: db_sqlite3.php 5379 2011-02-21 11:06:42Z Tomm $
|
*/
class DB_SQLite3
| */
class DB_SQLite3
|
Zeile 180 | Zeile 180 |
---|
} else {
|
} else {
|
$query = $this->alter_table_parse($tablename, $alterdefs);
| $query = $this->alter_table_parse($tablename, $alterdefs, $string);
|
} } }
| } } }
|
Zeile 616 | Zeile 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 626 | Zeile 654 |
---|
* @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 656 | Zeile 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)) { return false;
|
{ if(!is_array($array)) { return false;
|
}
| }
|
$comma = ""; $query = "";
| $comma = ""; $query = "";
|
Zeile 672 | Zeile 733 |
---|
{ $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}";
|
}
/**
| }
/**
|
Zeile 689 | Zeile 750 |
---|
* @param string An optional where clause for the query. * @param string An optional limit clause for the query. * @return resource The query data.
|
* @param string An optional where clause for the query. * @param string An optional limit clause for the query. * @return resource The query data.
|
*/
| */
|
function delete_query($table, $where="", $limit="") { $query = ""; if(!empty($where)) { $query .= " WHERE $where";
|
function delete_query($table, $where="", $limit="") { $query = ""; if(!empty($where)) { $query .= " WHERE $where";
|
}
| }
|
return $this->query("DELETE FROM {$this->table_prefix}$table $query"); }
/** * Escape a string
|
return $this->query("DELETE FROM {$this->table_prefix}$table $query"); }
/** * Escape a string
|
* * @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) {
|
Zeile 720 | Zeile 781 |
---|
function free_result($query) { return;
|
function free_result($query) { return;
|
} /**
| } /**
|
* Escape a string used within a like command. * * @param string The string to be escaped.
| * Escape a string used within a like command. * * @param string The string to be escaped.
|
Zeile 731 | Zeile 792 |
---|
function escape_string_like($string) { return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string));
|
function escape_string_like($string) { return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string));
|
}
| }
|
/** * Gets the current version of SQLLite.
| /** * Gets the current version of SQLLite.
|
Zeile 739 | Zeile 800 |
---|
* @return string Version of MySQL. */ function get_version()
|
* @return string Version of MySQL. */ function get_version()
|
{
| {
|
if($this->version) { return $this->version;
| if($this->version) { return $this->version;
|
Zeile 757 | Zeile 818 |
---|
function optimize_table($table) { $this->query("VACUUM ".$this->table_prefix.$table."");
|
function optimize_table($table) { $this->query("VACUUM ".$this->table_prefix.$table."");
|
} /**
| } /**
|
* Analyzes a specific table. * * @param string The name of the table to be analyzed. */ function analyze_table($table)
|
* Analyzes a specific table. * * @param string The name of the table to be analyzed. */ function analyze_table($table)
|
{
| {
|
$this->query("ANALYZE ".$this->table_prefix.$table.""); }
| $this->query("ANALYZE ".$this->table_prefix.$table.""); }
|
Zeile 774 | Zeile 835 |
---|
* * @param string The name of the table. * @return string The MySQL command to create the specified table.
|
* * @param string The name of the table. * @return string The MySQL command to create the specified table.
|
*/
| */
|
function show_create_table($table) { $old_tbl_prefix = $this->table_prefix;
| function show_create_table($table) { $old_tbl_prefix = $this->table_prefix;
|
Zeile 783 | Zeile 844 |
---|
$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 795 | Zeile 856 |
---|
{ $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")));
|
Zeile 828 | Zeile 889 |
---|
/** * 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. */
|
function supports_fulltext($table) {
| function supports_fulltext($table) {
|
Zeile 840 | Zeile 901 |
---|
/** * Returns whether or not this database engine supports boolean fulltext matching.
|
/** * Returns whether or not this database engine supports boolean fulltext matching.
|
*
| *
|
* @param string The table to be checked. * @return boolean True or false if supported or not. */ function supports_fulltext_boolean($table)
|
* @param string The table to be checked. * @return boolean True or false if supported or not. */ 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. * * @param string The name of the table.
| * Creates a fulltext index on the specified column in the specified table with optional index name. * * @param string The name of the table.
|
Zeile 857 | Zeile 918 |
---|
* @param string The index name, optional. */ function create_fulltext_index($table, $column, $name="")
|
* @param string The index name, optional. */ function create_fulltext_index($table, $column, $name="")
|
{ return false;
| { return false;
|
}
/** * Drop an index with the specified name from the specified table
|
}
/** * 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. */
| * * @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");
|
$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) { return false;
|
} /**
| } /**
|
Zeile 884 | Zeile 956 |
---|
if($table_prefix == false) { $table_prefix = "";
|
if($table_prefix == false) { $table_prefix = "";
|
}
| }
|
else { $table_prefix = $this->table_prefix;
| else { $table_prefix = $this->table_prefix;
|
Zeile 900 | Zeile 972 |
---|
else { $this->query('DROP TABLE '.$table_prefix.$table);
|
else { $this->query('DROP TABLE '.$table_prefix.$table);
|
} }
| } } /** * Replace contents of table with 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(), $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
|
/** * Replace contents of table with values * * @param string The table
|
* @param array The values */ function replace_query($table, $replacements=array()) {
| * @param array The replacements */ function build_replace_query($table, $replacements=array(), $default_field="") {
|
$columns = ''; $values = ''; $comma = '';
| $columns = ''; $values = ''; $comma = '';
|
Zeile 918 | Zeile 1045 |
---|
{ $columns .= $comma.$column; $values .= $comma."'".$value."'";
|
{ $columns .= $comma.$column; $values .= $comma."'".$value."'";
|
|
|
$comma = ','; } if(empty($columns) || empty($values)) { return false;
|
$comma = ','; } 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 * * @param string The new table prefix
|
} /** * Sets the table prefix used by the simple select, insert, update and delete functions * * @param string The new table prefix
|
*/
| */
|
function set_table_prefix($prefix) { $this->table_prefix = $prefix;
| function set_table_prefix($prefix) { $this->table_prefix = $prefix;
|
Zeile 942 | Zeile 1095 |
---|
/** * Fetched the total size of all mysql tables or a specific table
|
/** * Fetched the total size of all mysql tables or a specific table
|
*
| *
|
* @param string The table (optional) (ignored) * @return integer the total size of all mysql tables or a specific table */ function fetch_size($table='') { global $config, $lang;
|
* @param string The table (optional) (ignored) * @return integer the total size of all mysql tables or a specific table */ function fetch_size($table='') { global $config, $lang;
|
|
|
$total = @filesize($config['database']['database']); if(!$total || $table != '') {
| $total = @filesize($config['database']['database']); if(!$total || $table != '') {
|
Zeile 964 | Zeile 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 1041 | Zeile 1204 |
---|
else { $createtesttableSQL = substr($createtesttableSQL, 0, $severpos-(strpos($createtesttableSQL, ',') ? 0 : 1)).$insertval.')';
|
else { $createtesttableSQL = substr($createtesttableSQL, 0, $severpos-(strpos($createtesttableSQL, ',') ? 0 : 1)).$insertval.')';
|
} } else { $this->error($alterdefs, 'unknown column "'.$defparts[1].'" in "'.$table.'"', E_USER_WARNING); return false;
| } } else { $this->error($fullquery, 'unknown column "'.$defparts[1].'" in "'.$table.'"', E_USER_WARNING); return false;
|
} break; case 'drop': if(sizeof($defparts) < 2) {
|
} 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 1073 | Zeile 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 1122 | Zeile 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;
|
Zeile 1189 | Zeile 1352 |
---|
} }
|
} }
|
if(!class_exists('databaseEngine')) { class databaseEngine extends DB_SQLite3 { } }
| |
?>
| ?>
|