mysql2-cs-bind 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  Require 'mysql2-cs-bind' instead of (or after) 'mysql2', you can use Mysql2::Client#xquery with bound variables like below:
22
22
 
23
- use 'mysql2-cs-bind'
23
+ require 'mysql2-cs-bind'
24
24
  client = Mysql2::Client.new(...)
25
25
  client.xquery('SELECT x,y,z FROM tbl WHERE x=? AND y=?', val1, val2) #=> Mysql2::Result
26
26
 
@@ -44,6 +44,11 @@ Formatting for nil and Time objects:
44
44
  client.xquery('INSERT INTO tbl (val1,created_at) VALUES (?,?)', nil, Time.now)
45
45
  #execute "INSERT INTO tbl (val1,created_at) VALUES (NULL,'2012-01-02 13:45:01')"
46
46
 
47
+ Expanding for Array object.
48
+
49
+ client.xquery('SELECT val1 FROM tbl WHERE id IN (?)', [[1,2,3]])
50
+ #execute "SELECT val1 FROM tbl WHERE id IN ('1','2','3')"
51
+
47
52
  ### Type Conversion of Numbers
48
53
 
49
54
  Mysql2::Client#xquery quotes any values as STRING. This may not be problems for almost all kind of queries, but sometimes you may be confused by return value types:
@@ -32,6 +32,8 @@ class Mysql2::Client
32
32
  sql[pos] = 'NULL'
33
33
  elsif rawvalue.is_a?(Time)
34
34
  sql[pos] = "'" + rawvalue.strftime('%Y-%m-%d %H:%M:%S') + "'"
35
+ elsif rawvalue.is_a?(Array)
36
+ sql[pos] = rawvalue.map{|v| "'" + Mysql2::Client.escape(v.to_s) + "'" }.join(",")
35
37
  else
36
38
  sql[pos] = "'" + Mysql2::Client.escape(rawvalue.to_s) + "'"
37
39
  end
@@ -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.2"
5
+ gem.version = "0.0.3"
6
6
  gem.authors = ["TAGOMORI Satoshi"]
7
7
  gem.email = ["tagomoris@gmail.com"]
8
8
  gem.homepage = "https://github.com/tagomoris/mysql2-cs-bind"
@@ -21,5 +21,5 @@ Gem::Specification.new do |gem|
21
21
  gem.add_development_dependency 'eventmachine'
22
22
  gem.add_development_dependency 'rake-compiler', "~> 0.7.7"
23
23
  gem.add_development_dependency 'rake', '0.8.7' # NB: 0.8.7 required by rake-compiler 0.7.9
24
- gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'rspec', '2.10.0'
25
25
  end
@@ -45,6 +45,11 @@ describe Mysql2::Client do
45
45
  t = Time.strptime('2012/04/20 16:50:45', '%Y/%m/%d %H:%M:%S')
46
46
  @klass.pseudo_bind("UPDATE x SET y=? WHERE x=?", [t,1]).should eql("UPDATE x SET y='2012-04-20 16:50:45' WHERE x='1'")
47
47
  end
48
+
49
+ it "should replace placeholder with value list about Array object" do
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
+ @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
+ end
48
53
  end
49
54
 
50
55
  context "#xquery" do
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.2
4
+ version: 0.0.3
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-04-20 00:00:00.000000000 Z
12
+ date: 2012-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mysql2
@@ -96,17 +96,17 @@ dependencies:
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - ! '>='
99
+ - - '='
100
100
  - !ruby/object:Gem::Version
101
- version: '0'
101
+ version: 2.10.0
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - ! '>='
107
+ - - '='
108
108
  - !ruby/object:Gem::Version
109
- version: '0'
109
+ version: 2.10.0
110
110
  description: extension for mysql2 to add client-side variable binding, by adding method
111
111
  Mysql2::Client#xquery
112
112
  email: