--- mqtt/etc/mqtt_pub.sql 2011/11/28 16:59:28 1.1.2.7 +++ mqtt/etc/mqtt_pub.sql 2012/02/01 14:53:13 1.2.2.1 @@ -1,12 +1,19 @@ PRAGMA foreign_keys=ON; BEGIN TRANSACTION; CREATE TABLE IF NOT EXISTS Online ( -Username varchar(64) not null, +ConnID varchar(23) not null primary key, +Username varchar(12) not null, RemoteHost varchar(64) not null, -RemotePort smallint unsigned not null, +WillFlag tinyint not null, +WillTopic text, +WillMsg text, +WillQoS tinyint, +WillRetain tinyint, Stamp timestamp); CREATE TABLE IF NOT EXISTS Topics ( id integer not null primary key, +MsgID smallint unsigned not null, +QoS char not null, Retain char not null, Topic varchar(255) not null, Value text, @@ -14,20 +21,34 @@ PubUser varchar(64) not null, PubDate datetime not null, PubHost varchar(64) not null, Stamp timestamp); -CREATE INDEX IF NOT EXISTS RemoteHost on Online (RemoteHost); -CREATE INDEX IF NOT EXISTS Username on Online (Username); -CREATE UNIQUE INDEX IF NOT EXISTS User on Online (Username, RemoteHost); -CREATE INDEX IF NOT EXISTS PubDate on Topics (PubDate); -CREATE INDEX IF NOT EXISTS PubHost on Topics (PubHost); -CREATE INDEX IF NOT EXISTS PubUser on Topics (PubUser); -CREATE INDEX IF NOT EXISTS Topic on Topics (Topic); +CREATE TABLE IF NOT EXISTS Subscribes ( +id integer not null primary key, +MsgID smallint unsigned not null, +QoS char not null, +Topic varchar(255) not null, +PubUser varchar(64) not null, +PubDate datetime not null, +PubHost varchar(64) not null, +Stamp timestamp); +CREATE INDEX IF NOT EXISTS online_RemoteHost on Online (RemoteHost); +CREATE INDEX IF NOT EXISTS online_Username on Online (Username); +CREATE INDEX IF NOT EXISTS topics_PubDate on Topics (PubDate); +CREATE INDEX IF NOT EXISTS topics_PubHost on Topics (PubHost); +CREATE INDEX IF NOT EXISTS topics_PubUser on Topics (PubUser); +CREATE INDEX IF NOT EXISTS topics_MsgID on Topics (MsgID); +CREATE INDEX IF NOT EXISTS topics_Topic on Topics (Topic); +CREATE INDEX IF NOT EXISTS subscribes_PubDate on Subscribes (PubDate); +CREATE INDEX IF NOT EXISTS subscribes_PubHost on Subscribes (PubHost); +CREATE INDEX IF NOT EXISTS subscribes_PubUser on Subscribes (PubUser); +CREATE INDEX IF NOT EXISTS subscribes_MsgID on Subscribes (MsgID); +CREATE INDEX IF NOT EXISTS subscribes_Topic on Subscribes (Topic); CREATE TRIGGER IF NOT EXISTS Online_update_t AFTER UPDATE ON Online BEGIN - UPDATE Online SET Stamp = strftime('%s', 'now') WHERE Username = old.Username; + UPDATE Online SET Stamp = strftime('%s', 'now') WHERE ConnID = old.ConnID; END; CREATE TRIGGER IF NOT EXISTS Online_insert_t AFTER INSERT ON Online BEGIN - UPDATE Online SET Stamp = strftime('%s', 'now') WHERE Username = new.Username; + UPDATE Online SET Stamp = strftime('%s', 'now') WHERE ConnID = new.ConnID; END; CREATE TRIGGER IF NOT EXISTS Topics_update_t AFTER UPDATE ON Topics BEGIN @@ -36,5 +57,13 @@ END; CREATE TRIGGER IF NOT EXISTS Topics_insert_t AFTER INSERT ON Topics BEGIN UPDATE Topics SET Stamp = strftime('%s', 'now') WHERE id = new.id; +END; +CREATE TRIGGER IF NOT EXISTS Subscribes_update_t AFTER UPDATE ON Subscribes +BEGIN + UPDATE Subscribes SET Stamp = strftime('%s', 'now') WHERE id = old.id; +END; +CREATE TRIGGER IF NOT EXISTS Subscribes_insert_t AFTER INSERT ON Subscribes +BEGIN + UPDATE Subscribes SET Stamp = strftime('%s', 'now') WHERE id = new.id; END; COMMIT;