diff options
Diffstat (limited to 'rhnop-client/db.lua')
-rw-r--r-- | rhnop-client/db.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/rhnop-client/db.lua b/rhnop-client/db.lua index 5a6a92c..17e91f1 100644 --- a/rhnop-client/db.lua +++ b/rhnop-client/db.lua @@ -28,6 +28,8 @@ require "luasql.mysql" -- USE nop -- CREATE TABLE IF NOT EXISTS master (timestamp BIGINT UNSIGNED PRIMARY KEY NOT NULL, cart INT NOT NULL, len INT, showtitle VARCHAR(255), title VARCHAR(255), artist VARCHAR(255), album VARCHAR(255), ismusic BOOLEAN); -- CREATE TABLE IF NOT EXISTS standby (timestamp BIGINT UNSIGNED PRIMARY KEY NOT NULL, cart INT NOT NULL, len INT, showtitle VARCHAR(255), title VARCHAR(255), artist VARCHAR(255), album VARCHAR(255), ismusic BOOLEAN); +-- CREATE TABLE IF NOT EXISTS state (timestamp BIGINT UNSIGNED PRIMARY KEY NOT NULL, state VARCHAR(32)); +-- GRANT select,insert,update ON nop.state TO 'nopsysstated' IDENTIFIED BY '<password>'; local db = {} @@ -111,6 +113,28 @@ function db.init(db, user, pwd, host, port, table) return true end + function mydb:getLastSysState() + local cur, err = self.con:execute("SELECT state FROM " .. self.table .. " WHERE timestamp = (SELECT MAX(timestamp) FROM " .. self.table .. ")") + if cur == nil then + return nil, err + end + + local state = cur:fetch() + if state == nil then state = "unknown" end + return state + end + + function mydb:updateSysState(timestamp, state) + local t = self.con:escape(timestamp) + local s = self.con:escape(state) + + local cur, err = self.con:execute("INSERT INTO " .. self.table .. " VALUES('" .. t .. "', '" .. s .. "')") + if cur == nil then + return nil, err + end + return true + end + function mydb:close() if self.con then self.con:close() |