sqlite updates

This commit is contained in:
Shish 2012-06-26 23:46:38 +01:00
parent 3a8269baf3
commit 02a286cba0

View File

@ -61,7 +61,7 @@ class MySQL extends DBEngine {
var $name = "mysql"; var $name = "mysql";
public function init($db) { public function init($db) {
$db->query("SET NAMES utf8;"); $db->exec("SET NAMES utf8;");
} }
public function scoreql_to_sql($data) { public function scoreql_to_sql($data) {
@ -87,7 +87,7 @@ class PostgreSQL extends DBEngine {
var $name = "pgsql"; var $name = "pgsql";
public function init($db) { public function init($db) {
$db->query("SET application_name TO 'shimmie [{$_SERVER['REMOTE_ADDR']}]';"); $db->exec("SET application_name TO 'shimmie [{$_SERVER['REMOTE_ADDR']}]';");
} }
public function scoreql_to_sql($data) { public function scoreql_to_sql($data) {
@ -127,15 +127,15 @@ class SQLite extends DBEngine {
public function init($db) { public function init($db) {
ini_set('sqlite.assoc_case', 0); ini_set('sqlite.assoc_case', 0);
$db->execute("PRAGMA foreign_keys = ON;"); $db->exec("PRAGMA foreign_keys = ON;");
@sqlite_create_function($db->_connectionID, 'UNIX_TIMESTAMP', '_unix_timestamp', 1); $db->sqliteCreateFunction('UNIX_TIMESTAMP', '_unix_timestamp', 1);
@sqlite_create_function($db->_connectionID, 'now', '_now', 0); $db->sqliteCreateFunction('now', '_now', 0);
@sqlite_create_function($db->_connectionID, 'floor', '_floor', 1); $db->sqliteCreateFunction('floor', '_floor', 1);
@sqlite_create_function($db->_connectionID, 'log', '_log'); $db->sqliteCreateFunction('log', '_log');
@sqlite_create_function($db->_connectionID, 'isnull', '_isnull', 1); $db->sqliteCreateFunction('isnull', '_isnull', 1);
@sqlite_create_function($db->_connectionID, 'md5', '_md5', 1); $db->sqliteCreateFunction('md5', '_md5', 1);
@sqlite_create_function($db->_connectionID, 'concat', '_concat', 2); $db->sqliteCreateFunction('concat', '_concat', 2);
@sqlite_create_function($db->_connectionID, 'lower', '_lower', 1); $db->sqliteCreateFunction('lower', '_lower', 1);
} }
public function create_table_sql($name, $data) { public function create_table_sql($name, $data) {
@ -153,14 +153,14 @@ class SQLite extends DBEngine {
$matches = array(); $matches = array();
if(preg_match("/INDEX\s*\((.*)\)/", $bit, $matches)) { if(preg_match("/INDEX\s*\((.*)\)/", $bit, $matches)) {
$col = $matches[1]; $col = $matches[1];
$extras .= 'CREATE INDEX '.$name.'_'.$col.' on '.$name($col).';'; $extras .= "CREATE INDEX {$name}_{$col} on {$name}({$col});";
} }
else { else {
$cols[] = $bit; $cols[] = $bit;
} }
} }
$cols_redone = implode(", ", $cols); $cols_redone = implode(", ", $cols);
return 'CREATE TABLE '.$name.' ('.$cols_redone.'); '.$extras; return "CREATE TABLE $name ($cols_redone); $extras";
} }
} }
// }}} // }}}
@ -454,6 +454,7 @@ class Database {
* Create a table from pseudo-SQL * Create a table from pseudo-SQL
*/ */
public function create_table($name, $data) { public function create_table($name, $data) {
if(is_null($this->engine)) $this->connect_engine();
$this->execute($this->engine->create_table_sql($name, $data)); $this->execute($this->engine->create_table_sql($name, $data));
} }