lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


database file gets created using below sql file, then lua script calls "db.import config_ascc", then I get errors says "insert table failed for eventLog", below are my sql file entry, config file, also import and saveTable function, any idea what is wrong, why I get error?.

actually I found this log file gets created by db.export function below, when it inserts, it adds "\" for every textMessage, looklike that "\" is creating this error "insert table failed", I canot figureout how this "\" is getting added by db.export/db.saveTable function?. can some expert figureout?.


system.sql file
==========
CREATE TABLE eventLog
(
component text NOT NULL,
facilityId integer NOT NULL,
logLevel integer NOT NULL,
textMessage text NOT NULL,
binMessage blob,
FOREIGN KEY (component,facilityId) REFERENCES compFacilityMap(component,facilityId)
)
;

insert into saveTables (tableName) values("eventLog");


config_ascci file
===========
eventLog = {}
eventLog[1] = {}
eventLog[1]["component"] = "UMI_COMP_NTP"
eventLog[1]["textMessage"] = "Sun Dec 30 11:08:00 2007 [Netgard_MFD][System][NTP] ntpTblHandler:167:ntpTblHandler\
eventLog[1]["logLevel"] = "128"
eventLog[1]["binMessage"] = ""
eventLog[1]["_ROWID_"] = "1"
eventLog[1]["facilityId"] = "3"
eventLog[2] = {}
eventLog[2]["component"] = "UMI_COMP_NTP"
eventLog[2]["textMessage"] = "Sun Dec 30 11:08:00 2007 [Netgard_MFD][System][NTP] ntpTblHandler:181:tz: 0 \
eventLog[2]["logLevel"] = "128"
eventLog[2]["binMessage"] = ""
eventLog[2]["_ROWID_"] = "2"
eventLog[2]["facilityId"] = "3"
eventLog[3] = {}
eventLog[3]["component"] = "UMI_COMP_NTP"
eventLog[3]["textMessage"] = "Sun Dec 30 11:08:00 2007 [Netgard_MFD][System][NTP] ntpTblHandler:191:DayLightsaving: 0 \
eventLog[3]["logLevel"] = "128"
eventLog[3]["binMessage"] = ""
eventLog[3]["_ROWID_"] = "3"
eventLog[3]["facilityId"] = "3"
eventLog[4] = {}
eventLog[4]["component"] = "UMI_COMP_NTP"
eventLog[4]["textMessage"] = "Sun Dec 30 11:08:00 2007 [Netgard_MFD][System][NTP] ntpTblHandler:204:status: 1 \
eventLog[4]["logLevel"] = "128"
eventLog[4]["binMessage"] = ""
eventLog[4]["_ROWID_"] = "4"
eventLog[4]["facilityId"] = "3"
eventLog[5] = {}
eventLog[5]["component"] = "UMI_COMP_NTP"
eventLog[5]["textMessage"] = "Sun Dec 30 11:08:03 2007 [Netgard_MFD][System][NTP] ntpTblHandler:236:pNtpControl->ServerNames[PRIMARY_SERVER]: 0.us.pool.ntp.org \
eventLog[5]["logLevel"] = "128"
eventLog[5]["binMessage"] = ""
eventLog[5]["_ROWID_"] = "5"
eventLog[5]["facilityId"] = "3"
eventLog[6] = {}
eventLog[6]["component"] = "UMI_COMP_NTP"
eventLog[6]["textMessage"] = "Sun Dec 30 11:08:03 2007 [Netgard_MFD][System][NTP] ntpTblHandler:242:pNtpControl->ServerNames[SECONDARY_SERVER]: 1.us.pool.ntp.org \
eventLog[6]["logLevel"] = "128"
eventLog[6]["binMessage"] = ""
eventLog[6]["_ROWID_"] = "6"
eventLog[6]["facilityId"] = "3"
eventLog[7] = {}
eventLog[7]["component"] = "UMI_COMP_NTP"
eventLog[7]["textMessage"] = "Sun Dec 30 11:08:03 2007 [Netgard_MFD][System][NTP] ntpTblHandler:281:DS: 1 \
eventLog[7]["logLevel"] = "128"
eventLog[7]["binMessage"] = ""
eventLog[7]["_ROWID_"] = "7"
eventLog[7]["facilityId"] = "3"
eventLog[8] = {}
eventLog[8]["component"] = "UMI_COMP_NTP"
eventLog[8]["textMessage"] = "Sun Dec 30 11:08:03 2007 [Netgard_MFD][System][NTP] ntpdGetDefaultServers:509:pPriServ 0.us.pool.ntp.org\
eventLog[8]["logLevel"] = "128"
eventLog[8]["binMessage"] = ""
eventLog[8]["_ROWID_"] = "8"
eventLog[8]["facilityId"] = "3"
eventLog[9] = {}
eventLog[9]["component"] = "UMI_COMP_NTP"
eventLog[9]["textMessage"] = "Sun Dec 30 11:08:03 2007 [Netgard_MFD][System][NTP] ntpdGetDefaultServers:510:pSecServ 1.us.pool.ntp.org\
eventLog[9]["logLevel"] = "128"
eventLog[9]["binMessage"] = ""
eventLog[9]["_ROWID_"] = "9"
eventLog[9]["facilityId"] = "3"
eventLog[10] = {}
eventLog[10]["component"] = "UMI_COMP_PLATFORM"
eventLog[10]["textMessage"] = "Sun Dec 30 11:08:03 2007 [Netgard_MFD][System][PLATFORM] platformHandleDBUpdate:248:DATABASE UPDATE, Table Name:vlan operation:INSERT row=2\
eventLog[10]["logLevel"] = "128"
eventLog[10]["binMessage"] = ""
eventLog[10]["_ROWID_"] = "10"
eventLog[10]["facilityId"] = "3"

 
  1.  
  2. database.lua script
  3. =============
  4. -- Import settings from given file.
  5. function db.import (filename)
  6.     local valid = true
  7.     util.appendDebugOut("Imported DB!<br>")
  8.     dofile(filename)
  9.     local saveTables = db.getTable("saveTables", false)
  10.     db.beginTransaction()
  11.  
  12.     -- for each dbTable
  13.     for k,v in pairs(saveTables) do
  14.         if (not valid) then break end
  15.         local tableName = v["tableName"]
  16.         local table = util.getLuaVariable(tableName)
  17.  
  18.         if (table == nil) then
  19.             print ("no LUA variable:" .. tableName)
  20.             break
  21.         end
  22.  
  23.         if (#table >= 1) then
  24.             -- for each row
  25.             for kk,vv in pairs(table) do
  26.                 valid = db.insert(tableName, table[kk], true, true)
  27.                 if (not valid) then 
  28.                     print ("******** table insert failed for " .. tableName)
  29.                     break 
  30.                 end
  31.             end
  32.         end
  33.     end
  34.  
  35.     -- return
  36.     if (valid) then
  37.         db.commitTransaction()
  38.         return "imported successfully!!!!!!!!!!!!!!!!!!"
  39.     else
  40.         db.rollback()
  41.         return "import failed!"
  42.     end
  43. end
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. -- Save table to file in ascii format.
  52. function db.saveTable (f, name, value, saved)
  53.     local one, two = "", ""
  54.     saved = saved or {}       -- initial value
  55.     if type(value) == "number" or type(value) == "string" then
  56.         one = name .. " = "
  57.         two = basicSerialize(value) .. "\n"
  58.         f:write(one, two)
  59.     elseif type(value) == "table" then
  60.         one = name .. " = "
  61.         if saved[value] then    -- value already saved?
  62.             f:write(one)
  63.             f:write(saved[value], "\n")  -- use its previous name
  64.         else
  65.             f:write(one)
  66.             f:write("{}\n")
  67.             saved[value] = name   -- save name for next time
  68.             for k,v in pairs(value) do      -- save its fields
  69.                 local fieldname = string.format("%s[%s]", name,
  70.                 basicSerialize(k))
  71.                 db.saveTable(f, fieldname, v, saved)
  72.             end
  73.         end
  74.     else
  75.     -- function
  76.     end
  77.     f:flush()
  78. end
  79.  
  80. -- Export settings and flash it.

    function db.save ()

    -- export

    db.export(SETTINGS_FILE)

    -- copy file to flash

    local writeprog = db.getAttribute("environment", "name", "CFG_WRITE_PROGRAM", "value")

    local configpart = db.getAttribute("environment", "name", "FLASH_CFG_PARTITION", "value")

    util.appendDebugOut("Exec = " .. os.execute(writeprog .. " " .. configpart .. " " .. SETTINGS_FILE))

    util.appendDebugOut("Saved DB!<br>")

    end

    -- Export settings to given file.

    function db.export (filename)

    local f = io.open(filename, "wb")

    local saveTables = db.getTable("saveTables", false)

    for k,v in pairs(saveTables) do

    db.saveTable(f, v["tableName"], db.getTable(v["tableName"], false))

    end

    end

 
 


 
On Tue, Feb 2, 2010 at 10:43 AM, Rob Kendrick <rjek@rjek.com> wrote:
On Tue, 2 Feb 2010 10:18:06 -0500
Vasanta <vtanna1@gmail.com> wrote:

> lua script add "\" when I save log, it shows correct string when I
> display table from database, how can I figureout who inserts "\"

It may help if you provide example sources, data sets and actual output
along with your expected output.  We'll be able to more quickly and
accurately help you.

Also, what is the "log", and how are you saving it, and what are you
using to display the table from which database?

B.