summaryrefslogtreecommitdiff
path: root/lib/dblib.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dblib.lua')
-rw-r--r--lib/dblib.lua11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/dblib.lua b/lib/dblib.lua
index 801ffb5..c0414f1 100644
--- a/lib/dblib.lua
+++ b/lib/dblib.lua
@@ -66,7 +66,7 @@ _luadb = {
end
end,
- generate_fields = function(ddl)
+ generate_fields = function(db, ddl)
local k, v
local r, r2 = {}, {}
@@ -111,12 +111,19 @@ _luadb = {
if options.AUTO then
r[k] = r[k] .. " AUTO_INCREMENT"
end
+
+ if v.default then
+ if type(v.default) ~= "string" and type(v.default) ~= "number" then
+ error("Default value for field " .. k .. " isn't usable.")
+ end
+ r[k] = r[k] .. ' DEFAULT "' .. db.sql_escape(v.default) .. '"'
+ end
end
return r, r2
end,
opentable = function(db, tablename, ddl)
- local fields, alters = _luadb.generate_fields(ddl)
+ local fields, alters = _luadb.generate_fields(db, ddl)
local tname = "`" .. db._.prefix .. db.sql_escape(tablename) .. "`"
if db:SafeQuery("DESC " .. tname) ~= 0 then