mysql2 0.2.19b4 → 0.2.19b5

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.
@@ -1,3 +1,3 @@
1
1
  module Mysql2
2
- VERSION = "0.2.19b4"
2
+ VERSION = "0.2.19b5"
3
3
  end
@@ -6,12 +6,30 @@ describe Mysql2::Client do
6
6
  @client = Mysql2::Client.new DatabaseCredentials['root']
7
7
  end
8
8
 
9
+ it "should raise an exception upon connection failure" do
10
+ lambda {
11
+ # The odd local host IP address forces the mysql client library to
12
+ # use a TCP socket rather than a domain socket.
13
+ Mysql2::Client.new DatabaseCredentials['root'].merge('host' => '127.0.0.2', 'port' => 999999)
14
+ }.should raise_error(Mysql2::Error)
15
+ end
16
+
9
17
  if defined? Encoding
10
18
  it "should raise an exception on create for invalid encodings" do
11
19
  lambda {
12
20
  c = Mysql2::Client.new(:encoding => "fake")
13
21
  }.should raise_error(Mysql2::Error)
14
22
  end
23
+
24
+ it "should not raise an exception on create for a valid encoding" do
25
+ lambda {
26
+ c = Mysql2::Client.new(:encoding => "utf8")
27
+ }.should_not raise_error(Mysql2::Error)
28
+
29
+ lambda {
30
+ c = Mysql2::Client.new(:encoding => "big5")
31
+ }.should_not raise_error(Mysql2::Error)
32
+ end
15
33
  end
16
34
 
17
35
  it "should accept connect flags and pass them to #connect" do
@@ -85,6 +103,31 @@ describe Mysql2::Client do
85
103
  @client.should respond_to(:query)
86
104
  end
87
105
 
106
+ it "should respond to #warning_count" do
107
+ @client.should respond_to(:warning_count)
108
+ end
109
+
110
+ context "#warning_count" do
111
+ context "when no warnings" do
112
+ before(:each) do
113
+ @client.query('select 1')
114
+ end
115
+ it "should 0" do
116
+ @client.warning_count.should == 0
117
+ end
118
+ end
119
+ context "when has a warnings" do
120
+ before(:each) do
121
+ # "the statement produces extra information that can be viewed by issuing a SHOW WARNINGS"
122
+ # http://dev.mysql.com/doc/refman/5.0/en/explain-extended.html
123
+ @client.query("explain extended select 1")
124
+ end
125
+ it "should > 0" do
126
+ @client.warning_count.should > 0
127
+ end
128
+ end
129
+ end
130
+
88
131
  it "should expect connect_timeout to be a positive integer" do
89
132
  lambda {
90
133
  Mysql2::Client.new(:connect_timeout => -1)
@@ -126,9 +169,26 @@ describe Mysql2::Client do
126
169
  }.should raise_error(TypeError)
127
170
  end
128
171
 
129
- it "should accept an options hash that inherits from Mysql2::Client.default_query_options" do
130
- @client.query "SELECT 1", :something => :else
131
- @client.query_options.should eql(@client.query_options.merge(:something => :else))
172
+ it "should not retain query options set on a query for subsequent queries, but should retain it in the result" do
173
+ result = @client.query "SELECT 1", :something => :else
174
+ @client.query_options[:something].should be_nil
175
+ result.instance_variable_get('@query_options').should eql(@client.query_options.merge(:something => :else))
176
+ @client.instance_variable_get('@current_query_options').should eql(@client.query_options.merge(:something => :else))
177
+
178
+ result = @client.query "SELECT 1"
179
+ result.instance_variable_get('@query_options').should eql(@client.query_options)
180
+ @client.instance_variable_get('@current_query_options').should eql(@client.query_options)
181
+ end
182
+
183
+ it "should allow changing query options for subsequent queries" do
184
+ @client.query_options.merge!(:something => :else)
185
+ result = @client.query "SELECT 1"
186
+ @client.query_options[:something].should eql(:else)
187
+ result.instance_variable_get('@query_options')[:something].should eql(:else)
188
+
189
+ # Clean up after this test
190
+ @client.query_options.delete(:something)
191
+ @client.query_options[:something].should be_nil
132
192
  end
