querybuilder 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,6 +69,10 @@ module QueryBuilder
69
69
  str_buf = ""
70
70
  }
71
71
 
72
+ action in_op {
73
+ last = apply_op(stack, :in)
74
+ }
75
+
72
76
  action is {
73
77
  # We need the 'is' operator to avoid confusion with 'in site'.
74
78
  last = apply_op(stack, :is)
@@ -23,8 +23,10 @@
23
23
  operator = (op %operator | text_op %operator ws+ );
24
24
  interval = ws+ ('second'|'minute'|'hour'|'day'|'week'|'month'|'year') $str_a %interval 's'?;
25
25
  value = ((field | string | number | rubyless) interval? | ws* '(' >goto_expr_p ws* ')');
26
+ in_value = (string | number | rubyless) (ws* ',' (string | number | rubyless))*;
27
+ in_expr = ws+ ('not' $str_a %operator ws+)? 'in' ws* '(' %in_op in_value ws* ')'; # wait until '(' to execute 'operator' to avoid confusion with scope
26
28
  is_null = ws+ 'is' %is ws+ (('not' ws+)* ('null' | 'NULL')) $str_a %raw;
27
- expr = value (operator value | is_null)*;
29
+ expr = value (operator value | in_expr | is_null)*;
28
30
  expr_p := expr ws* ')' $expr_close;
29
31
 
30
32
  relation = ws* var %relation;
data/querybuilder.gemspec CHANGED
@@ -5,17 +5,18 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{querybuilder}
8
- s.version = "0.8.2"
8
+ s.version = "0.8.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gaspard Bucher"]
12
- s.date = %q{2010-08-30}
12
+ s.date = %q{2010-08-31}
13
13
  s.description = %q{QueryBuilder is an interpreter for the "pseudo sql" language. This language
14
14
  can be used for two purposes:
15
15
 
16
16
  1. protect your database from illegal SQL by securing queries
17
17
  2. ease writing complex relational queries by abstracting table internals}
18
18
  s.email = %q{gaspard@teti.ch}
19
+ s.extensions = ["lib/extconf.rb"]
19
20
  s.extra_rdoc_files = [
20
21
  "README.rdoc"
21
22
  ]
@@ -121,3 +121,21 @@ filter_empty_literal:
121
121
  src: "objects where \"\" = ''"
122
122
  sxp: '[:query, [:filter, [:relation, "objects"], [:"=", [:dstring, ""], [:string, ""]]]]'
123
123
  sql: "SELECT objects.* FROM objects WHERE '' = '' AND objects.parent_id = 123"
124
+
125
+ filter_in_literal:
126
+ src: "objects where id in (1, 2 , 3,4) in site"
127
+ sxp: '[:query, [:scope, [:filter, [:relation, "objects"], [:in, [:field, "id"], [:integer, "1"], [:integer, "2"], [:integer, "3"], [:integer, "4"]]], "site"]]'
128
+ sql: "SELECT objects.* FROM objects WHERE objects.id IN (1,2,3,4)"
129
+
130
+ filter_in_string:
131
+ src: "objects where name in ('paul', 'john') in site"
132
+ sql: "SELECT objects.* FROM objects WHERE objects.name IN ('paul','john')"
133
+
134
+ filter_in_single_literal:
135
+ src: "objects where id in (1) in site"
136
+ sql: "SELECT objects.* FROM objects WHERE objects.id IN (1)"
137
+
138
+ filter_not_in_literal:
139
+ src: "objects where id not in (1, 2 , 3,4) in site"
140
+ sxp: '[:query, [:scope, [:filter, [:relation, "objects"], [:not, [:in, [:field, "id"], [:integer, "1"], [:integer, "2"], [:integer, "3"], [:integer, "4"]]]], "site"]]'
141
+ sql: "SELECT objects.* FROM objects WHERE objects.id NOT IN (1,2,3,4)"
@@ -12,4 +12,13 @@ eval:
12
12
 
13
13
  date_function:
14
14
  src: 'objects where name = #{params[:name]}.year'
15
- res: "/objects.name = strftime\('%Y',\?\)/"
15
+ res: "/objects.name = strftime\('%Y',\?\)/"
16
+
17
+ filter_in_rubyless:
18
+ src: "objects where id in (#{params[:d]}) in site"
19
+ sxp: '[:query, [:scope, [:filter, [:relation, "objects"], [:in, [:field, "id"], [:rubyless, "params[:d]"]]], "site"]]'
20
+ res: "[%Q{SELECT objects.* FROM objects WHERE objects.id IN (?)}, get_params[:d]]"
21
+
22
+ filter_in_mixed:
23
+ src: 'objects where name in ("hello", #{params[:p]})'
24
+ res: "[%Q{SELECT objects.* FROM objects WHERE objects.name IN ('hello',?) AND objects.parent_id = ?}, get_params[:p], id]"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 2
9
- version: 0.8.2
8
+ - 3
9
+ version: 0.8.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Gaspard Bucher
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-30 00:00:00 +02:00
17
+ date: 2010-08-31 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -66,8 +66,8 @@ description: |-
66
66
  email: gaspard@teti.ch
67
67
  executables: []
68
68
 
69
- extensions: []
70
-
69
+ extensions:
70
+ - lib/extconf.rb
71
71
  extra_rdoc_files:
72
72
  - README.rdoc
73
73
  files: