From 6f8b67f4d558db456c4f47ed3ab4127f87f4413f Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Tue, 23 Sep 2014 16:40:37 +0200 Subject: [PATCH] MT#9067 use one MySQL connection only on NGCP Don't close the connection, just the cursor. We may need a ping function to test the connection. https://github.com/keplerproject/luasql/pull/12 --- ngcp/cp.lua | 1 - ngcp/dp.lua | 1 - ngcp/ngcp.lua | 11 +++++++---- ngcp/pp.lua | 1 - ngcp/up.lua | 1 - tests/ngcp.lua | 12 ++---------- tests/ngcp_dp.lua | 2 -- tests/ngcp_pp.lua | 2 -- tests/ngcp_up.lua | 2 -- 9 files changed, 9 insertions(+), 24 deletions(-) diff --git a/ngcp/cp.lua b/ngcp/cp.lua index 8cbd5a2..62c7e31 100644 --- a/ngcp/cp.lua +++ b/ngcp/cp.lua @@ -97,7 +97,6 @@ NGCPContractPrefs_MT.__tostring = function () sr.log("dbg", string.format("no results for query:%s", query)) end cur:close() - con:close() xavp = self:xavp(level, result) for k,v in pairs(defaults) do diff --git a/ngcp/dp.lua b/ngcp/dp.lua index 02ac084..f01a7d6 100644 --- a/ngcp/dp.lua +++ b/ngcp/dp.lua @@ -97,7 +97,6 @@ NGCPDomainPrefs_MT.__tostring = function () sr.log("dbg", string.format("no results for query:%s", query)) end cur:close() - con:close() xavp = self:xavp(level, result) for k,v in pairs(defaults) do diff --git a/ngcp/ngcp.lua b/ngcp/ngcp.lua index a5408a0..c74c561 100644 --- a/ngcp/ngcp.lua +++ b/ngcp/ngcp.lua @@ -80,10 +80,13 @@ NGCPConfig_MT = { __index = NGCPConfig } end function NGCPConfig:getDBConnection() - local env = assert (luasql.mysql()) - sr.log("dbg","connecting to mysql") - return env:connect( self.db_database, - self.db_username, self.db_pass, self.db_host, self.db_port) + if not self.con then + self.env = assert (luasql.mysql()) + sr.log("dbg","connecting to mysql") + self.con = self.env:connect( self.db_database, + self.db_username, self.db_pass, self.db_host, self.db_port) + end + return self.con end function NGCPConfig:get_defaults(vtype) diff --git a/ngcp/pp.lua b/ngcp/pp.lua index e5e4d11..8228567 100644 --- a/ngcp/pp.lua +++ b/ngcp/pp.lua @@ -99,7 +99,6 @@ NGCPPeerPrefs_MT.__tostring = function () sr.log("dbg", string.format("no results for query:%s", query)) end cur:close() - con:close() xavp = self:xavp(level, result) for k,v in pairs(defaults) do diff --git a/ngcp/up.lua b/ngcp/up.lua index 2b3ef27..8d19ad6 100644 --- a/ngcp/up.lua +++ b/ngcp/up.lua @@ -97,7 +97,6 @@ NGCPUserPrefs_MT.__tostring = function () sr.log("dbg", string.format("no results for query:%s", query)) end cur:close() - con:close() xavp = self:xavp(level, result) for k,v in pairs(defaults) do diff --git a/tests/ngcp.lua b/tests/ngcp.lua index ab2cc0d..d5589cf 100644 --- a/tests/ngcp.lua +++ b/tests/ngcp.lua @@ -130,7 +130,6 @@ TestNGCP = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - self.con:close() mc:replay() local keys = self.ngcp:caller_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c") @@ -152,7 +151,6 @@ TestNGCP = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.dp_vars:val("d_192_168_51_56")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - self.con:close() mc:replay() local keys = self.ngcp:caller_usr_load(nil, "192.168.51.56") @@ -177,8 +175,7 @@ TestNGCP = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.dp_vars:val("d_192_168_51_56")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - self.con:close() - env:connect(c.db_database, c.db_username, c.db_pass, c.db_host, c.db_port) ;mc :returns(self.con) + self.con:execute("SELECT * FROM usr_preferences WHERE uuid ='ae736f72-21d1-4ea6-a3ea-4d7f56b3887c'") ;mc :returns(self.cur) self.cur:fetch(mc.ANYARGS) ;mc :returns(self.up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(self.up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) @@ -188,7 +185,6 @@ TestNGCP = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - self.con:close() mc:replay() local keys = self.ngcp:caller_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c", "192.168.51.56") @@ -215,8 +211,7 @@ TestNGCP = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.dp_vars:val("d_192_168_51_56")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - self.con:close() - env:connect(c.db_database, c.db_username, c.db_pass, c.db_host, c.db_port) ;mc :returns(self.con) + self.con:execute("SELECT * FROM usr_preferences WHERE uuid ='ae736f72-21d1-4ea6-a3ea-4d7f56b3887c'") ;mc :returns(self.cur) self.cur:fetch(mc.ANYARGS) ;mc :returns(self.up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(self.up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) @@ -225,7 +220,6 @@ TestNGCP = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - self.con:close() mc:replay() local keys = self.ngcp:callee_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c", "192.168.51.56") @@ -251,7 +245,6 @@ TestNGCP = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.pp_vars:val("p_2")) --sst_refresh_method: "UPDATE_FALLBACK_INVITE" self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - self.con:close() mc:replay() local keys = self.ngcp:caller_peer_load("2") @@ -274,7 +267,6 @@ TestNGCP = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.pp_vars:val("p_2")) --sst_refresh_method: "UPDATE_FALLBACK_INVITE" self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - self.con:close() mc:replay() local keys = self.ngcp:callee_peer_load("2") diff --git a/tests/ngcp_dp.lua b/tests/ngcp_dp.lua index 1a86a53..9b5ad15 100644 --- a/tests/ngcp_dp.lua +++ b/tests/ngcp_dp.lua @@ -101,7 +101,6 @@ TestNGCPDomainPrefs = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.dp_vars:val("d_192_168_51_56")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - con:close() mc:replay() local keys = self.d:caller_load("192.168.51.56") @@ -119,7 +118,6 @@ TestNGCPDomainPrefs = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.dp_vars:val("d_192_168_51_56")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - con:close() mc:replay() local keys = self.d:callee_load("192.168.51.56") diff --git a/tests/ngcp_pp.lua b/tests/ngcp_pp.lua index 7141375..d8f70f3 100644 --- a/tests/ngcp_pp.lua +++ b/tests/ngcp_pp.lua @@ -111,7 +111,6 @@ TestNGCPPeerPrefs = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.pp_vars:val("p_2")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - con:close() mc:replay() local keys = self.d:caller_load("2") @@ -131,7 +130,6 @@ TestNGCPPeerPrefs = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.pp_vars:val("p_2")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - con:close() mc:replay() local keys = self.d:callee_load("2") diff --git a/tests/ngcp_up.lua b/tests/ngcp_up.lua index a425bee..7389e94 100644 --- a/tests/ngcp_up.lua +++ b/tests/ngcp_up.lua @@ -113,7 +113,6 @@ TestNGCPUserPrefs = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - con:close() mc:replay() local keys = self.d:caller_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c") @@ -136,7 +135,6 @@ TestNGCPUserPrefs = {} --class self.cur:fetch(mc.ANYARGS) ;mc :returns(self.up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:close() - con:close() mc:replay() local keys = self.d:callee_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c")