mysql2-cs-bind 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ class Mysql2::Client
11
11
  if args.size < 1
12
12
  query(sql, options)
13
13
  else
14
- query(Mysql2::Client.pseudo_bind(sql, args.flatten), options)
14
+ query(Mysql2::Client.pseudo_bind(sql, args), options)
15
15
  end
16
16
  end
17
17
 
@@ -24,6 +24,7 @@ class Mysql2::Client
24
24
  placeholders.push(pos)
25
25
  search_pos = pos + 1
26
26
  end
27
+ values = values.flatten(1) if placeholders.length == values.flatten(1).length
27
28
  raise ArgumentError, "mismatch between placeholders number and values arguments" if placeholders.length != values.length
28
29
 
29
30
  while pos = placeholders.pop()
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "mysql2-cs-bind"
5
- gem.version = "0.0.3"
5
+ gem.version = "0.0.4"
6
6
  gem.authors = ["TAGOMORI Satoshi"]
7
7
  gem.email = ["tagomoris@gmail.com"]
8
8
  gem.homepage = "https://github.com/tagomoris/mysql2-cs-bind"
@@ -49,6 +49,8 @@ describe Mysql2::Client do
49
49
  it "should replace placeholder with value list about Array object" do
50
50
  @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x in (?)", [[1,2,3]]).should eql("SELECT x,y,z FROM x WHERE x in ('1','2','3')")
51
51
  @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x = ? and y in (?)", [1, [1, 2, 3]]).should eql("SELECT x,y,z FROM x WHERE x = '1' and y in ('1','2','3')")
52
+ @klass.pseudo_bind("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id = ? OR id in (?)", [1, [2,3]]).should eql("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id = '1' OR id in ('2','3')")
53
+ @klass.pseudo_bind("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id in (?) OR id = ?", [[1,2], 3]).should eql("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id in ('1','2') OR id = '3'")
52
54
  end
53
55
  end
54
56
 
@@ -80,6 +82,28 @@ describe Mysql2::Client do
80
82
  @client.xquery("SELECT ?+1", 1).first.should eql([2.0])
81
83
  end
82
84
 
85
+ it "should read multi style args" do
86
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id IN (1)").first["id"].should eql(1)
87
+
88
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id = ?", 1).first["id"].should eql(1)
89
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id = ? OR id = ?", 1, 2).first["id"].should eql(1)
90
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id = ? OR id = ?", [1,2]).first["id"].should eql(1)
91
+
92
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id in (?)", [1,2,3]).first["id"].should eql(1)
93
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id = ? OR id in (?)", 1, [2,3]).first["id"].should eql(1)
94
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id = ? OR id in (?)", [1, [2,3]]).first["id"].should eql(1)
95
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id in (?) OR id = ?", [1,2], 3).first["id"].should eql(1)
96
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id in (?) OR id = ?", [[1,2], 3]).first["id"].should eql(1)
97
+
98
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id IN (1)",:something => :else).first["id"].should eql(1)
99
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id = ? OR id in (?)", 1, [2,3],:something => :else).first["id"].should eql(1)
100
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id in (?) OR id = ?", [[1,2], 3],:something => :else).first["id"].should eql(1)
101
+
102
+ expect {
103
+ @client.xquery("SELECT id FROM (SELECT 1 AS id) AS tbl WHERE id in (?) OR id = ?", [[1,2], 3, 4],:something => :else)
104
+ }.should raise_exception(ArgumentError)
105
+ end
106
+
83
107
  it "should be able to return results with symbolized keys" do
84
108
  @client.xquery("SELECT 1", :symbolize_keys => true).first.keys[0].class.should eql(Symbol)
85
109
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql2-cs-bind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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: 2012-07-17 00:00:00.000000000 Z
12
+ date: 2012-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mysql2