more sqlite, and indexes

This commit is contained in:
Shish 2012-06-27 00:08:51 +01:00
parent 685c1248d9
commit 53ad7d4a2f
2 changed files with 14 additions and 7 deletions

View File

@ -138,7 +138,7 @@ class SQLite extends DBEngine {
$db->sqliteCreateFunction('lower', '_lower', 1); $db->sqliteCreateFunction('lower', '_lower', 1);
} }
public function create_table_sql($name, $data) { public function scoreql_to_sql($data) {
$data = str_replace("SCORE_AIPK", "INTEGER PRIMARY KEY", $data); $data = str_replace("SCORE_AIPK", "INTEGER PRIMARY KEY", $data);
$data = str_replace("SCORE_INET", "VARCHAR(45)", $data); $data = str_replace("SCORE_INET", "VARCHAR(45)", $data);
$data = str_replace("SCORE_BOOL_Y", "'Y'", $data); $data = str_replace("SCORE_BOOL_Y", "'Y'", $data);
@ -147,6 +147,10 @@ class SQLite extends DBEngine {
$data = str_replace("SCORE_NOW", "\"1970-01-01\"", $data); $data = str_replace("SCORE_NOW", "\"1970-01-01\"", $data);
$data = str_replace("SCORE_STRNORM", "", $data); $data = str_replace("SCORE_STRNORM", "", $data);
$data = str_replace("SCORE_ILIKE", "LIKE", $data); $data = str_replace("SCORE_ILIKE", "LIKE", $data);
}
public function create_table_sql($name, $data) {
$data = $this->scoreql_to_sql($data);
$cols = array(); $cols = array();
$extras = ""; $extras = "";
foreach(explode(",", $data) as $bit) { foreach(explode(",", $data) as $bit) {

View File

@ -252,7 +252,8 @@ function create_tables() { // {{{
pass CHAR(32), pass CHAR(32),
joindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW, joindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,
class VARCHAR(32) NOT NULL DEFAULT 'user', class VARCHAR(32) NOT NULL DEFAULT 'user',
email VARCHAR(128) email VARCHAR(128),
INDEX(name)
"); ");
$db->create_table("images", " $db->create_table("images", "
id SCORE_AIPK, id SCORE_AIPK,
@ -270,12 +271,14 @@ function create_tables() { // {{{
INDEX(owner_id), INDEX(owner_id),
INDEX(width), INDEX(width),
INDEX(height), INDEX(height),
INDEX(hash),
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT
"); ");
$db->create_table("tags", " $db->create_table("tags", "
id SCORE_AIPK, id SCORE_AIPK,
tag VARCHAR(64) UNIQUE NOT NULL, tag VARCHAR(64) UNIQUE NOT NULL,
count INTEGER NOT NULL DEFAULT 0 count INTEGER NOT NULL DEFAULT 0,
INDEX(tag)
"); ");
$db->create_table("image_tags", " $db->create_table("image_tags", "
image_id INTEGER NOT NULL, image_id INTEGER NOT NULL,
@ -287,9 +290,9 @@ function create_tables() { // {{{
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
"); ");
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)"); $db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)");
$db->commit();
} }
catch (PDOException $e) catch(PDOException $e) {
{
// FIXME: Make the error message user friendly // FIXME: Make the error message user friendly
exit($e->getMessage()); exit($e->getMessage());
} }
@ -304,9 +307,9 @@ function insert_defaults() { // {{{
if(check_im_version() > 0) { if(check_im_version() > 0) {
$db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", Array("name" => 'thumb_engine', "value" => 'convert')); $db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", Array("name" => 'thumb_engine', "value" => 'convert'));
} }
$db->commit();
} }
catch (PDOException $e) catch(PDOException $e) {
{
// FIXME: Make the error message user friendly // FIXME: Make the error message user friendly
exit($e->getMessage()); exit($e->getMessage());
} }