mysql2-cs-bind 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +2 -2
- data/lib/mysql2-cs-bind.rb +2 -3
- data/mysql2-cs-bind.gemspec +1 -1
- data/spec/mysql2/client_spec.rb +10 -9
- metadata +1 -1
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2012- TAGOMORI Satoshi - http://github.com/tagomoris
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/mysql2-cs-bind.rb
CHANGED
@@ -11,12 +11,11 @@ class Mysql2::Client
|
|
11
11
|
if args.size < 1
|
12
12
|
query(sql, options)
|
13
13
|
else
|
14
|
-
query(pseudo_bind(sql, args.flatten), options)
|
14
|
+
query(Mysql2::Client.pseudo_bind(sql, args.flatten), options)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
def pseudo_bind(sql, values)
|
18
|
+
def self.pseudo_bind(sql, values)
|
20
19
|
sql = sql.dup
|
21
20
|
|
22
21
|
placeholders = []
|
data/mysql2-cs-bind.gemspec
CHANGED
data/spec/mysql2/client_spec.rb
CHANGED
@@ -4,6 +4,7 @@ require 'spec_helper'
|
|
4
4
|
describe Mysql2::Client do
|
5
5
|
before(:each) do
|
6
6
|
@client = Mysql2::Client.new
|
7
|
+
@klass = Mysql2::Client
|
7
8
|
end
|
8
9
|
|
9
10
|
it "should respond to #query" do
|
@@ -12,37 +13,37 @@ describe Mysql2::Client do
|
|
12
13
|
|
13
14
|
context "#pseudo_bind" do
|
14
15
|
it "should return query just same as argument, if without any placeholders" do
|
15
|
-
@
|
16
|
+
@klass.pseudo_bind("SELECT x,y,z FROM x WHERE x='1'", []).should eql("SELECT x,y,z FROM x WHERE x='1'")
|
16
17
|
end
|
17
18
|
|
18
19
|
it "should return replaced query if with placeholders" do
|
19
|
-
@
|
20
|
-
@
|
20
|
+
@klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=?", [1]).should eql("SELECT x,y,z FROM x WHERE x='1'")
|
21
|
+
@klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=? AND y=?", [1, 'X']).should eql("SELECT x,y,z FROM x WHERE x='1' AND y='X'")
|
21
22
|
end
|
22
23
|
|
23
24
|
it "should raise ArgumentError if mismatch exists between placeholders and arguments" do
|
24
25
|
expect {
|
25
|
-
@
|
26
|
+
@klass.pseudo_bind("SELECT x,y,z FROM x", [1])
|
26
27
|
}.should raise_exception(ArgumentError)
|
27
28
|
expect {
|
28
|
-
@
|
29
|
+
@klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=?", [1,2])
|
29
30
|
}.should raise_exception(ArgumentError)
|
30
31
|
expect {
|
31
|
-
@
|
32
|
+
@klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=? AND y=?", [1])
|
32
33
|
}.should raise_exception(ArgumentError)
|
33
34
|
expect {
|
34
|
-
@
|
35
|
+
@klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=?", [])
|
35
36
|
}.should raise_exception(ArgumentError)
|
36
37
|
end
|
37
38
|
|
38
39
|
it "should replace placeholder with NULL about nil" do
|
39
|
-
@
|
40
|
+
@klass.pseudo_bind("UPDATE x SET y=? WHERE x=?", [nil,1]).should eql("UPDATE x SET y=NULL WHERE x='1'")
|
40
41
|
end
|
41
42
|
|
42
43
|
it "should replace placeholder with formatted timestamp string about Time object" do
|
43
44
|
require 'time'
|
44
45
|
t = Time.strptime('2012/04/20 16:50:45', '%Y/%m/%d %H:%M:%S')
|
45
|
-
@
|
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'")
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|