summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-10-09 19:38:05 +0000
committerTed Trask <ttrask01@yahoo.com>2013-10-09 19:38:05 +0000
commitee99aaec435442035100801ac7093ca536375265 (patch)
treeaf0857df4ff1303d20a1fef109bc6e8902607d03
parent3f507e4e6710b559ed1efe4260b043b6c1b1694d (diff)
downloadacf-lib-ee99aaec435442035100801ac7093ca536375265.tar.bz2
acf-lib-ee99aaec435442035100801ac7093ca536375265.tar.xz
Add support for sqlite3 to db.lua
-rw-r--r--db.lua18
1 files changed, 16 insertions, 2 deletions
diff --git a/db.lua b/db.lua
index 8712a2b..bdc6c07 100644
--- a/db.lua
+++ b/db.lua
@@ -27,6 +27,9 @@ export.databaseconnect = function(dbobject)
if dbobject.engine == engine.postgresql then
require("luasql.postgres")
dbobject.env = assert (luasql.postgres())
+ elseif dbobject.engine == engine.sqlite3 then
+ require("luasql.sqlite3")
+ dbobject.env = assert (luasql.sqlite3())
else
error("Unknown database engine "..tostring(dbobject.engine))
end
@@ -60,7 +63,12 @@ export.runsqlcommand = function(dbobject, sql, transaction)
local res, err = dbobject.con:execute(sql)
if not res and err then
-- Catch the error to see if it's caused by lack of table
- local table = string.match(err, "relation \"(%S+)\" does not exist")
+ local table
+ if dbobject.engine == engine.postgresql then
+ table = string.match(err, "relation \"(%S+)\" does not exist")
+ elseif dbobject.engine == engine.sqlite3 then
+ table = string.match(err, "LuaSQL: no such table: (%S+)")
+ end
if table and dbobject.table_creation_scripts[table] then
if transaction then assert(dbobject.con:execute("ROLLBACK TO before_command")) end
dbobject.runscript(dbobject.table_creation_scripts[table])
@@ -96,7 +104,12 @@ export.getselectresponse = function(dbobject, sql, transaction)
end)
if not res and err then
-- Catch the error to see if it's caused by lack of table
- local table = string.match(err, "relation \"(%S+)\" does not exist")
+ local table
+ if dbobject.engine == engine.postgresql then
+ table = string.match(err, "relation \"(%S+)\" does not exist")
+ elseif dbobject.engine == engine.sqlite3 then
+ table = string.match(err, "LuaSQL: no such table: (%S+)")
+ end
if table and dbobject.table_creation_scripts[table] then
if transaction then assert(con:execute("ROLLBACK TO before_select")) end
dbobject.runscript(dbobject.table_creation_scripts[table])
@@ -167,6 +180,7 @@ end
engine = {
["postgresql"] = 1,
+["sqlite3"] = 2,
}
create = function(engine, database, user, password, host, port)