diff options
author | Karl Berry <karl@freefriends.org> | 2017-04-19 23:04:15 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-04-19 23:04:15 +0000 |
commit | f74161ca4e7eb3c5af9afcbe92522ae3b58987c1 (patch) | |
tree | 3c30a13df5ac7968195c85070a2b074578e669d2 /Master/texmf-dist/tex/context/base/mkiv/util-sql-imp-client.lua | |
parent | 1d5a55ac8f5506a7ae9cfca52f4b588182e199d4 (diff) |
context beta/cont-tmf.zip (Apr 16 12:55)
git-svn-id: svn://tug.org/texlive/trunk@43931 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/util-sql-imp-client.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/util-sql-imp-client.lua | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/util-sql-imp-client.lua b/Master/texmf-dist/tex/context/base/mkiv/util-sql-imp-client.lua index 9a0fbc29983..a2763feac4c 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/util-sql-imp-client.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/util-sql-imp-client.lua @@ -1,4 +1,4 @@ -if not modules then modules = { } end modules ['util-sql-client'] = { +if not modules then modules = { } end modules ['util-sql-imp-client'] = { version = 1.001, comment = "companion to util-sql.lua", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", @@ -26,6 +26,8 @@ local serialize = sql.serialize local deserialize = sql.deserialize local getserver = sql.getserver +local osclock = os.gettimeofday + -- Experiments with an p/action demonstrated that there is not much gain. We could do a runtime -- capture but creating all the small tables is not faster and it doesn't work well anyway. @@ -107,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 @@ -132,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; @@ -144,10 +151,10 @@ SET NOCOUNT ON; ]], } -local function dataprepared(specification,client) +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 @@ -165,14 +172,16 @@ local function dataprepared(specification,client) end end -local function datafetched(specification,client) - local runner = t_runner[getserver()] or t_runner.mysql +local function datafetched(specification) + 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() report_state("command: %s",command) + -- for now we don't use sandbox.registerrunners as this module is + -- also used outside context local okay = os.execute(command) - report_state("fetchtime: %.3f sec",osclock()-t) -- not okay under linux + report_state("fetchtime: %.3f sec, return code: %i",osclock()-t,okay) -- not okay under linux return okay == 0 else return os.execute(command) == 0 @@ -220,12 +229,12 @@ local function execute(specification) report_state("error in specification") return end - if not dataprepared(specification,methods.client) then + if not dataprepared(specification) then report_state("error in preparation") return end - if not datafetched(specification,methods.client) then - report_state("error in fetching, query: %s",string.collapsespaces(io.loaddata(specification.queryfile))) + if not datafetched(specification) then + report_state("error in fetching, query: %s",string.collapsespaces(io.loaddata(specification.queryfile) or "?")) return end local data = dataloaded(specification) |