summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rddb.lua67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/rddb.lua b/src/rddb.lua
index 0827f62..5bf9db2 100644
--- a/src/rddb.lua
+++ b/src/rddb.lua
@@ -51,6 +51,7 @@ function rddb:getCartInfo(cartnum)
end
if cur:numrows() ~= 1 then
+ cur:close()
return nil, "nothing found in rivendell db"
end
@@ -101,13 +102,77 @@ function rddb:getGroupNameAndCartType(cartnum)
return carttype, groupname, groupdesc
end
+local getShowType = function(params)
+ local n = 0
+ for p in string.gmatch(params, "([^;]+)") do
+ if n == 5 then
+ return p
+ end
+ n = n + 1
+ end
+ return "n"
+end
+
+local getShowLog = function(macros)
+ local log = string.match(macros, "^LL 1 ([^ ]+) 0!$")
+ if log == nil then
+ return nil, "invalid show macro"
+ end
+ log = string.gsub(log, "-", "_") .. "_LOG"
+ if string.match(log, "^[_0-9a-zA-Z-]+$") == nil then
+ return nil, "invalid show log-name: " .. log
+ end
+ return log
+end
+
+function rddb:__showHasCart(showlog, cartnum)
+ local cur, err = self.con:execute("select CART_NUMBER from " .. showlog .. " where CART_NUMBER = " .. tonumber(cartnum))
+ if cur == nil then
+ return nil, err
+ end
+ local nresults = cur:numrows()
+ cur:close()
+
+ return nresults > 0
+end
+
+function rddb:__getShowNameForShowCart(cartnum, groupname)
+ local cur, err = self.con:execute("select CART.TITLE,CART.MACROS,DROPBOXES.SET_USER_DEFINED as PARAMS from CART,DROPBOXES where CART.NUMBER = DROPBOXES.TO_CART and DROPBOXES.GROUP_NAME = '" .. self.con:escape(groupname) .. "'")
+ if cur == nil then
+ return nil, err
+ end
+
+ while true do
+ local data = {}
+ data = cur:fetch(data, "a")
+ if data == nil then break end
+
+ local showtype = getShowType(data.PARAMS)
+ if showtype == "r" then
+ data.TITLE = data.TITLE .. " (Wiederholung)"
+ elseif showtype == "s" then
+ data.TITLE = data.TITLE .. " (Sondersendung)"
+ end
+
+ local log = getShowLog(data.MACROS)
+
+ if self:__showHasCart(log, cartnum) then
+ cur:close()
+ return data.TITLE, "show"
+ end
+ end
+ cur:close()
+
+ return nil, "can't find any show for cart: " .. cartnum
+end
+
function rddb:getCartShowName(cartnum)
local carttype, groupname, groupdesc = self:getGroupNameAndCartType(cartnum)
if carttype == nil then
return nil, groupname
end
if carttype == "show" then
- return nil, "show carts not yet supported"
+ return rddb:__getShowNameForShowCart(cartnum, groupname)
end
return groupdesc, carttype
end