mysql2 0.3.20 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1 -0
- data/README.md +183 -72
- data/ext/mysql2/client.c +432 -183
- data/ext/mysql2/client.h +10 -38
- data/ext/mysql2/extconf.rb +126 -56
- data/ext/mysql2/infile.c +2 -2
- data/ext/mysql2/mysql2_ext.c +3 -1
- data/ext/mysql2/mysql2_ext.h +13 -14
- data/ext/mysql2/mysql_enc_name_to_ruby.h +62 -58
- data/ext/mysql2/mysql_enc_to_ruby.h +82 -18
- data/ext/mysql2/result.c +505 -164
- data/ext/mysql2/result.h +11 -4
- data/ext/mysql2/statement.c +604 -0
- data/ext/mysql2/statement.h +17 -0
- data/ext/mysql2/wait_for_single_fd.h +2 -1
- data/lib/mysql2/client.rb +89 -28
- data/lib/mysql2/console.rb +1 -1
- data/lib/mysql2/em.rb +6 -9
- data/lib/mysql2/error.rb +55 -35
- data/lib/mysql2/field.rb +3 -0
- data/lib/mysql2/result.rb +2 -0
- data/lib/mysql2/statement.rb +11 -0
- data/lib/mysql2/version.rb +1 -1
- data/lib/mysql2.rb +46 -24
- data/support/5072E1F5.asc +432 -0
- data/support/mysql_enc_to_ruby.rb +15 -11
- data/support/ruby_enc_to_mysql.rb +8 -6
- metadata +22 -77
- data/examples/eventmachine.rb +0 -21
- data/examples/threaded.rb +0 -20
- data/spec/configuration.yml.example +0 -17
- data/spec/em/em_spec.rb +0 -135
- data/spec/my.cnf.example +0 -9
- data/spec/mysql2/client_spec.rb +0 -921
- data/spec/mysql2/error_spec.rb +0 -83
- data/spec/mysql2/result_spec.rb +0 -514
- data/spec/rcov.opts +0 -3
- data/spec/spec_helper.rb +0 -87
- data/spec/test_data +0 -1
data/examples/eventmachine.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift 'lib'
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'eventmachine'
|
7
|
-
require 'mysql2/em'
|
8
|
-
|
9
|
-
EM.run do
|
10
|
-
client1 = Mysql2::EM::Client.new
|
11
|
-
defer1 = client1.query "SELECT sleep(3) as first_query"
|
12
|
-
defer1.callback do |result|
|
13
|
-
puts "Result: #{result.to_a.inspect}"
|
14
|
-
end
|
15
|
-
|
16
|
-
client2 = Mysql2::EM::Client.new
|
17
|
-
defer2 = client2.query "SELECT sleep(1) second_query"
|
18
|
-
defer2.callback do |result|
|
19
|
-
puts "Result: #{result.to_a.inspect}"
|
20
|
-
end
|
21
|
-
end
|
data/examples/threaded.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift 'lib'
|
4
|
-
require 'mysql2'
|
5
|
-
require 'timeout'
|
6
|
-
|
7
|
-
threads = []
|
8
|
-
# Should never exceed worst case 3.5 secs across all 20 threads
|
9
|
-
Timeout.timeout(3.5) do
|
10
|
-
20.times do
|
11
|
-
threads << Thread.new do
|
12
|
-
overhead = rand(3)
|
13
|
-
puts ">> thread #{Thread.current.object_id} query, #{overhead} sec overhead"
|
14
|
-
# 3 second overhead per query
|
15
|
-
Mysql2::Client.new(:host => "localhost", :username => "root").query("SELECT sleep(#{overhead}) as result")
|
16
|
-
puts "<< thread #{Thread.current.object_id} result, #{overhead} sec overhead"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
threads.each{|t| t.join }
|
20
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
root:
|
2
|
-
host: localhost
|
3
|
-
username: root
|
4
|
-
password:
|
5
|
-
database: test
|
6
|
-
|
7
|
-
user:
|
8
|
-
host: localhost
|
9
|
-
username: LOCALUSERNAME
|
10
|
-
password:
|
11
|
-
database: mysql2_test
|
12
|
-
|
13
|
-
numericuser:
|
14
|
-
host: localhost
|
15
|
-
username: LOCALUSERNAME
|
16
|
-
password:
|
17
|
-
database: 12345
|
data/spec/em/em_spec.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
begin
|
4
|
-
require 'eventmachine'
|
5
|
-
require 'mysql2/em'
|
6
|
-
|
7
|
-
describe Mysql2::EM::Client do
|
8
|
-
it "should support async queries" do
|
9
|
-
results = []
|
10
|
-
EM.run do
|
11
|
-
client1 = Mysql2::EM::Client.new DatabaseCredentials['root']
|
12
|
-
defer1 = client1.query "SELECT sleep(0.1) as first_query"
|
13
|
-
defer1.callback do |result|
|
14
|
-
results << result.first
|
15
|
-
client1.close
|
16
|
-
EM.stop_event_loop
|
17
|
-
end
|
18
|
-
|
19
|
-
client2 = Mysql2::EM::Client.new DatabaseCredentials['root']
|
20
|
-
defer2 = client2.query "SELECT sleep(0.025) second_query"
|
21
|
-
defer2.callback do |result|
|
22
|
-
results << result.first
|
23
|
-
client2.close
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
results[0].keys.should include("second_query")
|
28
|
-
results[1].keys.should include("first_query")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should support queries in callbacks" do
|
32
|
-
results = []
|
33
|
-
EM.run do
|
34
|
-
client = Mysql2::EM::Client.new DatabaseCredentials['root']
|
35
|
-
defer1 = client.query "SELECT sleep(0.025) as first_query"
|
36
|
-
defer1.callback do |result|
|
37
|
-
results << result.first
|
38
|
-
defer2 = client.query "SELECT sleep(0.025) as second_query"
|
39
|
-
defer2.callback do |r|
|
40
|
-
results << r.first
|
41
|
-
client.close
|
42
|
-
EM.stop_event_loop
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
results[0].keys.should include("first_query")
|
48
|
-
results[1].keys.should include("second_query")
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should not swallow exceptions raised in callbacks" do
|
52
|
-
lambda {
|
53
|
-
EM.run do
|
54
|
-
client = Mysql2::EM::Client.new DatabaseCredentials['root']
|
55
|
-
defer = client.query "SELECT sleep(0.1) as first_query"
|
56
|
-
defer.callback do |result|
|
57
|
-
client.close
|
58
|
-
raise 'some error'
|
59
|
-
end
|
60
|
-
defer.errback do |err|
|
61
|
-
# This _shouldn't_ be run, but it needed to prevent the specs from
|
62
|
-
# freezing if this test fails.
|
63
|
-
EM.stop_event_loop
|
64
|
-
end
|
65
|
-
end
|
66
|
-
}.should raise_error
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'when an exception is raised by the client' do
|
70
|
-
let(:client) { Mysql2::EM::Client.new DatabaseCredentials['root'] }
|
71
|
-
let(:error) { StandardError.new('some error') }
|
72
|
-
before { client.stub(:async_result).and_raise(error) }
|
73
|
-
|
74
|
-
it "should swallow exceptions raised in by the client" do
|
75
|
-
errors = []
|
76
|
-
EM.run do
|
77
|
-
defer = client.query "SELECT sleep(0.1) as first_query"
|
78
|
-
defer.callback do |result|
|
79
|
-
# This _shouldn't_ be run, but it is needed to prevent the specs from
|
80
|
-
# freezing if this test fails.
|
81
|
-
EM.stop_event_loop
|
82
|
-
end
|
83
|
-
defer.errback do |err|
|
84
|
-
errors << err
|
85
|
-
EM.stop_event_loop
|
86
|
-
end
|
87
|
-
end
|
88
|
-
errors.should == [error]
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should fail the deferrable" do
|
92
|
-
callbacks_run = []
|
93
|
-
EM.run do
|
94
|
-
defer = client.query "SELECT sleep(0.025) as first_query"
|
95
|
-
EM.add_timer(0.1) do
|
96
|
-
defer.callback do |result|
|
97
|
-
callbacks_run << :callback
|
98
|
-
# This _shouldn't_ be run, but it is needed to prevent the specs from
|
99
|
-
# freezing if this test fails.
|
100
|
-
EM.stop_event_loop
|
101
|
-
end
|
102
|
-
defer.errback do |err|
|
103
|
-
callbacks_run << :errback
|
104
|
-
EM.stop_event_loop
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
callbacks_run.should == [:errback]
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should not raise error when closing client with no query running" do
|
113
|
-
callbacks_run = []
|
114
|
-
EM.run do
|
115
|
-
client = Mysql2::EM::Client.new DatabaseCredentials['root']
|
116
|
-
defer = client.query("select sleep(0.025)")
|
117
|
-
defer.callback do |result|
|
118
|
-
callbacks_run << :callback
|
119
|
-
end
|
120
|
-
defer.errback do |err|
|
121
|
-
callbacks_run << :errback
|
122
|
-
end
|
123
|
-
EM.add_timer(0.1) do
|
124
|
-
callbacks_run.should == [:callback]
|
125
|
-
lambda {
|
126
|
-
client.close
|
127
|
-
}.should_not raise_error(/invalid binding to detach/)
|
128
|
-
EM.stop_event_loop
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
rescue LoadError
|
134
|
-
puts "EventMachine not installed, skipping the specs that use it"
|
135
|
-
end
|