1
0
mirror of https://github.com/MinetestForFun/mysql_base.git synced 2024-12-28 10:30:20 +01:00

Abstraction: add INSERT default values & UPDATE custom value

This commit is contained in:
Dorian Wouters 2017-11-22 21:30:58 +01:00
parent fc093abb9f
commit 124bdb7401
No known key found for this signature in database
GPG Key ID: 6E9DA8063322434B

View File

@ -9,7 +9,10 @@ function thismod.create_table_sql(name, params)
for _, coldata in ipairs(params.columns) do for _, coldata in ipairs(params.columns) do
local line = (coldata.name or coldata[1]) .. ' ' .. (coldata.type or coldata[2]) local line = (coldata.name or coldata[1]) .. ' ' .. (coldata.type or coldata[2])
if coldata.notnull then if coldata.notnull then
line = line .. ' NOT NULL' line = line .. ' NOT NULL'
end
if coldata.default then
line = line .. ' DEFAULT ' .. coldata.default
end end
if coldata.autoincrement then if coldata.autoincrement then
line = line .. ' AUTO_INCREMENT' line = line .. ' AUTO_INCREMENT'
@ -69,8 +72,10 @@ end
function thismod.prepare_update(tablename, cols, where, wheretypes) function thismod.prepare_update(tablename, cols, where, wheretypes)
local colnames, paramtypes = {}, {} local colnames, paramtypes = {}, {}
for _, col in ipairs(cols) do 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 '?'))
table.insert(paramtypes, col.type or col[2]) if col.type or col[2] then
table.insert(paramtypes, col.type or col[2])
end
end end
for _, wheretype in ipairs(wheretypes) do for _, wheretype in ipairs(wheretypes) do
table.insert(paramtypes, wheretype) table.insert(paramtypes, wheretype)