diff options
author | Christian Pointner <equinox@helsinki.at> | 2011-03-16 01:47:03 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2011-03-16 01:47:03 (GMT) |
commit | d3960b443bd20216d096815db6e10e2b7f6c53b9 (patch) | |
tree | 67322d836cdf6d1e771a2f9861cb6ef2c5308e42 /nopsyncd/tempstorage.lua | |
parent | 74cce8f8317cacc9f07404236710e68f279b3773 (diff) |
insert music into tempstorage
Diffstat (limited to 'nopsyncd/tempstorage.lua')
-rw-r--r-- | nopsyncd/tempstorage.lua | 27 |
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() |