133
193
 
134
194
  it "should return results as a hash by default" do
@@ -245,15 +305,47 @@ describe Mysql2::Client do
245
305
  }.should_not raise_error(Mysql2::Error)
246
306
  end
247
307
 
308
+ it "should handle Timeouts without leaving the connection hanging if reconnect is set to true after construction true" do
309
+ client = Mysql2::Client.new(DatabaseCredentials['root'])
310
+ begin
311
+ Timeout.timeout(1) do
312
+ client.query("SELECT sleep(2)")
313
+ end
314
+ rescue Timeout::Error
315
+ end
316
+
317
+ lambda {
318
+ client.query("SELECT 1")
319
+ }.should raise_error(Mysql2::Error)
320
+
321
+ client.reconnect = true
322
+
323
+ begin
324
+ Timeout.timeout(1) do
325
+ client.query("SELECT sleep(2)")
326
+ end
327
+ rescue Timeout::Error
328
+ end
329
+
330
+ lambda {
331
+ client.query("SELECT 1")
332
+ }.should_not raise_error(Mysql2::Error)
333
+
334
+ end
335
+
248
336
  it "threaded queries should be supported" do
249
337
  threads, results = [], {}
338
+ lock = Mutex.new
250
339
  connect = lambda{
251
340
  Mysql2::Client.new(DatabaseCredentials['root'])
252
341
  }
253
342
  Timeout.timeout(0.7) do
254
343
  5.times {
255
344
  threads << Thread.new do
256
- results[Thread.current.object_id] = connect.call.query("SELECT sleep(0.5) as result")
345
+ result = connect.call.query("SELECT sleep(0.5) as result")
346
+ lock.synchronize do
347
+ results[Thread.current.object_id] = result
348
+ end
257
349
  end
258
350
  }
259
351
  end
@@ -281,14 +373,6 @@ describe Mysql2::Client do
281
373
  result = @client.async_result
282
374
  result.class.should eql(Mysql2::Result)
283
375
  end
284
-
285
- it "should not allow options to be set on an open connection" do
286
- lambda {
287
- @client.escape ""
288
- @client.query("SELECT 1")
289
- @client.options(0, 0)
290
- }.should raise_error(Mysql2::Error)
291
- end
292
376
  end
293
377
 
294
378
  context "Multiple results sets" do
@@ -313,6 +397,31 @@ describe Mysql2::Client do
313
397
 
314
398
  @multi_client.query( "select 3 as 'next'").first.should == { 'next' => 3 }
315
399
  end
400
+
401
+ it "will raise on query if there are outstanding results to read" do
402
+ @multi_client.query("SELECT 1; SELECT 2; SELECT 3")
403
+ lambda {
404
+ @multi_client.query("SELECT 4")
405
+ }.should raise_error(Mysql2::Error)
406
+ end
407
+
408
+ it "#abandon_results! should work" do
409
+ @multi_client.query("SELECT 1; SELECT 2; SELECT 3")
410
+ @multi_client.abandon_results!
411
+ lambda {
412
+ @multi_client.query("SELECT 4")
413
+ }.should_not raise_error(Mysql2::Error)
414
+ end
415
+
416
+ it "#more_results? should work" do
417
+ @multi_client.query( "select 1 as 'set_1'; select 2 as 'set_2'")
418
+ @multi_client.more_results?.should == true
419
+
420
+ @multi_client.next_result
421
+ @multi_client.store_result
422
+
423
+ @multi_client.more_results?.should == false
424
+ end
316
425
  end
317
426
  end
318
427
 
@@ -354,7 +463,7 @@ describe Mysql2::Client do
354
463
  }.should_not raise_error(SystemStackError)
355
464
  end
356
465
 
357
- if RUBY_VERSION =~ /1.9/
466
+ unless RUBY_VERSION =~ /1.8/
358
467
  it "should carry over the original string's encoding" do
