summaryrefslogtreecommitdiff
path: root/rhnop-client
diff options
context:
space:
mode:
Diffstat (limited to 'rhnop-client')
-rw-r--r--rhnop-client/db.lua30
1 files changed, 21 insertions, 9 deletions
diff --git a/rhnop-client/db.lua b/rhnop-client/db.lua
index 0d6f591..ce3b15f 100644
--- a/rhnop-client/db.lua
+++ b/rhnop-client/db.lua
@@ -27,8 +27,6 @@ require "luasql.mysql"
-- USE rhnop
-- CREATE TABLE IF NOT EXISTS now (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);
-conf = require "conf"
-
local db = {}
function db:init(db, user, pwd, host, port, table)
@@ -54,15 +52,29 @@ function db:init(db, user, pwd, host, port, table)
return true
end
-function db:getLastCart()
- local cur, err = self.con:execute("SELECT cart FROM now WHERE timestamp = (SELECT MAX(timestamp) FROM now)")
+function db:getLastEntry()
+ local cur, err = self.con:execute("SELECT MAX(timestamp) FROM " .. self.table)
if cur == nil then
return nil, err
end
- local cart = cur:fetch()
- if cart == nil then cart = 0 end
- return cart
+ local timestamp = cur:fetch()
+ if timestamp == nil then timestamp = 0 end
+ return timestamp
+end
+
+function db:findMissingEntries(lasttimestamp)
+ local lastts = self.con:escape(lasttimestamp)
+ return = self.con:execute("SELECT * FROM " .. self.table .. " WHERE timestamp > '" .. lastts .. "')")
+end
+
+function db:getNextMissingEntry(cur)
+ local data = {}
+ data = cur:fetch(data, "a")
+ if data == nil then
+ return nil, "that's all folks"
+ end
+ return data
end
function db:getEntry(timestamp)
@@ -80,7 +92,7 @@ function db:getEntry(timestamp)
return data
end
-function db:insertEntry(data)
+function db:addEntry(data)
local timestamp = self.con:escape(data.timestamp)
local cart = self.con:escape(data.cart)
local len = self.con:escape(data.len)
@@ -90,7 +102,7 @@ function db:insertEntry(data)
local album = self.con:escape(data.album)
local ismusic = self.con:escape(data.ismusic)
- local cur, err = self.con:execute("INSERT into " .. self.table .. " VALUES('" .. timestamp .. "', '" .. cart .. "', '" .. len .. "', '" .. showtitle .. "', '" .. title .. "', '" .. artist .."', '" .. album .. "', '" .. 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