diff options
Diffstat (limited to 'tex/context/base/util-sql-imp-swiglib.lua')
-rw-r--r-- | tex/context/base/util-sql-imp-swiglib.lua | 84 |
1 files changed, 74 insertions, 10 deletions
diff --git a/tex/context/base/util-sql-imp-swiglib.lua b/tex/context/base/util-sql-imp-swiglib.lua index 15fbe2487..9a22477a9 100644 --- a/tex/context/base/util-sql-imp-swiglib.lua +++ b/tex/context/base/util-sql-imp-swiglib.lua @@ -15,13 +15,20 @@ local concat = table.concat local format = string.format local lpegmatch = lpeg.match local setmetatable, type = setmetatable, type +local sleep = os.sleep local trace_sql = false trackers.register("sql.trace", function(v) trace_sql = v end) local trace_queries = false trackers.register("sql.queries",function(v) trace_queries = v end) local report_state = logs.reporter("sql","swiglib") local sql = utilities.sql -local mysql = require("swigluamysql") +local mysql = require("swiglib.mysql.core") -- "5.6" + +-- inspect(table.sortedkeys(mysql)) + +local nofretries = 5 +local retrydelay = 1 + local cache = { } local helpers = sql.helpers local methods = sql.methods @@ -53,15 +60,28 @@ local mysql_options_argument = mysql.mysql_options_argument local instance = mysql.MYSQL() -local mysql_constant_false = mysql_options_argument(false) -- 0 "\0" -local mysql_constant_true = mysql_options_argument(true) -- 1 "\1" - --- print(swig_type(mysql_constant_false)) --- print(swig_type(mysql_constant_true)) - -mysql.mysql_options(instance,mysql.MYSQL_OPT_RECONNECT,mysql_constant_true); +local mysql_constant_false = false +local mysql_constant_true = true + +-- if mysql_options_argument then +-- +-- mysql_constant_false = mysql_options_argument(false) -- 0 "\0" +-- mysql_constant_true = mysql_options_argument(true) -- 1 "\1" +-- +-- -- print(swig_type(mysql_constant_false)) +-- -- print(swig_type(mysql_constant_true)) +-- +-- mysql.mysql_options(instance,mysql.MYSQL_OPT_RECONNECT,mysql_constant_true); +-- +-- else +-- +-- print("") +-- print("incomplete swiglib.mysql interface") +-- print("") +-- +-- end -local typemap = { +local typemap = mysql.MYSQL_TYPE_VAR_STRING and { [mysql.MYSQL_TYPE_VAR_STRING ] = "string", [mysql.MYSQL_TYPE_STRING ] = "string", [mysql.MYSQL_TYPE_DECIMAL ] = "number", @@ -272,6 +292,16 @@ local function connect(session,specification) ) end +local function error_in_connection(specification,action) + report_state("error in connection: [%s] %s@%s to %s:%s", + action or "unknown", + specification.database or "no database", + specification.username or "no username", + specification.host or "no host", + specification.port or "no port" + ) +end + local function datafetched(specification,query,converter) if not query or query == "" then report_state("no valid query") @@ -288,11 +318,45 @@ local function datafetched(specification,query,converter) if not connection then session = initialize() connection = connect(session,specification) - cache[id] = { session = session, connection = connection } + if not connection then + for i=1,nofretries do + sleep(retrydelay) + report_state("retrying to connect: [%s.%s] %s@%s to %s:%s", + id,i, + specification.database or "no database", + specification.username or "no username", + specification.host or "no host", + specification.port or "no port" + ) + connection = connect(session,specification) + if connection then + break + end + end + end + if connection then + cache[id] = { session = session, connection = connection } + end end else session = initialize() connection = connect(session,specification) + if not connection then + for i=1,nofretries do + sleep(retrydelay) + report_state("retrying to connect: [%s] %s@%s to %s:%s", + i, + specification.database or "no database", + specification.username or "no username", + specification.host or "no host", + specification.port or "no port" + ) + connection = connect(session,specification) + if connection then + break + end + end + end end if not connection then report_state("error in connection: %s@%s to %s:%s", |