diff options
author | Christian Pointner <equinox@helsinki.at> | 2017-01-06 21:49:35 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2017-01-06 21:49:35 (GMT) |
commit | 52680074ae2143b5d92e1c99c36a53d4a9c01471 (patch) | |
tree | ae2251bd6bc8ee0acfec05d2e50efc69188755b1 /src/playlog.lua | |
parent | df67f85aafb91466bcd63681ebf4f6d9b3b6e8be (diff) |
fix last cart check
Diffstat (limited to 'src/playlog.lua')
-rw-r--r-- | src/playlog.lua | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/playlog.lua b/src/playlog.lua index b93a3cc..591468f 100644 --- a/src/playlog.lua +++ b/src/playlog.lua @@ -25,7 +25,7 @@ luasql = require "luasql.mysql" -- GRANT select,insert,update ON rhnop.* TO 'nopfetchd' IDENTIFIED BY '<password>'; -- GRANT select ON rhnop.* TO 'nopsyncd' IDENTIFIED BY '<password>'; -- 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), carttype ENUM('show','pool','jingle')); +-- 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), carttype ENUM('show','pool','jingle'), output INT NOT NULL); -- ALTER TABLE now CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci; local playlog = {} @@ -56,8 +56,8 @@ function playlog:init(cnf) return true end -function playlog:getLastCart() - local cur, err = self.con:execute("SELECT cart FROM now WHERE timestamp = (SELECT MAX(timestamp) FROM now)") +function playlog:getLastCart(output, timestamp) + local cur, err = self.con:execute("SELECT cart FROM now WHERE timestamp = " .. timestamp .. " and output = " .. output) if cur == nil then return nil, err end @@ -67,10 +67,30 @@ function playlog:getLastCart() return cart end -function playlog:insertNow(timestamp, cart, len, showtitle, title, artist, album, carttype) +function playlog:getLastCarts() + local cur, err = self.con:execute("select output,max(timestamp) as timestamp from now GROUP BY output") + if cur == nil then + return nil, err + end + + local carts = {} + while true do + local data = {} + data = cur:fetch(data, "a") + if data == nil then break end + + t[data.output] = self:getLastCart(data.output, data.timestamp) + end + cur:close() + + return t +end + +function playlog:insertNow(timestamp, cart, len, showtitle, title, artist, album, carttype, output) cart = tonumber(cart) len = tonumber(len) - local cur, err = self.con:execute("INSERT into now VALUES(" .. self.con:escape(timestamp) .. ", " .. cart .. ", " .. len .. ", '" .. self.con:escape(showtitle) .. "', '" .. self.con:escape(title) .. "', '" .. self.con:escape(artist) .."', '" .. self.con:escape(album) .. "', '" .. self.con:escape(carttype) .. "')") + output = tonumber(output) + local cur, err = self.con:execute("INSERT into now VALUES(" .. self.con:escape(timestamp) .. ", " .. cart .. ", " .. len .. ", '" .. self.con:escape(showtitle) .. "', '" .. self.con:escape(title) .. "', '" .. self.con:escape(artist) .."', '" .. self.con:escape(album) .. "', '" .. self.con:escape(carttype) .. "', " .. output .. ")") if cur == nil then return nil, err end |