1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
if not modules then modules = { } end modules ['util-sql-tracers'] = {
version = 1.001,
comment = "companion to m-sql.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local sql = utilities.sql
local tracers = { }
sql.tracers = tracers
sql.setmethod("swiglib")
function sql.tracers.gettables(presets)
local results, keys = sql.execute {
presets = presets,
template = "SHOW TABLES FROM `%database%`",
variables = {
database = presets.database,
},
}
local key = keys[1]
local tables = { }
for i=1,#results do
local name = results[i][key]
local results, keys = sql.execute {
presets = presets,
template = "SHOW FIELDS FROM `%database%`.`%table%` ",
variables = {
database = presets.database,
table = name
},
}
if #results > 0 then
for i=1,#results do
results[i] = table.loweredkeys(results[i])
end
tables[name] = results
else
-- a view
end
end
return tables
end
|