forked from mff/mysql_base
Abstraction: add INSERT default values & UPDATE custom value
This commit is contained in:
parent
fc093abb9f
commit
124bdb7401
@ -11,6 +11,9 @@ function thismod.create_table_sql(name, params)
|
||||
if coldata.notnull then
|
||||
line = line .. ' NOT NULL'
|
||||
end
|
||||
if coldata.default then
|
||||
line = line .. ' DEFAULT ' .. coldata.default
|
||||
end
|
||||
if coldata.autoincrement then
|
||||
line = line .. ' AUTO_INCREMENT'
|
||||
end
|
||||
@ -69,9 +72,11 @@ end
|
||||
function thismod.prepare_update(tablename, cols, where, wheretypes)
|
||||
local colnames, paramtypes = {}, {}
|
||||
for _, col in ipairs(cols) do
|
||||
table.insert(colnames, (col.name or col[1]) .. '=?')
|
||||
table.insert(colnames, (col.name or col[1]) .. '=' .. (col.value or '?'))
|
||||
if col.type or col[2] then
|
||||
table.insert(paramtypes, col.type or col[2])
|
||||
end
|
||||
end
|
||||
for _, wheretype in ipairs(wheretypes) do
|
||||
table.insert(paramtypes, wheretype)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user