359
468
  str = "abc'def\"ghi\0jkl%mno"
360
469
  escaped = Mysql2::Client.escape(str)
@@ -571,7 +680,7 @@ describe Mysql2::Client do
571
680
  @client.ping.should eql(false)
572
681
  end
573
682
 
574
- if RUBY_VERSION =~ /1.9/
683
+ unless RUBY_VERSION =~ /1.8/
575
684
  it "should respond to #encoding" do
576
685
  @client.should respond_to(:encoding)
577
686
  end
@@ -35,7 +35,7 @@ describe Mysql2::Error do
35
35
  @error.should respond_to(:error)
36
36
  end
37
37
 
38
- if RUBY_VERSION =~ /1.9/
38
+ unless RUBY_VERSION =~ /1.8/
39
39
  it "#message encoding should match the connection's encoding, or Encoding.default_internal if set" do
40
40
  if Encoding.default_internal.nil?
41
41
  @error.message.encoding.should eql(@client.encoding)
@@ -234,7 +234,7 @@ describe Mysql2::Result do
234
234
  end
235
235
 
236
236
  if 1.size == 4 # 32bit
237
- if RUBY_VERSION =~ /1.9/
237
+ unless RUBY_VERSION =~ /1.8/
238
238
  klass = Time
239
239
  else
240
240
  klass = DateTime
@@ -252,7 +252,7 @@ describe Mysql2::Result do
252
252
  r.first['test'].class.should eql(klass)
253
253
  end
254
254
  elsif 1.size == 8 # 64bit
255
- if RUBY_VERSION =~ /1.9/
255
+ unless RUBY_VERSION =~ /1.8/
256
256
  it "should return Time when timestamp is < 1901-12-13 20:45:52" do
257
257
  r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
258
258
  r.first['test'].class.should eql(Time)
