mysql2 0.3.18 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/LICENSE +21 -0
- data/README.md +132 -55
- data/examples/eventmachine.rb +1 -1
- data/examples/threaded.rb +4 -6
- data/ext/mysql2/client.c +374 -197
- data/ext/mysql2/client.h +13 -3
- data/ext/mysql2/extconf.rb +119 -35
- data/ext/mysql2/infile.c +2 -2
- data/ext/mysql2/mysql2_ext.c +1 -0
- data/ext/mysql2/mysql2_ext.h +7 -6
- data/ext/mysql2/mysql_enc_name_to_ruby.h +2 -2
- data/ext/mysql2/mysql_enc_to_ruby.h +25 -22
- data/ext/mysql2/result.c +512 -138
- data/ext/mysql2/result.h +13 -6
- data/ext/mysql2/statement.c +595 -0
- data/ext/mysql2/statement.h +19 -0
- data/lib/mysql2/client.rb +85 -26
- data/lib/mysql2/console.rb +1 -1
- data/lib/mysql2/em.rb +5 -6
- data/lib/mysql2/error.rb +18 -27
- data/lib/mysql2/field.rb +3 -0
- data/lib/mysql2/statement.rb +17 -0
- data/lib/mysql2/version.rb +1 -1
- data/lib/mysql2.rb +38 -18
- data/spec/configuration.yml.example +0 -6
- data/spec/em/em_spec.rb +22 -21
- data/spec/mysql2/client_spec.rb +530 -388
- data/spec/mysql2/error_spec.rb +38 -39
- data/spec/mysql2/result_spec.rb +223 -214
- data/spec/mysql2/statement_spec.rb +763 -0
- data/spec/spec_helper.rb +80 -59
- data/spec/ssl/ca-cert.pem +17 -0
- data/spec/ssl/ca-key.pem +27 -0
- data/spec/ssl/ca.cnf +22 -0
- data/spec/ssl/cert.cnf +22 -0
- data/spec/ssl/client-cert.pem +17 -0
- data/spec/ssl/client-key.pem +27 -0
- data/spec/ssl/client-req.pem +15 -0
- data/spec/ssl/gen_certs.sh +48 -0
- data/spec/ssl/pkcs8-client-key.pem +28 -0
- data/spec/ssl/pkcs8-server-key.pem +28 -0
- data/spec/ssl/server-cert.pem +17 -0
- data/spec/ssl/server-key.pem +27 -0
- data/spec/ssl/server-req.pem +15 -0
- data/support/mysql_enc_to_ruby.rb +7 -8
- data/support/ruby_enc_to_mysql.rb +1 -1
- metadata +42 -47
data/spec/mysql2/error_spec.rb
CHANGED
@@ -2,81 +2,80 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Mysql2::Error do
|
6
|
-
let(:
|
7
|
-
|
8
|
-
let :error do
|
5
|
+
RSpec.describe Mysql2::Error do
|
6
|
+
let(:error) do
|
9
7
|
begin
|
10
|
-
client.query("HAHAHA")
|
8
|
+
@client.query("HAHAHA")
|
11
9
|
rescue Mysql2::Error => e
|
12
10
|
error = e
|
13
|
-
ensure
|
14
|
-
client.close
|
15
11
|
end
|
16
12
|
|
17
13
|
error
|
18
14
|
end
|
19
15
|
|
20
16
|
it "responds to error_number and sql_state, with aliases" do
|
21
|
-
error.
|
22
|
-
error.
|
17
|
+
expect(error).to respond_to(:error_number)
|
18
|
+
expect(error).to respond_to(:sql_state)
|
23
19
|
|
24
20
|
# Mysql gem compatibility
|
25
|
-
error.
|
26
|
-
error.
|
21
|
+
expect(error).to respond_to(:errno)
|
22
|
+
expect(error).to respond_to(:error)
|
27
23
|
end
|
28
24
|
|
29
|
-
|
30
|
-
let
|
31
|
-
|
25
|
+
context 'encoding' do
|
26
|
+
let(:valid_utf8) { '造字' }
|
27
|
+
let(:error) do
|
32
28
|
begin
|
33
|
-
client.query(
|
29
|
+
@client.query(valid_utf8)
|
34
30
|
rescue Mysql2::Error => e
|
35
|
-
|
36
|
-
ensure
|
37
|
-
client.close
|
31
|
+
e
|
38
32
|
end
|
39
|
-
|
40
|
-
error
|
41
33
|
end
|
42
34
|
|
43
|
-
let
|
44
|
-
|
35
|
+
let(:invalid_utf8) { ["e5c67d1f"].pack('H*').force_encoding(Encoding::UTF_8) }
|
36
|
+
let(:bad_err) do
|
45
37
|
begin
|
46
|
-
client.query(
|
38
|
+
@client.query(invalid_utf8)
|
47
39
|
rescue Mysql2::Error => e
|
48
|
-
|
49
|
-
ensure
|
50
|
-
client.close
|
40
|
+
e
|
51
41
|
end
|
42
|
+
end
|
43
|
+
|
44
|
+
before do
|
45
|
+
pending('String#encoding is not defined') unless String.public_method_defined?(:encoding)
|
46
|
+
|
47
|
+
# sanity check
|
48
|
+
expect(valid_utf8.encoding).to eql(Encoding::UTF_8)
|
49
|
+
expect(valid_utf8).to be_valid_encoding
|
52
50
|
|
53
|
-
|
51
|
+
expect(invalid_utf8.encoding).to eql(Encoding::UTF_8)
|
52
|
+
expect(invalid_utf8).to_not be_valid_encoding
|
54
53
|
end
|
55
54
|
|
56
55
|
it "returns error messages as UTF-8 by default" do
|
57
56
|
with_internal_encoding nil do
|
58
|
-
error.message.encoding.
|
59
|
-
error.message.
|
57
|
+
expect(error.message.encoding).to eql(Encoding::UTF_8)
|
58
|
+
expect(error.message).to be_valid_encoding
|
60
59
|
|
61
|
-
bad_err.message.encoding.
|
62
|
-
bad_err.message.
|
60
|
+
expect(bad_err.message.encoding).to eql(Encoding::UTF_8)
|
61
|
+
expect(bad_err.message).to be_valid_encoding
|
63
62
|
|
64
|
-
bad_err.message.
|
63
|
+
expect(bad_err.message).to include("??}\u001F")
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
68
67
|
it "returns sql state as ASCII" do
|
69
|
-
error.sql_state.encoding.
|
70
|
-
error.sql_state.
|
68
|
+
expect(error.sql_state.encoding).to eql(Encoding::US_ASCII)
|
69
|
+
expect(error.sql_state).to be_valid_encoding
|
71
70
|
end
|
72
71
|
|
73
72
|
it "returns error messages and sql state in Encoding.default_internal if set" do
|
74
|
-
with_internal_encoding
|
75
|
-
error.message.encoding.
|
76
|
-
error.message.
|
73
|
+
with_internal_encoding Encoding::UTF_16LE do
|
74
|
+
expect(error.message.encoding).to eql(Encoding.default_internal)
|
75
|
+
expect(error.message).to be_valid_encoding
|
77
76
|
|
78
|
-
bad_err.message.encoding.
|
79
|
-
bad_err.message.
|
77
|
+
expect(bad_err.message.encoding).to eql(Encoding.default_internal)
|
78
|
+
expect(bad_err.message).to be_valid_encoding
|
80
79
|
end
|
81
80
|
end
|
82
81
|
end
|