mysql2-cs-bind 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 55ec5a580710a7b43264267b1dbeafaa09960f42637b2342603cd8940fc02792
4
+ data.tar.gz: 8019c547da9eaaf11f89bda94ca2adc6a824d3238cee4cb315d7b940c2b55581
5
+ SHA512:
6
+ metadata.gz: e18f71240d20a93a48154950b53e1ba3035f744545972d46eb6833435c3a52f5360e3449f39b01a21ae610fb03482f73ec0e601c1b2b0489c3d9c664a0e71351
7
+ data.tar.gz: 13df7872ed377ef38ba22a7a51473e44fe1b3db4cbd6d5ba0976e66a14d51b56311e5f5ec5251fa67079c3762684f3f2c24a8a14f9ddb7e5475ab7241c561920
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # mysql-cs-bind
1
+ # mysql2-cs-bind
2
2
 
3
- 'mysql-cs-bind' is extension of 'mysql2', to add method of client-side variable binding (pseudo prepared statement).
3
+ 'mysql2-cs-bind' is extension of 'mysql2', to add method of client-side variable binding (pseudo prepared statement).
4
4
 
5
5
  ## Installation
6
6
 
@@ -29,17 +29,28 @@ class Mysql2::Client
29
29
 
30
30
  while pos = placeholders.pop()
31
31
  rawvalue = values.pop()
32
- if rawvalue.nil?
33
- sql[pos] = 'NULL'
34
- elsif rawvalue.respond_to?(:strftime)
35
- sql[pos] = "'" + rawvalue.strftime('%Y-%m-%d %H:%M:%S') + "'"
36
- elsif rawvalue.is_a?(Array)
37
- sql[pos] = rawvalue.map{|v| "'" + Mysql2::Client.escape(v.to_s) + "'" }.join(",")
32
+ if rawvalue.is_a?(Array)
33
+ sql[pos] = rawvalue.map{|v| quote(v) }.join(",")
38
34
  else
39
- sql[pos] = "'" + Mysql2::Client.escape(rawvalue.to_s) + "'"
35
+ sql[pos] = quote(rawvalue)
40
36
  end
41
37
  end
42
38
  sql
43
39
  end
44
40
 
41
+ private
42
+
43
+ def self.quote(rawvalue)
44
+ if rawvalue.nil?
45
+ 'NULL'
46
+ elsif rawvalue == true
47
+ 'TRUE'
48
+ elsif rawvalue == false
49
+ 'FALSE'
50
+ elsif rawvalue.respond_to?(:strftime)
51
+ "'" + rawvalue.strftime('%Y-%m-%d %H:%M:%S') + "'"
52
+ else
53
+ "'" + Mysql2::Client.escape(rawvalue.to_s) + "'"
54
+ end
55
+ end
45
56
  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.6"
5
+ gem.version = "0.0.7"
6
6
  gem.authors = ["TAGOMORI Satoshi"]
7
7
  gem.email = ["tagomoris@gmail.com"]
8
8
  gem.homepage = "https://github.com/tagomoris/mysql2-cs-bind"
@@ -1,5 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  require 'spec_helper'
3
+ require 'time'
3
4
 
4
5
  describe Mysql2::Client do
5
6
  before(:each) do
@@ -41,16 +42,23 @@ describe Mysql2::Client do
41
42
  end
42
43
 
43
44
  it "should replace placeholder with formatted timestamp string about Time object" do
44
- require 'time'
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
48
 
49
+ it "should replace placeholder with TRUE/FALSE about true/false" do
50
+ @klass.pseudo_bind("UPDATE x SET y=? WHERE x=?", [true,1]).should eql("UPDATE x SET y=TRUE WHERE x='1'")
51
+ @klass.pseudo_bind("UPDATE x SET y=? WHERE x=?", [false,1]).should eql("UPDATE x SET y=FALSE WHERE x='1'")
52
+ end
53
+
49
54
  it "should replace placeholder with value list about Array object" do
55
+ t = Time.strptime('2012/04/20 16:50:45', '%Y/%m/%d %H:%M:%S')
50
56
  @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
57
  @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
58
  @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
59
  @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'")
60
+ @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x = ? and y in (?)", [1, [true, nil]]).should eql("SELECT x,y,z FROM x WHERE x = '1' and y in (TRUE,NULL)")
61
+ @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x = ? and y in (?)", [1, [t, nil]]).should eql("SELECT x,y,z FROM x WHERE x = '1' and y in ('2012-04-20 16:50:45',NULL)")
54
62
  end
55
63
  end
56
64
 
metadata CHANGED
@@ -1,68 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql2-cs-bind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
5
- prerelease:
4
+ version: 0.0.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - TAGOMORI Satoshi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-08 00:00:00.000000000 Z
11
+ date: 2018-09-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mysql2
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: eventmachine
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake-compiler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: 0.7.7
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: 0.7.7
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - '='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - '='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - '='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - '='
92
81
  - !ruby/object:Gem::Version
@@ -99,7 +88,7 @@ executables: []
99
88
  extensions: []
100
89
  extra_rdoc_files: []
101
90
  files:
102
- - .gitignore
91
+ - ".gitignore"
103
92
  - Gemfile
104
93
  - MIT-LICENSE
105
94
  - README.md
@@ -112,27 +101,26 @@ files:
112
101
  - spec/spec_helper.rb
113
102
  homepage: https://github.com/tagomoris/mysql2-cs-bind
114
103
  licenses: []
104
+ metadata: {}
115
105
  post_install_message:
116
106
  rdoc_options: []
117
107
  require_paths:
118
108
  - lib
119
109
  required_ruby_version: !ruby/object:Gem::Requirement
120
- none: false
121
110
  requirements:
122
- - - ! '>='
111
+ - - ">="
123
112
  - !ruby/object:Gem::Version
124
113
  version: '0'
125
114
  required_rubygems_version: !ruby/object:Gem::Requirement
126
- none: false
127
115
  requirements:
128
- - - ! '>='
116
+ - - ">="
129
117
  - !ruby/object:Gem::Version
130
118
  version: '0'
131
119
  requirements: []
132
120
  rubyforge_project:
133
- rubygems_version: 1.8.23
121
+ rubygems_version: 2.7.6
134
122
  signing_key:
135
- specification_version: 3
123
+ specification_version: 4
136
124
  summary: extension for mysql2 to add client-side variable binding
137
125
  test_files:
138
126
  - spec/mysql2/client_spec.rb