mysql2 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ # encoding: UTF-8
2
+ if defined? EventMachine && defined? Fiber
3
+ require 'spec_helper'
4
+ require 'mysql2/em_fiber'
5
+
6
+ describe Mysql2::EM::Fiber::Client do
7
+ it 'should support queries' do
8
+ results = []
9
+ EM.run do
10
+ Fiber.new {
11
+ client1 = Mysql2::EM::Fiber::Client.new
12
+ results = client1.query "SELECT sleep(0.1) as first_query"
13
+ EM.stop_event_loop
14
+ }.resume
15
+ end
16
+
17
+ results.first.keys.should include("first_query")
18
+ end
19
+ end
20
+ else
21
+ puts "Either EventMachine or Fibers not available. Skipping tests that use them."
22
+ end
@@ -85,7 +85,19 @@ describe Mysql2::Client do
85
85
  @client.should respond_to(:query)
86
86
  end
87
87
 
88
+ it "should expect read_timeout to be a positive integer" do
89
+ lambda {
90
+ Mysql2::Client.new(:read_timeout => -1)
91
+ }.should raise_error(Mysql2::Error)
92
+ end
93
+
88
94
  context "#query" do
95
+ it "should only accept strings as the query parameter" do
96
+ lambda {
97
+ @client.query ["SELECT 'not right'"]
98
+ }.should raise_error(TypeError)
99
+ end
100
+
89
101
  it "should accept an options hash that inherits from Mysql2::Client.default_query_options" do
90
102
  @client.query "SELECT 1", :something => :else
91
103
  @client.query_options.should eql(@client.query_options.merge(:something => :else))
@@ -118,6 +130,13 @@ describe Mysql2::Client do
118
130
  }.should raise_error(Mysql2::Error)
119
131
  end
120
132
 
133
+ it "should timeout if we wait longer than :read_timeout" do
134
+ client = Mysql2::Client.new(:read_timeout => 1)
135
+ lambda {
136
+ client.query("SELECT sleep(2)")
137
+ }.should raise_error(Mysql2::Error)
138
+ end
139
+
121
140
  # XXX this test is not deterministic (because Unix signal handling is not)
122
141
  # and may fail on a loaded system
123
142
  if RUBY_PLATFORM !~ /mingw|mswin/
@@ -271,7 +290,7 @@ describe Mysql2::Client do
271
290
 
272
291
  it "should raise a Mysql2::Error exception upon connection failure" do
273
292
  lambda {
274
- bad_client = Mysql2::Client.new :host => "dfjhdi9wrhw", :username => 'asdfasdf8d2h'
293
+ bad_client = Mysql2::Client.new :host => "localhost", :username => 'asdfasdf8d2h', :password => 'asdfasdfw42'
275
294
  }.should raise_error(Mysql2::Error)
276
295
 
