sql_helper 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -221,7 +221,7 @@ module SQLHelper
221
221
  end
222
222
  when Hash
223
223
  cond.each do |col, cnd|
224
- ret = eval_hash_cond col, cnd, prepared
224
+ ret = eval_cond col, cnd, prepared
225
225
  sqls << ret[0]
226
226
  params += ret[1..-1] || []
227
227
  end
@@ -238,7 +238,7 @@ module SQLHelper
238
238
  end
239
239
  end
240
240
 
241
- def eval_hash_cond col, cnd, prepared
241
+ def eval_cond col, cnd, prepared
242
242
  case cnd
243
243
  when Numeric, String
244
244
  prepared ? ["#{col} = ?", cnd] : [[col, quote(cnd)].join(' = ')]
@@ -256,7 +256,7 @@ module SQLHelper
256
256
  sqls = []
257
257
  params = []
258
258
  cnd.each do |v|
259
- ret = eval_hash_cond col, v, prepared
259
+ ret = eval_cond col, v, prepared
260
260
  sqls << ret[0]
261
261
  params += ret[1..-1]
262
262
  end
@@ -277,15 +277,20 @@ module SQLHelper
277
277
  ["#{col} <> ?", val] :
278
278
  ["#{col} <> #{quote val}"]
279
279
  else
280
- ary = eval_hash_cond col, val, prepared
281
- ary[0].prepend 'not '
280
+ ary = eval_cond col, val, prepared
281
+ ary[0] =
282
+ if ary[0] =~ /^\(.*\)$/
283
+ "not #{ary[0]}"
284
+ else
285
+ "not (#{ary[0]})"
286
+ end
282
287
  ary
283
288
  end
284
289
  when :or
285
290
  sqls = []
286
291
  params = []
287
292
  val.each do |v|
288
- ret = eval_hash_cond col, v, prepared
293
+ ret = eval_cond col, v, prepared
289
294
  sqls << ret[0]
290
295
  params += ret[1..-1]
291
296
  end
@@ -1,3 +1,3 @@
1
1
  module SQLHelper
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -30,7 +30,9 @@ class TestSQLHelper < MiniTest::Unit::TestCase
30
30
  :r => { :or => [{ :like => ['ABC%', 'DEF%'] }, { :not => { :like => 'XYZ%' } }] },
31
31
  :s => { :not => 100 },
32
32
  :t => { :not => 'str' },
33
- :u => ('aa'..'zz')
33
+ :u => ('aa'..'zz'),
34
+ :v => { :not => { :gt => 100, :lt => 200 } },
35
+ :w => { :not => { :sql => 'sysdate' } }
34
36
  },
35
37
  [],
36
38
  [nil],
@@ -39,7 +41,7 @@ class TestSQLHelper < MiniTest::Unit::TestCase
39
41
  ' '
40
42
  ]
41
43
 
42
- @wherep = ["where (z <> 100) and (y = ? or y = ? or y = ? or z = 'xxx') and a = ? and b between ? and ? and c >= ? and c < ? and (d = ? or d = ?) and e = sysdate and f is not null and g > ? and h < ? and i like ? and not j like ? and k <= sysdate and l >= ? and l <= ? and not (m = ? or m >= ? and m <= ?) and n is null and not o between ? and ? and (p > ? or p < ?) and (q like ? or q like ?) and ((r like ? or r like ?) or not r like ?) and s <> ? and t <> ? and u between ? and ?",
44
+ @wherep = ["where (z <> 100) and (y = ? or y = ? or y = ? or z = 'xxx') and a = ? and b between ? and ? and c >= ? and c < ? and (d = ? or d = ?) and e = sysdate and f is not null and g > ? and h < ? and i like ? and not (j like ?) and k <= sysdate and l >= ? and l <= ? and not (m = ? or m >= ? and m <= ?) and n is null and not (o between ? and ?) and (p > ? or p < ?) and (q like ? or q like ?) and ((r like ? or r like ?) or not (r like ?)) and s <> ? and t <> ? and u between ? and ? and not (v > ? and v < ?) and not (w = sysdate)",
43
45
  200, "Macy's???", BigDecimal("3.141592"),
44
46
  "hello 'world'???",
45
47
  1, 10,
@@ -57,7 +59,8 @@ class TestSQLHelper < MiniTest::Unit::TestCase
57
59
  'ABC%', 'DEF%', 'XYZ%',
58
60
  100,
59
61
  'str',
60
- 'aa', 'zz'
62
+ 'aa', 'zz',
63
+ 100, 200
61
64
  ]
62
65
 
63
66
  params = @wherep[1..-1]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-16 00:00:00.000000000 Z
12
+ date: 2013-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  segments:
92
92
  - 0
93
- hash: 1991983397644293356
93
+ hash: 1884977039615962457
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  segments:
101
101
  - 0
102
- hash: 1991983397644293356
102
+ hash: 1884977039615962457
103
103
  requirements: []
104
104
  rubyforge_project:
105
105
  rubygems_version: 1.8.25