@@ -0,0 +1,82 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'mysql2'
3
+
4
+ user, pass, host, port = ENV.values_at('user', 'pass', 'host', 'port')
5
+
6
+ mysql_to_rb = {
7
+ "big5" => "Big5",
8
+ "dec8" => "NULL",
9
+ "cp850" => "CP850",
10
+ "hp8" => "NULL",
11
+ "koi8r" => "KOI8-R",
12
+ "latin1" => "ISO-8859-1",
13
+ "latin2" => "ISO-8859-2",
14
+ "swe7" => "NULL",
15
+ "ascii" => "US-ASCII",
16
+ "ujis" => "eucJP-ms",
17
+ "sjis" => "Shift_JIS",
18
+ "hebrew" => "ISO-8859-8",
19
+ "tis620" => "TIS-620",
20
+ "euckr" => "EUC-KR",
21
+ "koi8u" => "KOI8-R",
22
+ "gb2312" => "GB2312",
23
+ "greek" => "ISO-8859-7",
24
+ "cp1250" => "Windows-1250",
25
+ "gbk" => "GBK",
26
+ "latin5" => "ISO-8859-9",
27
+ "armscii8" => "NULL",
28
+ "utf8" => "UTF-8",
29
+ "ucs2" => "UTF-16BE",
30
+ "cp866" => "IBM866",
31
+ "keybcs2" => "NULL",
32
+ "macce" => "macCentEuro",
33
+ "macroman" => "macRoman",
34
+ "cp852" => "CP852",
35
+ "latin7" => "ISO-8859-13",
36
+ "utf8mb4" => "UTF-8",
37
+ "cp1251" => "Windows-1251",
38
+ "utf16" => "UTF-16",
39
+ "cp1256" => "Windows-1256",
40
+ "cp1257" => "Windows-1257",
41
+ "utf32" => "UTF-32",
42
+ "binary" => "ASCII-8BIT",
43
+ "geostd8" => "NULL",
44
+ "cp932" => "Windows-31J",
45
+ "eucjpms" => "eucJP-ms"
46
+ }
47
+
48
+ client = Mysql2::Client.new(:username => user, :password => pass, :host => host, :port => port.to_i)
49
+ collations = client.query "SHOW COLLATION", :as => :array
50
+ encodings = Array.new(collations.to_a.last[2].to_i)
51
+ encodings_with_nil = Array.new(encodings.size)
52
+
53
+ collations.each do |collation|
54
+ mysql_col_idx = collation[2].to_i
55
+ rb_enc = mysql_to_rb[collation[1]]
56
+ encodings[mysql_col_idx-1] = [mysql_col_idx, rb_enc]
57
+ end
58
+
59
+ encodings.each_with_index do |encoding, idx|
60
+ encodings_with_nil[idx] = (encoding || [idx, "NULL"])
61
+ end
62
+
63
+ encodings_with_nil.sort! do |a, b|
64
+ a[0] <=> b[0]
65
+ end
66
+
67
+ encodings_with_nil = encodings_with_nil.map do |encoding|
68
+ name = "NULL"
69
+
70
+ if !encoding.nil? && encoding[1] != "NULL"
71
+ name = "\"#{encoding[1]}\""
72
+ end
73
+
74
+ " #{name}"
75
+ end
76
+
77
+ # start printing output
78
+
79
+ puts "const char *mysql2_mysql_enc_to_rb[] = {"
80
+ puts encodings_with_nil.join(",\n")
81
+ puts "};"
82
+ puts
@@ -0,0 +1,61 @@
1
+ mysql_to_rb = {
2
+ "big5" => "Big5",
3
+ "dec8" => nil,
4
+ "cp850" => "CP850",
5
+ "hp8" => nil,
6
+ "koi8r" => "KOI8-R",
7
+ "latin1" => "ISO-8859-1",
8
+ "latin2" => "ISO-8859-2",
9
+ "swe7" => nil,
10
+ "ascii" => "US-ASCII",
11
+ "ujis" => "eucJP-ms",
12
+ "sjis" => "Shift_JIS",
13
+ "hebrew" => "ISO-8859-8",
14
+ "tis620" => "TIS-620",
15
+ "euckr" => "EUC-KR",
16
+ "koi8u" => "KOI8-R",
17
+ "gb2312" => "GB2312",
18
+ "greek" => "ISO-8859-7",
19
+ "cp1250" => "Windows-1250",
20
+ "gbk" => "GBK",
21
+ "latin5" => "ISO-8859-9",
22
+ "armscii8" => nil,
23
+ "utf8" => "UTF-8",
24
+ "ucs2" => "UTF-16BE",
25
+ "cp866" => "IBM866",
26
+ "keybcs2" => nil,
27
+ "macce" => "macCentEuro",
28
+ "macroman" => "macRoman",
29
+ "cp852" => "CP852",
30
+ "latin7" => "ISO-8859-13",
31
+ "utf8mb4" => "UTF-8",
32
+ "cp1251" => "Windows-1251",
33
+ "utf16" => "UTF-16",
34
+ "cp1256" => "Windows-1256",
35
+ "cp1257" => "Windows-1257",
36
+ "utf32" => "UTF-32",
37
+ "binary" => "ASCII-8BIT",
38
+ "geostd8" => nil,
39
+ "cp932" => "Windows-31J",
40
+ "eucjpms" => "eucJP-ms"
41
+ }
42
+
43
+ puts <<-header
44
+ %readonly-tables
45
+ %enum
46
+ %define lookup-function-name mysql2_mysql_enc_name_to_rb
47
+ %define hash-function-name mysql2_mysql_enc_name_to_rb_hash
48
+ %struct-type
49
+ struct mysql2_mysql_enc_name_to_rb_map { const char *name; const char *rb_name; }
50
+ %%
51
+ header
52
+
53
+ mysql_to_rb.each do |mysql, ruby|
54
+ if ruby.nil?
55
+ name = "NULL"
56
+ else
57
+ name = "\"#{ruby}\""
58
+ end
59
+
60
+ puts "#{mysql}, #{name}"
61
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.19b4
4
+ version: 0.2.19b5
5
5
  prerelease: 6
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-08-22 00:00:00.000000000 Z
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.7.7
37
+ version: 0.8.1
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,119 +42,39 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.7.7
45
+ version: 0.8.1
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rake
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - '='
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 0.8.7
53
+ version: 0.9.3
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - '='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.7
61
+ version: 0.9.3
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rspec
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: activerecord
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: mysql
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: do_mysql
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: sequel
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ! '>='
132
- - !ruby/object:Gem::Version
133
- version: '0'
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
142
- - !ruby/object:Gem::Dependency
143
- name: faker
144
- requirement: !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ! '>='
67
+ - - ~>
148
68
  - !ruby/object:Gem::Version
