diff options
Diffstat (limited to 'src/db.lua')
-rw-r--r-- | src/db.lua | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -69,17 +69,17 @@ function db.init(db, user, pwd, host, port, table) if cur == nil then return nil, err end - + local timestamp = cur:fetch() if timestamp == nil then timestamp = 0 end return timestamp end - + function mydb:findMissingEntries(lasttimestamp) local lastts = self.con:escape(lasttimestamp) return self.con:execute("SELECT * FROM " .. self.table .. " WHERE timestamp > " .. lastts) end - + function mydb:getNextMissingEntry(cur) local data = {} data = cur:fetch(data, "a") @@ -88,14 +88,14 @@ function db.init(db, user, pwd, host, port, table) end return data end - + function mydb:getEntry(timestamp) local ts = self.con:escape(timestamp) local cur, err = self.con:execute("SELECT * FROM " .. self.table .. " WHERE timestamp = " .. ts) if cur == nil then return nil, err end - + local data = {} data = cur:fetch(data, "a") if data == nil then @@ -103,7 +103,7 @@ function db.init(db, user, pwd, host, port, table) end return data end - + function mydb:addEntry(data) local timestamp = self.con:escape(data.timestamp) local cart = self.con:escape(data.cart) @@ -113,21 +113,21 @@ function db.init(db, user, pwd, host, port, table) local artist = self.con:escape(data.artist) local album = self.con:escape(data.album) local ismusic = self.con:escape(data.ismusic) - + local cur, err = self.con:execute("REPLACE INTO " .. self.table .. " VALUES('" .. timestamp .. "', '" .. cart .. "', '" .. len .. "', '" .. showtitle .. "', '" .. title .. "', '" .. artist .."', '" .. album .. "', '" .. ismusic .. "')") if cur == nil then return nil, err end - + 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 @@ -148,7 +148,7 @@ function db.init(db, user, pwd, host, port, table) if self.con then self.con:close() end - + if self.env then self.env:close() end |