[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Database tries to import configuration - lua script fails "insert table table failed for"
- From: Vasanta <vtanna1@...>
- Date: Mon, 1 Feb 2010 13:17:09 -0500
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?. thanks in advance.
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"
-
- database.lua script
- =============
- -- Import settings from given file.
- function db.import (filename)
- local valid = true
- util.appendDebugOut("Imported DB!<br>")
- dofile(filename)
- local saveTables = db.getTable("saveTables", false)
- db.beginTransaction()
-
- -- for each dbTable
- for k,v in pairs(saveTables) do
- if (not valid) then break end
- local tableName = v["tableName"]
- local table = util.getLuaVariable(tableName)
-
- if (table == nil) then
- print ("no LUA variable:" .. tableName)
- break
- end
-
- if (#table >= 1) then
- -- for each row
- for kk,vv in pairs(table) do
- valid = db.insert(tableName, table[kk], true, true)
- if (not valid) then
- print ("******** table insert failed for " .. tableName)
- break
- end
- end
- end
- end
-
- -- return
- if (valid) then
- db.commitTransaction()
- return "imported successfully!!!!!!!!!!!!!!!!!!"
- else
- db.rollback()
- return "import failed!"
- end
- end
-
-
-
-
-
-
-
- -- Save table to file in ascii format.
- function db.saveTable (f, name, value, saved)
- local one, two = "", ""
- saved = saved or {} -- initial value
- if type(value) == "number" or type(value) == "string" then
- one = name .. " = "
- two = basicSerialize(value) .. "\n"
- f:write(one, two)
- elseif type(value) == "table" then
- one = name .. " = "
- if saved[value] then -- value already saved?
- f:write(one)
- f:write(saved[value], "\n") -- use its previous name
- else
- f:write(one)
- f:write("{}\n")
- saved[value] = name -- save name for next time
- for k,v in pairs(value) do -- save its fields
- local fieldname = string.format("%s[%s]", name,
- basicSerialize(k))
- db.saveTable(f, fieldname, v, saved)
- end
- end
- else
- -- function
- end
- f:flush()
- end
-