mysql2 0.3.18 → 0.4.2
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 +63 -12
- data/examples/eventmachine.rb +1 -1
- data/examples/threaded.rb +4 -6
- data/ext/mysql2/client.c +170 -175
- data/ext/mysql2/client.h +21 -1
- data/ext/mysql2/extconf.rb +95 -35
- data/ext/mysql2/infile.c +2 -2
- data/ext/mysql2/mysql2_ext.c +1 -0
- data/ext/mysql2/mysql2_ext.h +5 -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 +494 -132
- data/ext/mysql2/result.h +12 -6
- data/ext/mysql2/statement.c +494 -0
- data/ext/mysql2/statement.h +19 -0
- data/lib/mysql2/client.rb +68 -22
- 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/em/em_spec.rb +21 -21
- data/spec/mysql2/client_spec.rb +393 -351
- data/spec/mysql2/error_spec.rb +37 -36
- data/spec/mysql2/result_spec.rb +213 -208
- data/spec/mysql2/statement_spec.rb +684 -0
- data/spec/spec_helper.rb +7 -0
- 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 +41 -46
data/spec/mysql2/error_spec.rb
CHANGED
@@ -2,81 +2,82 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Mysql2::Error do
|
5
|
+
RSpec.describe Mysql2::Error do
|
6
6
|
let(:client) { Mysql2::Client.new(DatabaseCredentials['root']) }
|
7
7
|
|
8
|
-
let
|
8
|
+
let(:error) do
|
9
9
|
begin
|
10
10
|
client.query("HAHAHA")
|
11
11
|
rescue Mysql2::Error => e
|
12
12
|
error = e
|
13
|
-
ensure
|
14
|
-
client.close
|
15
13
|
end
|
16
14
|
|
17
15
|
error
|
18
16
|
end
|
19
17
|
|
20
18
|
it "responds to error_number and sql_state, with aliases" do
|
21
|
-
error.
|
22
|
-
error.
|
19
|
+
expect(error).to respond_to(:error_number)
|
20
|
+
expect(error).to respond_to(:sql_state)
|
23
21
|
|
24
22
|
# Mysql gem compatibility
|
25
|
-
error.
|
26
|
-
error.
|
23
|
+
expect(error).to respond_to(:errno)
|
24
|
+
expect(error).to respond_to(:error)
|
27
25
|
end
|
28
26
|
|
29
|
-
|
30
|
-
let
|
31
|
-
|
27
|
+
context 'encoding' do
|
28
|
+
let(:valid_utf8) { '造字' }
|
29
|
+
let(:error) do
|
32
30
|
begin
|
33
|
-
client.query(
|
31
|
+
client.query(valid_utf8)
|
34
32
|
rescue Mysql2::Error => e
|
35
|
-
|
36
|
-
ensure
|
37
|
-
client.close
|
33
|
+
e
|
38
34
|
end
|
39
|
-
|
40
|
-
error
|
41
35
|
end
|
42
36
|
|
43
|
-
let
|
44
|
-
|
37
|
+
let(:invalid_utf8) { "\xE5\xC6\x7D\x1F" }
|
38
|
+
let(:bad_err) do
|
45
39
|
begin
|
46
|
-
client.query(
|
40
|
+
client.query(invalid_utf8)
|
47
41
|
rescue Mysql2::Error => e
|
48
|
-
|
49
|
-
ensure
|
50
|
-
client.close
|
42
|
+
e
|
51
43
|
end
|
44
|
+
end
|
45
|
+
|
46
|
+
before do
|
47
|
+
pending('String#encoding is not defined') unless String.public_method_defined?(:encoding)
|
48
|
+
|
49
|
+
# sanity check
|
50
|
+
expect(valid_utf8.encoding).to eql(Encoding::UTF_8)
|
51
|
+
expect(valid_utf8).to be_valid_encoding
|
52
52
|
|
53
|
-
|
53
|
+
expect(invalid_utf8.encoding).to eql(Encoding::UTF_8)
|
54
|
+
expect(invalid_utf8).to_not be_valid_encoding
|
54
55
|
end
|
55
56
|
|
56
57
|
it "returns error messages as UTF-8 by default" do
|
57
58
|
with_internal_encoding nil do
|
58
|
-
error.message.encoding.
|
59
|
-
error.message.
|
59
|
+
expect(error.message.encoding).to eql(Encoding::UTF_8)
|
60
|
+
expect(error.message).to be_valid_encoding
|
60
61
|
|
61
|
-
bad_err.message.encoding.
|
62
|
-
bad_err.message.
|
62
|
+
expect(bad_err.message.encoding).to eql(Encoding::UTF_8)
|
63
|
+
expect(bad_err.message).to be_valid_encoding
|
63
64
|
|
64
|
-
bad_err.message.
|
65
|
+
expect(bad_err.message).to include("??}\u001F")
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
69
|
it "returns sql state as ASCII" do
|
69
|
-
error.sql_state.encoding.
|
70
|
-
error.sql_state.
|
70
|
+
expect(error.sql_state.encoding).to eql(Encoding::US_ASCII)
|
71
|
+
expect(error.sql_state).to be_valid_encoding
|
71
72
|
end
|
72
73
|
|
73
74
|
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.
|
75
|
+
with_internal_encoding Encoding::UTF_16LE do
|
76
|
+
expect(error.message.encoding).to eql(Encoding.default_internal)
|
77
|
+
expect(error.message).to be_valid_encoding
|
77
78
|
|
78
|
-
bad_err.message.encoding.
|
79
|
-
bad_err.message.
|
79
|
+
expect(bad_err.message.encoding).to eql(Encoding.default_internal)
|
80
|
+
expect(bad_err.message).to be_valid_encoding
|
80
81
|
end
|
81
82
|
end
|
82
83
|
end
|