summaryrefslogtreecommitdiffstats
path: root/kamailio-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2011-02-23 14:24:20 +0000
committerTed Trask <ttrask01@yahoo.com>2011-02-23 14:24:20 +0000
commit31f68d1ea1390017773e691cccd0e6f9cc1fd0a7 (patch)
tree94895b8799f0682635280ff67e3e7959ca1f1cde /kamailio-model.lua
parent8ceb7e4eb46a498d4d63005dd02b32af012dc4d1 (diff)
downloadacf-kamailio-31f68d1ea1390017773e691cccd0e6f9cc1fd0a7.tar.bz2
acf-kamailio-31f68d1ea1390017773e691cccd0e6f9cc1fd0a7.tar.xz
Added searchdatabase action
Diffstat (limited to 'kamailio-model.lua')
-rw-r--r--kamailio-model.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/kamailio-model.lua b/kamailio-model.lua
index 9c24346..7937ea8 100644
--- a/kamailio-model.lua
+++ b/kamailio-model.lua
@@ -469,3 +469,36 @@ function create_database()
local result = f:read("*a")
return cfe({ value=result, label="Create database result" })
end
+
+function search_database(id, value, comparison)
+ local errtxt
+ retval = {}
+ retval.id = cfe({type="select", value=id or "", label="Table.Column", option={}, seq=1})
+ retval.comparison = cfe({type="select", value=comparison or "=", label="Comparison", option={"=", "!=", "~", "!~", "~*", "!*~"}, seq=2})
+ retval.value = cfe({label="Value", value=value or "", descr="Value or SQL regular expression", seq=3})
+ local res, err = pcall(function()
+ local connected = databaseconnect()
+ local tables = listtables() or {}
+ for i,t in ipairs(tables) do
+ local columns = listcolumns(t) or {}
+ for i,c in ipairs(columns) do
+ retval.id.option[#retval.id.option + 1] = t.."."..c
+ end
+ end
+ -- Get the rows from the DB
+ if id and modelfunctions.validateselect(retval.id) and modelfunctions.validateselect(retval.comparison) then
+ retval.result = cfe({type="structure", value={}, label="List of Rows", seq=4 })
+ local table, column = string.match(id, "^([^.]*)%.(.*)")
+ if table then
+ local sql = "SELECT * FROM "..table.." WHERE "..column..comparison.."'"..value.."'"
+ retval.result.value = getselectresponse(sql)
+ end
+ end
+ if connected then databasedisconnect() end
+ end)
+ if not res and err then
+ errtxt = err
+ end
+ return cfe({type="group", value=retval, label="Database Search", errtxt=errtxt})
+end
+