From ae60921079fc349d0aab112c8536c33375001393 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 19 Sep 2015 18:36:43 +0000 Subject: Use db.getcolumndata to determine column type as previous version did not work for sqlite --- lib/dbmodelfunctions.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/dbmodelfunctions.lua b/lib/dbmodelfunctions.lua index d333548..e79bcb0 100644 --- a/lib/dbmodelfunctions.lua +++ b/lib/dbmodelfunctions.lua @@ -126,14 +126,15 @@ function mymodule.list_table_entries(dbase, self, clientdata) if t == retval.value.table.value then retval.value.table.errtxt = nil retval.errtxt = nil - -- FIXME - in the future, we should be able to do next these three things in one function call to db - retval.value.fields.value = db.listcolumns(t) or {} - retval.value.keyfields.value = db.listkeycolumns(t) or {} - -- this will not work for sqlite and the results are database-specific - local sql = "SELECT data_type FROM information_schema.columns WHERE table_name = '"..db.escape(t).."' ORDER BY ordinal_position" - local types = db.getselectresponse(sql) local fieldtypes = {} - for i,f in ipairs(types) do fieldtypes[retval.value.fields.value[i]] = f.data_type end + local columndata = db.getcolumndata(t) + for i,c in ipairs(columndata) do + retval.value.fields.value[#retval.value.fields.value+1] = c.name + if c.key then + retval.value.keyfields.value[#retval.value.keyfields.value+1] = c.name + end + fieldtypes[c.name] = c.type + end local orderby = {} local columns = {} -- cgit v1.2.3