summaryrefslogtreecommitdiff
path: root/nopsyncd/tempstorage.lua
diff options
context:
space:
mode:
Diffstat (limited to 'nopsyncd/tempstorage.lua')
-rw-r--r--nopsyncd/tempstorage.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/nopsyncd/tempstorage.lua b/nopsyncd/tempstorage.lua
index f034647..37f3422 100644
--- a/nopsyncd/tempstorage.lua
+++ b/nopsyncd/tempstorage.lua
@@ -49,6 +49,33 @@ function tempstorage:init()
return true
end
+function tempstorage:getLastCart()
+ local cur, err = self.con:execute("SELECT cart from (SELECT cart,timestamp,MAX(timestamp) AS tsmax FROM now) where timestamp = tsmax")
+ if cur == nil then
+ return nil, err
+ end
+
+ local cart = cur:fetch()
+ if cart == nil then cart = 0 end
+ return cart
+end
+
+function tempstorage:insertMusic(timestamp, cart, len, title, artist, album)
+ cart = tonumber(cart)
+ if cart < 400000 or cart > 450000 then
+ poolnum = 0
+ else
+ poolnum = math.floor(cart/1000) - 399
+ end
+ -- TODO escape "' in strings"
+ local cur, err = self.con:execute("INSERT into now VALUES(" .. timestamp .. ", " .. cart .. ", " .. len .. ", 'Musikpool " .. poolnum .. "', '" .. title .. "', '" .. artist .."', '" .. album .. "', 1)")
+ if cur == nil then
+ return nil, err
+ end
+
+ return true
+end
+
function tempstorage:close()
if self.con then
self.con:close()