diff --git a/core/image.class.php b/core/image.class.php index dcc4351f..fea1df60 100644 --- a/core/image.class.php +++ b/core/image.class.php @@ -16,6 +16,7 @@ class Image { public function Image($row=null) { if(!is_null($row)) { foreach($row as $name => $value) { + // FIXME: some databases use table.name rather than name $this->$name = $value; // hax } } @@ -30,7 +31,7 @@ class Image { if(!isset($this->tag_array)) { global $database; $this->tag_array = Array(); - $row = $database->Execute("SELECT * FROM image_tags JOIN tags ON image_tags.tag_id = tags.id WHERE image_id=? ORDER BY tag", array($this->id)); + $row = $database->Execute("SELECT tag FROM image_tags JOIN tags ON image_tags.tag_id = tags.id WHERE image_id=? ORDER BY tag", array($this->id)); while(!$row->EOF) { $this->tag_array[] = $row->fields['tag']; $row->MoveNext(); diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 6fe9d8ed..b348aa7d 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -167,7 +167,7 @@ class TagList extends Extension { global $config; $query = " - SELECT COUNT(it3.image_id) as count, t3.tag + SELECT COUNT(it3.image_id) as count, t3.tag AS tag FROM image_tags AS it1, image_tags AS it2, @@ -183,7 +183,7 @@ class TagList extends Extension { AND t1.id = it1.tag_id AND t3.id = it3.tag_id GROUP BY it3.tag_id - ORDER BY count DESC + ORDER BY count(it3.image_id) DESC LIMIT ? "; $args = array($image->id, $config->get_int('tag_list_length')); @@ -230,7 +230,7 @@ class TagList extends Extension { if($tags_ok) { $query = " - SELECT t2.tag, COUNT(it2.image_id) AS count + SELECT t2.tag AS tag, COUNT(it2.image_id) AS count FROM image_tags AS it1, image_tags AS it2, @@ -242,7 +242,7 @@ class TagList extends Extension { AND it1.tag_id = t1.id AND it2.tag_id = t2.id GROUP BY t2.tag - ORDER BY count + ORDER BY count(it2.image_id) DESC LIMIT ? "; $args = array($config->get_int('tag_list_length')); diff --git a/index.php b/index.php index 3ec226c1..420de3ca 100644 --- a/index.php +++ b/index.php @@ -62,4 +62,8 @@ $user = _get_user(); send_event(new InitExtEvent()); send_event(_get_page_request($page, $user)); $page->display(); + + +// for databases which support transactions +$database->db->CommitTrans(true); ?> diff --git a/install.php b/install.php index 780ba075..e04fbbca 100644 --- a/install.php +++ b/install.php @@ -492,145 +492,92 @@ function move_data($old_dsn, $new_dsn, $old_data) { * Note: try and keep this as ANSI SQL compliant as possible, * so that we can (in theory) support other databases */ -function create_tables_mysql($db) { - $db->StartTrans(); - - $db->Execute("SET NAMES utf8"); // FIXME: mysql-specific :( - +function create_tables_common($db, $auto_incrementing_id, $boolean, $true, $false, $ip) { $db->Execute("CREATE TABLE aliases ( - oldtag varchar(255) NOT NULL, - newtag varchar(255) NOT NULL, - PRIMARY KEY (oldtag) + oldtag VARCHAR(255) NOT NULL PRIMARY KEY, + newtag VARCHAR(255) NOT NULL )"); $db->Execute("CREATE TABLE config ( - name varchar(255) NOT NULL, - value text, - PRIMARY KEY (name) + name VARCHAR(255) NOT NULL PRIMARY KEY, + value TEXT )"); $db->Execute("CREATE TABLE images ( - id int(11) NOT NULL auto_increment, - owner_id int(11) NOT NULL default '0', - owner_ip char(16) default NULL, - filename varchar(64) NOT NULL default '', - filesize int(11) NOT NULL default '0', - hash char(32) NOT NULL default '', - ext char(4) NOT NULL default '', - source varchar(255), - width int(11) NOT NULL, - height int(11) NOT NULL, - posted datetime NOT NULL, - PRIMARY KEY (id), - UNIQUE (hash) - )"); - - $db->Execute("CREATE TABLE tags ( - id int not null auto_increment primary key, - tag varchar(64) not null unique, - count int not null default 0, - KEY tags_count(count) - )"); - - $db->Execute("CREATE TABLE image_tags ( - image_id int NOT NULL default 0, - tag_id int NOT NULL default 0, - UNIQUE KEY image_id_tag_id (image_id,tag_id), - KEY tags_tag_id (tag_id), - KEY tags_image_id (image_id) + id $auto_incrementing_id, + owner_id INTEGER NOT NULL, + owner_ip $ip, + filename VARCHAR(64) NOT NULL DEFAULT '', + filesize INTEGER NOT NULL, + hash CHAR(32) NOT NULL UNIQUE, + ext CHAR(4) NOT NULL, + source VARCHAR(255), + width INTEGER NOT NULL, + height INTEGER NOT NULL, + posted TIMESTAMP NOT NULL )"); $db->Execute("CREATE TABLE users ( - id int(11) NOT NULL auto_increment, - name varchar(32) NOT NULL, - pass char(32) default NULL, - joindate datetime NOT NULL, - enabled enum('N','Y') NOT NULL default 'Y', - admin enum('N','Y') NOT NULL default 'N', - email varchar(255) default NULL, - PRIMARY KEY (id), - UNIQUE (name) + id $auto_incrementing_id, + name VARCHAR(32) NOT NULL UNIQUE, + pass CHAR(32), + joindate DATETIME NOT NULL, + enabled $boolean NOT NULL DEFAULT $true, + admin $boolean NOT NULL DEFAULT $false, + email VARCHAR(255) )"); $db->Execute("CREATE TABLE layout ( - title varchar(64) primary key not null, - section varchar(32) not null default \"left\", - position int not null default 50, - visible enum('Y', 'N') default 'Y' not null - )"); - - $db->Execute("INSERT INTO config(name, value) VALUES(?, ?)", Array('db_version', 5)); - - return $db->CommitTrans(); -} -function create_tables_pgsql($db) { - $db->StartTrans(); - - $db->Execute("CREATE TABLE aliases ( - oldtag varchar(255) NOT NULL, - newtag varchar(255) NOT NULL, - PRIMARY KEY (oldtag) - )"); - - $db->Execute("CREATE TABLE config ( - name varchar(255) NOT NULL, - value text, - PRIMARY KEY (name) - )"); - - $db->Execute("CREATE TABLE images ( - id SERIAL NOT NULL, - owner_id integer NOT NULL default '0', - owner_ip char(16) default NULL, - filename varchar(64) NOT NULL default '', - filesize integer NOT NULL default '0', - hash char(32) NOT NULL default '', - ext char(4) NOT NULL default '', - source varchar(255), - width integer NOT NULL, - height integer NOT NULL, - posted timestamp NOT NULL, - PRIMARY KEY (id), - UNIQUE (hash) + title VARCHAR(64) PRIMARY KEY NOT NULL, + section VARCHAR(32) NOT NULL DEFAULT 'left', + position INTEGER NOT NULL DEFAULT 50, + visible $boolean DEFAULT $true )"); $db->Execute("CREATE TABLE tags ( - id SERIAL NOT NULL, - tag varchar(64) not null unique, - count int not null default 0, - PRIMARY KEY(id) + id $auto_incrementing_id, + tag VARCHAR(64) NOT NULL UNIQUE, + count INTEGER NOT NULL DEFAULT 0 )"); $db->Execute("CREATE INDEX tags__count ON tags(count)"); $db->Execute("CREATE TABLE image_tags ( - image_id int NOT NULL default 0, - tag_id int NOT NULL default 0, - UNIQUE (image_id,tag_id) + image_id INTEGER NOT NULL DEFAULT 0, + tag_id INTEGER NOT NULL DEFAULT 0, + UNIQUE (image_id, tag_id) )"); $db->Execute("CREATE INDEX image_tags__tag_id ON image_tags(tag_id)"); $db->Execute("CREATE INDEX image_tags__image_id ON image_tags(image_id)"); - - $db->Execute("CREATE TABLE users ( - id SERIAL NOT NULL, - name varchar(32) NOT NULL, - pass char(32) default NULL, - joindate timestamp NOT NULL, - enabled char(1) NOT NULL default 'Y', - admin char(1) NOT NULL default 'N', - email varchar(255) default NULL, - PRIMARY KEY (id), - UNIQUE (name) - )"); - $db->Execute("CREATE TABLE layout ( - title varchar(64) primary key not null, - section varchar(32) not null default 'left', - position int not null default 50, - visible char(1) default 'Y' not null - )"); $db->Execute("INSERT INTO config(name, value) VALUES(?, ?)", Array('db_version', 5)); - +} +function create_tables_mysql($db) { + $db->StartTrans(); + $db->Execute("SET NAMES utf8"); + create_tables_common($db, + "INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY", + "ENUM('Y', 'N')", "'Y'", "'N'", + "CHAR(15)" + ); + return $db->CommitTrans(); +} +function create_tables_pgsql($db) { + $db->StartTrans(); + create_tables_common($db, + "SERIAL NOT NULL PRIMARY KEY", + "BOOLEAN", "True", "False", + "INET" + ); + return $db->CommitTrans(); +} +function create_tables_sqlite($db) { + $db->StartTrans(); + create_tables_common($db, + "INTEGER AUTOINCREMENT PRIMARY KEY NOT NULL", + "CHAR(1)", "'Y'", "'N'", + "CHAR(15)" + ); return $db->CommitTrans(); } // }}} diff --git a/lib/adodb/drivers/adodb-sqlite.inc.php b/lib/adodb/drivers/adodb-sqlite.inc.php index 665cc543..64fbf496 100644 --- a/lib/adodb/drivers/adodb-sqlite.inc.php +++ b/lib/adodb/drivers/adodb-sqlite.inc.php @@ -152,6 +152,15 @@ class ADODB_sqlite extends ADOConnection { { @sqlite_create_function($this->_connectionID, 'adodb_date', 'adodb_date', 1); @sqlite_create_function($this->_connectionID, 'adodb_date2', 'adodb_date2', 2); + + // XXX: shimmie customisation, as suggested by naikoto on the forums + @sqlite_create_function($this->_connectionID, 'UNIX_TIMESTAMP', 'UNIX_TIMESTAMP', 1); + @sqlite_create_function($this->_connectionID, 'now', 'now', 0); + @sqlite_create_function($this->_connectionID, 'floor', 'mfloor', 1); + @sqlite_create_function($this->_connectionID, 'log', 'mlog', 1); + @sqlite_create_function($this->_connectionID, 'isnull', 'fisnull', 1); + @sqlite_create_function($this->_connectionID, 'md5', 'fmd5', 1); + @sqlite_create_function($this->_connectionID, 'concat', 'fconcat', 2); } @@ -395,4 +404,14 @@ class ADORecordset_sqlite extends ADORecordSet { } } -?> \ No newline at end of file + +// shimmie functions +ini_set ( 'sqlite.assoc_case' , 0 ); +function UNIX_TIMESTAMP($date) { return strtotime($date); } +function now() { return date("Y-m-d h:i:s"); } +function mfloor($a) { return floor($a); } +function mlog($a) { return log($a); } +function fisnull($a) { return is_null($a); } +function fmd5($a) { return md5($a); } +function fconcat($a, $b) { return $a . $b; } +?>