277
296
  lambda {
@@ -345,4 +364,28 @@ describe Mysql2::Client do
345
364
  @client.affected_rows.should eql(1)
346
365
  end
347
366
  end
367
+
368
+ it "should respond to #thread_id" do
369
+ @client.should respond_to(:thread_id)
370
+ end
371
+
372
+ it "#thread_id should be a Fixnum" do
373
+ @client.thread_id.class.should eql(Fixnum)
374
+ end
375
+
376
+ it "should respond to #ping" do
377
+ @client.should respond_to(:ping)
378
+ end
379
+
380
+ it "#thread_id should return a boolean" do
381
+ @client.ping.should eql(true)
382
+ @client.close
383
+ @client.ping.should eql(false)
384
+ end
385
+
386
+ if RUBY_VERSION =~ /1.9/
387
+ it "should respond to #encoding" do
388
+ @client.should respond_to(:encoding)
389
+ end
390
+ end
348
391
  end
@@ -3,13 +3,25 @@ require 'spec_helper'
3
3
 
4
4
  describe Mysql2::Error do
5
5
  before(:each) do
6
- @error = Mysql2::Error.new "testing"
6
+ @client = Mysql2::Client.new :encoding => "utf8"
7
+ begin
8
+ @client.query("HAHAHA")
9
+ rescue Mysql2::Error => e
10
+ @error = e
11
+ end
12
+
13
+ @client2 = Mysql2::Client.new :encoding => "big5"
14
+ begin
15
+ @client2.query("HAHAHA")
16
+ rescue Mysql2::Error => e
17
+ @error2 = e
18
+ end
7
19
  end
8
-
20
+
9
21
  it "should respond to #error_number" do
10
22
  @error.should respond_to(:error_number)
11
23
  end
12
-
24
+
13
25
  it "should respond to #sql_state" do
14
26
  @error.should respond_to(:sql_state)
15
27
  end
@@ -22,4 +34,36 @@ describe Mysql2::Error do
22
34
  it "should alias #message to #error" do
23
35
  @error.should respond_to(:error)
24
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
25
69
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  describe Mysql2::Result do
5
5
  before(:each) do
6
- @client = Mysql2::Client.new :host => "localhost", :username => "root"
6
+ @client = Mysql2::Client.new :host => "localhost", :username => "root", :database => 'test'
7
7
  end
8
8
 
9
9
  before(:each) do
@@ -153,8 +153,23 @@ describe Mysql2::Result do
153
153
  @test_result['date_time_test'].strftime("%F %T").should eql('2010-04-04 11:44:00')
154
154
  end
155
155
 
156
- it "should return DateTime for a DATETIME value when outside the supported range" do
157
- r = @client.query("SELECT CAST('1901-1-1 01:01:01' AS DATETIME) as test")
156
+ it "should return DateTime for a DATETIME value when outside the supported range, Time if otherwise" do
157
+ if RUBY_PLATFORM =~ /mswin/
158
+ inside_year = 1970
159
+ outside_year = inside_year-1
160
+ else
161
+ inside_year = 1902
162
+ outside_year = inside_year-1
163
+ end
164
+ r = @client.query("SELECT CAST('#{inside_year}-1-1 01:01:01' AS DATETIME) as test")
165
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
166
+ klass = DateTime
167
+ else
168
+ klass = Time
169
+ end
170
+ r.first['test'].class.should eql(klass)
171
+
172
+ r = @client.query("SELECT CAST('#{outside_year}-1-1 01:01:01' AS DATETIME) as test")
158
173
  r.first['test'].class.should eql(DateTime)
159
174
  end
160
175
 
@@ -1,13 +1,12 @@
1
1
  # encoding: UTF-8
2
2
 
3
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
4
3
  require 'rspec'
5
4
  require 'mysql2'
6
5
  require 'timeout'
7
6
 
8
7
  RSpec.configure do |config|
9
8
  config.before(:all) do
10
- client = Mysql2::Client.new :database => 'test'
9
+ client = Mysql2::Client.new :host => "localhost", :username => "root", :database => 'test'
11
10
  client.query %[
12
11
  CREATE TABLE IF NOT EXISTS mysql2_test (
13
12
  id MEDIUMINT NOT NULL AUTO_INCREMENT,
@@ -1,8 +1,20 @@
1
+ BENCHMARKS = Dir["#{File.dirname(__FILE__)}/../benchmark/*.rb"].map do |path|
2
+ File.basename(path, '.rb')
3
+ end.select { |x| x != 'setup_db' }
4
+
1
5
  namespace :bench do
2
- [ :active_record, :escape, :query_with_mysql_casting,
3
- :query_without_mysql_casting, :sequel, :allocations,
4
- :thread_alone].each do |feature|
6
+ BENCHMARKS.each do |feature|
5
7
  desc "Run #{feature} benchmarks"
6
8
  task(feature){ ruby "benchmark/#{feature}.rb" }
7
9
  end
10
+
11
+ task :all do
12
+ BENCHMARKS.each do |feature|
13
+ ruby "benchmark/#{feature}.rb"
14
+ end
15
+ end
16
+
17
+ task :setup do
18
+ ruby 'benchmark/setup_db'
19
+ end
8
20
  end
@@ -1,4 +1,3 @@
1
- gem 'rake-compiler', '~> 0.7.1'
2
1
  require "rake/extensiontask"
3
2
 
4
3
  MYSQL_VERSION = "5.1.51"
metadata CHANGED
@@ -1,40 +1,121 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mysql2
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 6
10
- version: 0.2.6
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.7
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Brian Lopez
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-10-19 00:00:00 -07:00
12
+ date: 2011-03-28 00:00:00.000000000 -07:00
19
13
  default_executable:
20
- dependencies: []
21
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: eventmachine
17
+ requirement: &2161341260 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *2161341260
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake-compiler
28
+ requirement: &2161340760 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2161340760
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &2161340340 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2161340340
48
+ - !ruby/object:Gem::Dependency
49
+ name: activerecord
50
+ requirement: &2161339880 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2161339880
59
+ - !ruby/object:Gem::Dependency
60
+ name: mysql
61
+ requirement: &2161339460 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2161339460
70
+ - !ruby/object:Gem::Dependency
71
+ name: do_mysql
72
+ requirement: &2161339040 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *2161339040
81
+ - !ruby/object:Gem::Dependency
82
+ name: sequel
83
+ requirement: &2161338620 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *2161338620
92
+ - !ruby/object:Gem::Dependency
93
+ name: faker
94
+ requirement: &2161338200 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *2161338200
22
103
  description:
23
104
  email: seniorlopez@gmail.com
24
105
  executables: []
25
-
26
- extensions:
106
+ extensions:
27
107
  - ext/mysql2/extconf.rb
28
- extra_rdoc_files:
108
+ extra_rdoc_files:
29
109
  - README.rdoc
30
- files:
110
+ files:
31
111
  - .gitignore
32
112
  - .rspec
113
+ - .rvmrc
33
114
  - CHANGELOG.md
115
+ - Gemfile
34
116
  - MIT-LICENSE
35
117
  - README.rdoc
36
118
  - Rakefile
37
- - VERSION
38
119
  - benchmark/active_record.rb
39
120
  - benchmark/allocations.rb
40
121
  - benchmark/escape.rb
@@ -58,9 +139,12 @@ files:
58
139
  - lib/mysql2.rb
59
140
  - lib/mysql2/client.rb
60
141
  - lib/mysql2/em.rb
142
+ - lib/mysql2/em_fiber.rb
61
143
  - lib/mysql2/error.rb
62
144
  - lib/mysql2/result.rb
145
+ - lib/mysql2/version.rb
63
146
  - mysql2.gemspec
147
+ - spec/em/em_fiber_spec.rb
64
148
  - spec/em/em_spec.rb
65
149
  - spec/mysql2/client_spec.rb
66
150
  - spec/mysql2/error_spec.rb
@@ -69,49 +153,42 @@ files:
69
153
  - spec/spec_helper.rb
70
154
  - tasks/benchmarks.rake
71
155
  - tasks/compile.rake
72
- - tasks/jeweler.rake
73
156
  - tasks/rspec.rake
74
157
  - tasks/vendor_mysql.rake
75
158
  has_rdoc: true
76
159
  homepage: http://github.com/brianmario/mysql2
77
160
  licenses: []
78
-
79
161
  post_install_message:
80
- rdoc_options:
162
+ rdoc_options:
81
163
  - --charset=UTF-8
82
- require_paths:
164
+ require_paths:
83
165
  - lib
84
166
  - ext
85
- required_ruby_version: !ruby/object:Gem::Requirement
167
+ required_ruby_version: !ruby/object:Gem::Requirement
86
168
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
94
- required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
174
  none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
101
- - 0
102
- version: "0"
175
+ requirements:
176
+ - - ! '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
103
179
  requirements: []
104
-
105
180
  rubyforge_project:
106
- rubygems_version: 1.3.7
181
+ rubygems_version: 1.6.1
107
182
  signing_key:
108
183
  specification_version: 3
109
184
  summary: A simple, fast Mysql library for Ruby, binding to libmysql
110
- test_files:
185
+ test_files:
186
+ - examples/eventmachine.rb
187
+ - examples/threaded.rb
188
+ - spec/em/em_fiber_spec.rb
111
189
  - spec/em/em_spec.rb
112
190
  - spec/mysql2/client_spec.rb
113
191
  - spec/mysql2/error_spec.rb
114
192
  - spec/mysql2/result_spec.rb
193
+ - spec/rcov.opts
115
194
  - spec/spec_helper.rb
116
- - examples/eventmachine.rb
117
- - examples/threaded.rb