mysql2-cs-bind 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4407a9571990644923605f3e94e689cfa2f58a2b0ae65751df47fe504c9f87cc
4
- data.tar.gz: 9e7f64a7e17c636b9da92d3a8849468b35519b7bf301bcda722e7664b0f39346
3
+ metadata.gz: d3495f65b800c8cddbb748e628a64ed8fca1d9d33766cd1196ed124c87c2b998
4
+ data.tar.gz: 66d1445f6104b171ec1cb72661f33d75f010a79a557bad875d3d836303d54ed5
5
5
  SHA512:
6
- metadata.gz: 1635039201253b1d8b48251fef0e5acf02ea4ac8e379af39bf417b0f1ab83f1b9f2cfe4d5587006e3c8ca5b8dd817e19978698182778e45865ae620d02f8d7f4
7
- data.tar.gz: 1dfec3139736b9de9d6bb61a76a53fcf72f2909ea16f79c6620d99ad55de045288cc6557cf04c70ecd6e48a662a4cc5154e74dd31e6cd0ab86992ba921619707
6
+ metadata.gz: 210e1bdf190d73617d5e3df68ecae830acf14d7f78a459c8d1cbbbf514ec4245d87713a38dc7358b9e34a1608d819d243dccdf78c5ed2586d2ccbc991aa53731
7
+ data.tar.gz: '058ca605f2586f0e3e23a37797f571386792ea8e44145dc4e301ce2de1009d8a4439fb7d8f2f43624bc90faf1b1ff00470971b8e9cb52966ae907cb05a95d476'
@@ -4,13 +4,8 @@ require 'mysql2'
4
4
 
5
5
  class Mysql2::Client
6
6
 
7
- def xquery(sql, *args)
8
- options = if args.size > 0 and args[-1].is_a?(Hash)
9
- args.pop
10
- else
11
- {}
12
- end
13
- if args.size < 1
7
+ def xquery(sql, *args, **options)
8
+ if args.empty?
14
9
  query(sql, options)
15
10
  else
16
11
  query(Mysql2::Client.pseudo_bind(sql, args), options)
@@ -26,8 +21,11 @@ class Mysql2::Client
26
21
  placeholders.push(pos)
27
22
  search_pos = pos + 1
28
23
  end
29
- values = values.flatten(1) if placeholders.length == values.flatten(1).length
30
- raise ArgumentError, "mismatch between placeholders number and values arguments" if placeholders.length != values.length
24
+
25
+ if placeholders.length != values.length &&
26
+ placeholders.length != (values = values.flatten(1)).length
27
+ raise ArgumentError, "mismatch between placeholders number and values arguments"
28
+ end
31
29
 
32
30
  while pos = placeholders.pop()
33
31
  rawvalue = values.pop()
@@ -43,16 +41,19 @@ class Mysql2::Client
43
41
  private
44
42
 
45
43
  def self.quote(rawvalue)
46
- if rawvalue.nil?
44
+ case rawvalue
45
+ when nil
47
46
  'NULL'
48
- elsif rawvalue == true
47
+ when true
49
48
  'TRUE'
50
- elsif rawvalue == false
49
+ when false
51
50
  'FALSE'
52
- elsif rawvalue.respond_to?(:strftime)
53
- "'#{rawvalue.strftime('%Y-%m-%d %H:%M:%S')}'"
54
51
  else
55
- "'#{Mysql2::Client.escape(rawvalue.to_s)}'"
52
+ if rawvalue.respond_to?(:strftime)
53
+ "'#{rawvalue.strftime('%Y-%m-%d %H:%M:%S')}'"
54
+ else
55
+ "'#{Mysql2::Client.escape(rawvalue.to_s)}'"
56
+ end
56
57
  end
57
58
  end
58
59
  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.1.0"
5
+ gem.version = "0.1.1"
6
6
  gem.authors = ["TAGOMORI Satoshi"]
7
7
  gem.email = ["tagomoris@gmail.com"]
8
8
  gem.homepage = "https://github.com/tagomoris/mysql2-cs-bind"
@@ -19,7 +19,6 @@ Gem::Specification.new do |gem|
19
19
  gem.add_runtime_dependency "mysql2"
20
20
 
21
21
  # tests
22
- gem.add_development_dependency 'eventmachine'
23
22
  gem.add_development_dependency 'rake-compiler', "~> 0.7.7"
24
23
  gem.add_development_dependency 'rake', '0.8.7' # NB: 0.8.7 required by rake-compiler 0.7.9
25
24
  gem.add_development_dependency 'rspec', '2.10.0'
