Commit 88e2a9a7 authored by Ted Trask's avatar Ted Trask

Change the UPDATE syntax so also works on sqlite

parent a23e376f
...@@ -290,16 +290,19 @@ function mymodule.update_table_entry(dbase, self, entry, action, create) ...@@ -290,16 +290,19 @@ function mymodule.update_table_entry(dbase, self, entry, action, create)
local sql local sql
local names = {} local names = {}
local values = {} local values = {}
for n,v in pairs(entry.value.fields.value) do if create then
if create or not reversekeyfields[n] then for n,v in pairs(entry.value.fields.value) do
names[#names+1] = n names[#names+1] = n
values[#values+1] = get_field_value(db, self, entry, n) values[#values+1] = get_field_value(db, self, entry, n)
end end
end
if create then
sql = "INSERT INTO "..db.escape(entry.value.table.value).." ("..table.concat(names, ", ")..") VALUES("..table.concat(values, ", ")..")" sql = "INSERT INTO "..db.escape(entry.value.table.value).." ("..table.concat(names, ", ")..") VALUES("..table.concat(values, ", ")..")"
else else
sql = "UPDATE "..db.escape(entry.value.table.value).." SET ("..table.concat(names, ", ")..") = ("..table.concat(values, ", ")..") WHERE "..table.concat(fieldchecks, " AND ") for n,v in pairs(entry.value.fields.value) do
if not reversekeyfields[n] then
values[#values+1] = n.."="..get_field_value(db, self, entry, n)
end
end
sql = "UPDATE "..db.escape(entry.value.table.value).." SET "..table.concat(values, ", ").." WHERE "..table.concat(fieldchecks, " AND ")
end end
db.runsqlcommand(sql) db.runsqlcommand(sql)
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment