mysql2-cs-bind 0.0.2 → 0.0.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.
- data/README.md +6 -1
- data/lib/mysql2-cs-bind.rb +2 -0
- data/mysql2-cs-bind.gemspec +2 -2
- data/spec/mysql2/client_spec.rb +5 -0
- metadata +6 -6
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
|
-
|
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:
|
data/lib/mysql2-cs-bind.rb
CHANGED
@@ -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
|
data/mysql2-cs-bind.gemspec
CHANGED
@@ -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.
|
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
|
data/spec/mysql2/client_spec.rb
CHANGED
@@ -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.
|
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-
|
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:
|
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:
|
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:
|