-- @create_greeting
CREATE TABLE IF NOT EXISTS greeting (jid varchar, room varchar, msg varchar);
-- @create_gr_index
CREATE UNIQUE INDEX IF NOT EXISTS gr_index ON greeting (jid, room);

-- @create_users
CREATE TABLE IF NOT EXISTS users (jid varchar, room varchar, nick varchar, last integer, action varchar, reason varchar);
-- @create_users_index
CREATE INDEX IF NOT EXISTS users_index on users (jid, room);

-- @get_greeting
SELECT msg FROM greeting WHERE jid=@jid AND room=@room;
-- @add_greeting
INSERT OR REPLACE INTO greeting (jid, room, msg) VALUES;

-- @get_last_by_nick
SELECT last FROM users where nick=@nick AND room=@room;
-- @get_last_by_jid
SELECT last FROM users where jid=@jid AND room=@room;

-- @update_user_by_nick
UPDATE users SET last=@last, action=@action, reason=@reason WHERE nick=@nick AND room=@room;
-- @update_user_by_jid
UPDATE users SET last=@last, action=@action, reason=@reason WHERE jid=@jid AND room=@room;

-- @add_user
INSERT INTO users VALUES;

-- @find_user
SELECT jid, last, action, reason FROM users WHERE nick=@nick AND room=@room ORDER BY last DESC LIMIT 1;

