Skip to content

Commit

Permalink
Check connections to MySQL only if query execution fails
Browse files Browse the repository at this point in the history
* Try to execute query using the existing connection.
* If that fails, establish new connection and execute query, so a
  balance is maintained between persistent connection and new connection
  for every query.
* If possible, look for a better/alternative solution.
  • Loading branch information
nishithshah2211 committed Jan 8, 2016
1 parent 9811160 commit 9e8cc8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions external/info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ _G.tFunction = {

Execute = function( sQuery )
local luasql = luasql or require "luasql.mysql"
if not ( SQLEnv and SQLCon ) then
local bSuccess, SQLCur = pcall( SQLCon.execute, SQLCon, sQuery )
if not bSuccess then
_G.SQLEnv = assert( luasql.mysql() )
_G.SQLCon = assert( SQLEnv:connect(Connection 'latest') )
SQLCur = assert( SQLCon:execute(sQuery) )
end
return assert( SQLCon:execute(sQuery) )
return SQLCur
end,

Report = ( function()
Expand Down
6 changes: 4 additions & 2 deletions external/offliner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ _G.tFunction = {

Execute = function( sQuery )
local luasql = luasql or require "luasql.mysql"
if not ( SQLEnv and SQLCon ) then
local bSuccess, SQLCur = pcall( SQLCon.execute, SQLCon, sQuery )
if not bSuccess then
_G.SQLEnv = assert( luasql.mysql() )
_G.SQLCon = assert( SQLEnv:connect(Connection 'latest') )
SQLCur = assert( SQLCon:execute(sQuery) )
end
return assert( SQLCon:execute(sQuery) )
return SQLCur
end,

Report = ( function()
Expand Down

0 comments on commit 9e8cc8a

Please sign in to comment.