Hi,
I want to create functions what makes sql queries easier, but I'm stuck with the update statement prepare. I tried unpack and table.concat, but didn't worked.
-- Example:
local core = exports.core;
core:dbUpdate('table_name', { name = 'New Name' }, { name = 'Old Name' }); -- 3. arg stands for WHERE thing
-- Core code
function dbUpdate(tableName, data, where)
if (dbConn and qID and tableName and data and type(data) == 'table' and where and where == 'table') then
local keys, values, rows = concatTable(data);
local wkeys, wvalues, wrows = concatTable(where);
-- do magic tricks to prepare query string
dbExec(dbConn, queryString);
end
end
function concatTable(data)
local keys, values, rows = {}, {}, 0;
for i, v in pairs(data) do
table.insert(keys, i);
table.insert(values, v);
rows = rows + 1;
end
return keys, values, rows;
end