summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2008-10-03 11:18:16 -0700
committerPixel <pixel@nobis-crew.org>2008-10-03 11:18:16 -0700
commit5cfd8ae5b5dd713af7d974c2b0234ab0d4487b84 (patch)
treeccec63fee69ff501ab8184477d3192f2dd98477e
parentb6aa3267bb1e51ff2e451eb3b2135736155bebb4 (diff)
Adding 'default' field to ddl.
-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