diff options
author | Hans Hagen <pragma@wxs.nl> | 2016-10-19 23:19:58 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-10-19 23:19:58 +0200 |
commit | 9e2c13b12ff90635be145c6c02e21d6e9583037f (patch) | |
tree | aa2dded4f0c97347381d72299cf93b6c3e4b80dd /tex/context/base/mkiv/util-sql-imp-client.lua | |
parent | d273e996892fcf539d67c9548c90d96c2877507a (diff) | |
download | context-9e2c13b12ff90635be145c6c02e21d6e9583037f.tar.gz |
2016-10-19 22:59:00
Diffstat (limited to 'tex/context/base/mkiv/util-sql-imp-client.lua')
-rw-r--r-- | tex/context/base/mkiv/util-sql-imp-client.lua | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/tex/context/base/mkiv/util-sql-imp-client.lua b/tex/context/base/mkiv/util-sql-imp-client.lua index 55c944ebb..6a019bd3a 100644 --- a/tex/context/base/mkiv/util-sql-imp-client.lua +++ b/tex/context/base/mkiv/util-sql-imp-client.lua @@ -109,11 +109,11 @@ local function splitdata(data) -- todo: hash on first line ... maybe move to cli end end p = Cf(Ct("") * p,rawset) * newline^1 -if getserver() == "mssql" then - p = skipfirst * skipdashes * Ct(p^0) -else - p = skipfirst * Ct(p^0) -end + if getserver() == "mssql" then + p = skipfirst * skipdashes * Ct(p^0) + else + p = skipfirst * Ct(p^0) + end cache[first] = { parser = p, keys = keys } local entries = lpegmatch(p,data) return entries or { }, keys @@ -134,6 +134,11 @@ local t_runner = { mssql = [[sqlcmd -S %host% %?U: -U "%username%" ?% %?P: -P "%password%" ?% -I -W -w 65535 -s"]] .. "\t" .. [[" -m 1 -i "%queryfile%" -o "%resultfile%"]], } +local t_runner_login = { + mysql = [[mysql --login-path="%login%" --batch --database="%database%" --default-character-set=utf8 < "%queryfile%" > "%resultfile%"]], + mssql = [[sqlcmd -S %host% %?U: -U "%username%" ?% %?P: -P "%password%" ?% -I -W -w 65535 -s"]] .. "\t" .. [[" -m 1 -i "%queryfile%" -o "%resultfile%"]], +} + local t_preamble = { mysql = [[ SET GLOBAL SQL_MODE=ANSI_QUOTES; @@ -149,7 +154,7 @@ SET NOCOUNT ON; local function dataprepared(specification) local query = preparetemplate(specification) if query then - local preamble = t_preamble[getserver()] or t_preamble.mysql + local preamble = t_preamble[getserver()] or t_preamble.mysql if preamble then preamble = replacetemplate(preamble,specification.variables,'sql') query = preamble .. "\n" .. query @@ -168,7 +173,7 @@ local function dataprepared(specification) end local function datafetched(specification) - local runner = t_runner[getserver()] or t_runner.mysql + local runner = (specification.login and t_runner_login or t_runner)[getserver()] or t_runner.mysql local command = replacetemplate(runner,specification) if trace_sql then local t = osclock() @@ -227,7 +232,7 @@ local function execute(specification) return end if not datafetched(specification) then - report_state("error in fetching, query: %s",string.collapsespaces(io.loaddata(specification.queryfile))) + report_state("error in fetching, query: %s",string.collapsespaces(io.loaddata(specification.queryfile) or "?")) return end local data = dataloaded(specification) |