@@ -21,7 +21,7 @@ describe Mysql2::Client do
21
21
  @klass.pseudo_bind("SELECT x,y,z FROM x WHERE x=?", [1]).should eql("SELECT x,y,z FROM x WHERE x='1'")
22
22
  @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'")
23
23
  end
24
-
24
+
25
25
  it "should raise ArgumentError if mismatch exists between placeholders and arguments" do
26
26
  expect {
27
27
  @klass.pseudo_bind("SELECT x,y,z FROM x", [1])
@@ -71,23 +71,16 @@ describe Mysql2::Client do
71
71
  }.to_not raise_exception(Mysql2::Error)
72
72
  end
73
73
 
74
- it "should accept an options hash that inherits from Mysql2::Client.default_query_options" do
75
- @client.xquery "SELECT ?", 1, :something => :else
76
- @client.query_options.should eql(@client.query_options.merge(:something => :else))
77
- end
78
-
79
74
  it "should return results as a hash by default" do
80
75
  @client.xquery("SELECT ?", 1).first.class.should eql(Hash)
81
76
  end
82
77
 
83
78
  it "should be able to return results as an array" do
84
79
  @client.xquery("SELECT ?", 1, :as => :array).first.class.should eql(Array)
85
- @client.xquery("SELECT ?", 1).each(:as => :array)
86
- @client.query("SELECT 1").first.should eql([1])
87
- @client.query("SELECT '1'").first.should eql(['1'])
80
+ @client.xquery("SELECT ?", 1).each(:as => :array).first.class.should eql(Array)
88
81
  @client.xquery("SELECT 1", :as => :array).first.should eql([1])
89
- @client.xquery("SELECT ?", 1).first.should eql(['1'])
90
- @client.xquery("SELECT ?+1", 1).first.should eql([2.0])
82
+ @client.xquery("SELECT ?", 1, :as => :array).first.should eql(['1'])
83
+ @client.xquery("SELECT ?+1", 1, :as => :array).first.should eql([2.0])
91
84
  end
92
85
 
93
86
  it "should read multi style args" do
@@ -127,10 +120,4 @@ describe Mysql2::Client do
127
120
  it "should respond to escape" do
128
121
  Mysql2::Client.should respond_to(:escape)
129
122
  end
130
-
131
- if RUBY_VERSION =~ /1.9/
132
- it "should respond to #encoding" do
133
- @client.should respond_to(:encoding)
134
- end
135
- end
136
123
  end
@@ -34,36 +34,4 @@ describe Mysql2::Error do
34
34
  it "should alias #message to #error" do
35
35
  @error.should respond_to(:error)
36
36
  end
37
-
38
- if RUBY_VERSION =~ /1.9/
39
- it "#message encoding should match the connection's encoding, or Encoding.default_internal if set" do
40
- if Encoding.default_internal.nil?
41
- @error.message.encoding.should eql(@client.encoding)
42
- @error2.message.encoding.should eql(@client2.encoding)
43
- else
44
- @error.message.encoding.should eql(Encoding.default_internal)
45
- @error2.message.encoding.should eql(Encoding.default_internal)
46
- end
47
- end
48
-
49
- it "#error encoding should match the connection's encoding, or Encoding.default_internal if set" do
50
- if Encoding.default_internal.nil?
51
- @error.error.encoding.should eql(@client.encoding)
52
- @error2.error.encoding.should eql(@client2.encoding)
53
- else
54
- @error.error.encoding.should eql(Encoding.default_internal)
55
- @error2.error.encoding.should eql(Encoding.default_internal)
56
- end
57
- end
58
-
59
- it "#sql_state encoding should match the connection's encoding, or Encoding.default_internal if set" do
60
- if Encoding.default_internal.nil?
61
- @error.sql_state.encoding.should eql(@client.encoding)
62
- @error2.sql_state.encoding.should eql(@client2.encoding)
63
- else
64
- @error.sql_state.encoding.should eql(Encoding.default_internal)
65
- @error2.sql_state.encoding.should eql(Encoding.default_internal)
66
- end
67
- end
68
- end
69
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql2-cs-bind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-15 00:00:00.000000000 Z
11
+ date: 2021-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: eventmachine
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake-compiler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -117,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
103
  - !ruby/object:Gem::Version
118
104
  version: '0'
119
105
  requirements: []
120
- rubygems_version: 3.1.2
106
+ rubygems_version: 3.3.0.dev
121
107
  signing_key:
122
108
  specification_version: 4
123
109
  summary: extension for mysql2 to add client-side variable binding