From 5cfd8ae5b5dd713af7d974c2b0234ab0d4487b84 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 3 Oct 2008 11:18:16 -0700 Subject: Adding 'default' field to ddl. --- lib/dblib.lua | 11 +++++++++-- 1 file 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 -- cgit v1.2.3