149
- version: '0'
69
+ version: 2.8.0
150
70
  type: :development
151
71
  prerelease: false
152
72
  version_requirements: !ruby/object:Gem::Requirement
153
73
  none: false
154
74
  requirements:
155
- - - ! '>='
75
+ - - ~>
156
76
  - !ruby/object:Gem::Version
157
- version: '0'
77
+ version: 2.8.0
158
78
  description:
159
79
  email: seniorlopez@gmail.com
160
80
  executables: []
@@ -162,33 +82,16 @@ extensions:
162
82
  - ext/mysql2/extconf.rb
163
83
  extra_rdoc_files: []
164
84
  files:
165
- - .gitignore
166
- - .rbenv-version
167
- - .rspec
168
- - .rvmrc
169
- - .travis.yml
170
85
  - CHANGELOG.md
171
- - Gemfile
172
- - Gemfile.lock
173
86
  - MIT-LICENSE
174
87
  - README.md
175
- - Rakefile
176
- - benchmark/active_record.rb
177
- - benchmark/active_record_threaded.rb
178
- - benchmark/allocations.rb
179
- - benchmark/escape.rb
180
- - benchmark/query_with_mysql_casting.rb
181
- - benchmark/query_without_mysql_casting.rb
182
- - benchmark/sequel.rb
183
- - benchmark/setup_db.rb
184
- - benchmark/threaded.rb
185
- - examples/eventmachine.rb
186
- - examples/threaded.rb
187
88
  - ext/mysql2/client.c
188
89
  - ext/mysql2/client.h
189
90
  - ext/mysql2/extconf.rb
190
91
  - ext/mysql2/mysql2_ext.c
191
92
  - ext/mysql2/mysql2_ext.h
93
+ - ext/mysql2/mysql_enc_name_to_ruby.h
94
+ - ext/mysql2/mysql_enc_to_ruby.h
192
95
  - ext/mysql2/result.c
193
96
  - ext/mysql2/result.h
194
97
  - ext/mysql2/wait_for_single_fd.h
@@ -203,7 +106,10 @@ files:
203
106
  - lib/mysql2/error.rb
204
107
  - lib/mysql2/result.rb
205
108
  - lib/mysql2/version.rb
206
- - mysql2.gemspec
109
+ - support/mysql_enc_to_ruby.rb
110
+ - support/ruby_enc_to_mysql.rb
111
+ - examples/eventmachine.rb
112
+ - examples/threaded.rb
207
113
  - spec/configuration.yml.example
208
114
  - spec/em/em_fiber_spec.rb
209
115
  - spec/em/em_spec.rb
@@ -212,10 +118,6 @@ files:
212
118
  - spec/mysql2/result_spec.rb
213
119
  - spec/rcov.opts
214
120
  - spec/spec_helper.rb
215
- - tasks/benchmarks.rake
216
- - tasks/compile.rake
217
- - tasks/rspec.rake
218
- - tasks/vendor_mysql.rake
219
121
  homepage: http://github.com/brianmario/mysql2
220
122
  licenses: []
221
123
  post_install_message:
@@ -252,3 +154,4 @@ test_files:
252
154
  - spec/mysql2/result_spec.rb
253
155
  - spec/rcov.opts
254
156
  - spec/spec_helper.rb
157
+ has_rdoc: