From 9295f0d2cfebb5e4305f8ca1c5d69c4e6320f037 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Sun, 3 Apr 2011 16:32:47 +0000
Subject: db somte tweaks db get missing entries


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
-- 
cgit v0.10.2