File: test_sql.lua

package info (click to toggle)
lua-orbit 2.2.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,956 kB
  • sloc: javascript: 2,216; sql: 78; sh: 32; makefile: 31; xml: 20
file content (47 lines) | stat: -rw-r--r-- 2,036 bytes parent folder | download | duplicates (5)
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

local model = require "orbit.model" 

local function build_query(sql, values)
  return model.condition_parser:match(sql, 1, function (field, op)
						return field .. op .. values[field]
					      end)
end

local queries = {
  { 
    from = [[node_term.term = term.id and term.vocabulary = vocabulary.id and term.name = ? and 
             vocabulary.name = ?]],
    to = [[node_term.term = term.id and term.vocabulary = vocabulary.id and term.name = visibility and vocabulary.name = home]],
    values = { ["vocabulary.name"] = "home", ["term.name"] = "visibility" }
  },
  { 
    from = [[node_term.term = term.id and term.vocabulary = vocabulary.id and term.name = ? and 
             vocabulary.name = ? and term.display_name is not null]],
    to = [[node_term.term = term.id and term.vocabulary = vocabulary.id and term.name = visibility and vocabulary.name = home and term.display_name is not null]],
    values = { ["vocabulary.name"] = "home", ["term.name"] = "visibility" }
  },
  {
    from = [[node in ?]],
    to = [[node in foo]],
    values = { node = "foo" }
  },
  { 
    from = [[node_term.term!=term and term.vocabulary = vocabulary.id and term.name = ? and 
             vocabulary.name = ? and term.display_name is not null]],
    to = [[node_term.term!=term and term.vocabulary = vocabulary.id and term.name = visibility and vocabulary.name = home and term.display_name is not null]],
    values = { ["vocabulary.name"] = "home", ["term.name"] = "visibility" }
  },
  { 
    from = [[node_term.term!=term and term.vocabulary = vocabulary.id and term.name =? and 
             vocabulary.name = ? and term.display_name is not null]],
    to = [[node_term.term!=term and term.vocabulary = vocabulary.id and term.name =visibility and vocabulary.name = home and term.display_name is not null]],
    values = { ["vocabulary.name"] = "home", ["term.name"] = "visibility" }
  },
}

for _, q in ipairs(queries) do
  if not (build_query(q.from, q.values) == q.to) then
    print(build_query(q.from, q.values))
  end
end