I am trying to find out if a field exist in a table. Is there a simple way to do this ?
I am using reteset's plugin v3.7.2
I am using reteset's plugin v3.7.2
function DoesColumnExist(db,strTable,strColumn) local q = string.format("SELECT %s FROM %s",strColumn,strTable) local stm = db:prepare(q) local bret = false if stm then if(stm:step() ) then bret = true end stm:finalize() end return bret end
local db = sqlite3.open_memory() db:exec[[ CREATE TABLE test (id INTEGER PRIMARY KEY, content TEXT); INSERT IGNORE INTO test VALUES (NULL, 'Hello World'); ]] local tblName = "test" local clmnName = "content" if (DoesColumnExist(db,tblName,clmnName)) then Dialog.Message("Notice", "The Column : "..clmnName.." Does Exist In Table : "..tblName); else Dialog.Message("Notice", "The Column : "..clmnName.." Does Not Exist In Table : "..tblName); end db:close()
Comment