summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-02-05 16:39:56 +0000
committerTed Trask <ttrask01@yahoo.com>2013-02-05 16:55:48 +0000
commitfdb356209a0ea846115447dceec4721375a4a604 (patch)
tree583307e543dfcb5877ca59306f9426a83c8089ed
parent674ef819171d9e46481152bc50e8f38d8cf7c083 (diff)
downloadacf-kamailio-fdb356209a0ea846115447dceec4721375a4a604.tar.bz2
acf-kamailio-fdb356209a0ea846115447dceec4721375a4a604.tar.xz
Added postgres version check to determine if should escape backslash or not
(cherry picked from commit d98358c9c05802e79a8185e466c14a42aebd2c22)
-rw-r--r--kamailio-model.lua59
1 files changed, 37 insertions, 22 deletions
diff --git a/kamailio-model.lua b/kamailio-model.lua
index 389ee72..85f8f04 100644
--- a/kamailio-model.lua
+++ b/kamailio-model.lua
@@ -17,6 +17,7 @@ local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
local env
local con
local DBENGINE
+local escapebackslash = false
-- ################################################################################
-- DATABASE FUNCTIONS
@@ -32,9 +33,34 @@ end
-- Escape special characters in sql statements
local escape = function(sql)
sql = sql or ""
+ if escapebackslash then
+ sql = string.gsub(sql, "\\", "\\\\")
+ end
return string.gsub(sql, "'", "''")
end
+local runsqlcommand = function(sql)
+logevent(sql)
+ assert(con:execute(sql))
+end
+
+local getselectresponse = function(sql)
+ local retval = {}
+logevent(sql)
+ local cur = assert (con:execute(sql))
+ local row = cur:fetch ({}, "a")
+ while row do
+ local tmp = {}
+ for name,val in pairs(row) do
+ tmp[name] = val
+ end
+ retval[#retval + 1] = tmp
+ row = cur:fetch (row, "a")
+ end
+ cur:close()
+ return retval
+end
+
local databaseconnect = function()
if not con then
-- parse the kamctlrc file
@@ -62,6 +88,17 @@ local databaseconnect = function()
-- connect to data source
con = assert(env:connect(config.DBNAME or "openser", config.DBRWUSER or "openser", config.DBRWPW or "openserrw", config.DBHOST, config.DBPORT))
+
+ -- Check the version for any special functionality
+ if DBENGINE == "PGSQL" then
+ local out = getselectresponse("SELECT version()")
+ local version = string.match(out[1].version, "([%d%.]+)")
+ local versionnum = tonumber(string.match(version, "%d+%.%d+"))
+ if versionnum < 9.1 then
+ escapebackslash = true
+ end
+ end
+
return true
end
return false
@@ -78,28 +115,6 @@ local databasedisconnect = function()
end
end
-local runsqlcommand = function(sql)
-logevent(sql)
- assert(con:execute(sql))
-end
-
-local getselectresponse = function(sql)
- local retval = {}
-logevent(sql)
- local cur = assert (con:execute(sql))
- local row = cur:fetch ({}, "a")
- while row do
- local tmp = {}
- for name,val in pairs(row) do
- tmp[name] = val
- end
- retval[#retval + 1] = tmp
- row = cur:fetch (row, "a")
- end
- cur:close()
- return retval
-end
-
local listtables = function()
local result = {}
if DBENGINE == "PGSQL" then