mysql2 0.3.18 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/LICENSE +21 -0
  4. data/README.md +63 -12
  5. data/examples/eventmachine.rb +1 -1
  6. data/examples/threaded.rb +4 -6
  7. data/ext/mysql2/client.c +170 -175
  8. data/ext/mysql2/client.h +21 -1
  9. data/ext/mysql2/extconf.rb +95 -35
  10. data/ext/mysql2/infile.c +2 -2
  11. data/ext/mysql2/mysql2_ext.c +1 -0
  12. data/ext/mysql2/mysql2_ext.h +5 -6
  13. data/ext/mysql2/mysql_enc_name_to_ruby.h +2 -2
  14. data/ext/mysql2/mysql_enc_to_ruby.h +25 -22
  15. data/ext/mysql2/result.c +494 -132
  16. data/ext/mysql2/result.h +12 -6
  17. data/ext/mysql2/statement.c +494 -0
  18. data/ext/mysql2/statement.h +19 -0
  19. data/lib/mysql2/client.rb +68 -22
  20. data/lib/mysql2/console.rb +1 -1
  21. data/lib/mysql2/em.rb +5 -6
  22. data/lib/mysql2/error.rb +18 -27
  23. data/lib/mysql2/field.rb +3 -0
  24. data/lib/mysql2/statement.rb +17 -0
  25. data/lib/mysql2/version.rb +1 -1
  26. data/lib/mysql2.rb +38 -18
  27. data/spec/em/em_spec.rb +21 -21
  28. data/spec/mysql2/client_spec.rb +393 -351
  29. data/spec/mysql2/error_spec.rb +37 -36
  30. data/spec/mysql2/result_spec.rb +213 -208
  31. data/spec/mysql2/statement_spec.rb +684 -0
  32. data/spec/spec_helper.rb +7 -0
  33. data/spec/ssl/ca-cert.pem +17 -0
  34. data/spec/ssl/ca-key.pem +27 -0
  35. data/spec/ssl/ca.cnf +22 -0
  36. data/spec/ssl/cert.cnf +22 -0
  37. data/spec/ssl/client-cert.pem +17 -0
  38. data/spec/ssl/client-key.pem +27 -0
  39. data/spec/ssl/client-req.pem +15 -0
  40. data/spec/ssl/gen_certs.sh +48 -0
  41. data/spec/ssl/pkcs8-client-key.pem +28 -0
  42. data/spec/ssl/pkcs8-server-key.pem +28 -0
  43. data/spec/ssl/server-cert.pem +17 -0
  44. data/spec/ssl/server-key.pem +27 -0
  45. data/spec/ssl/server-req.pem +15 -0
  46. data/support/mysql_enc_to_ruby.rb +7 -8
  47. data/support/ruby_enc_to_mysql.rb +1 -1
  48. metadata +41 -46
@@ -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 :error do
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.should respond_to(:error_number)
22
- error.should respond_to(:sql_state)
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.should respond_to(:errno)
26
- error.should respond_to(:error)
23
+ expect(error).to respond_to(:errno)
24
+ expect(error).to respond_to(:error)
27
25
  end
28
26
 
29
- if "".respond_to? :encoding
30
- let :error do
31
- client = Mysql2::Client.new(DatabaseCredentials['root'])
27
+ context 'encoding' do
28
+ let(:valid_utf8) { '造字' }
29
+ let(:error) do
32
30
  begin
33
- client.query("\xE9\x80\xA0\xE5\xAD\x97")
31
+ client.query(valid_utf8)
34
32
  rescue Mysql2::Error => e
35
- error = e
36
- ensure
37
- client.close
33
+ e
38
34
  end
39
-
40
- error
41
35
  end
42
36
 
43
- let :bad_err do
44
- client = Mysql2::Client.new(DatabaseCredentials['root'])
37
+ let(:invalid_utf8) { "\xE5\xC6\x7D\x1F" }
38
+ let(:bad_err) do
45
39
  begin
46
- client.query("\xE5\xC6\x7D\x1F")
40
+ client.query(invalid_utf8)
47
41
  rescue Mysql2::Error => e
48
- error = e
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
- error
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.should eql(Encoding::UTF_8)
59
- error.message.valid_encoding?
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.should eql(Encoding::UTF_8)
62
- bad_err.message.valid_encoding?
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.should include("??}\u001F")
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.should eql(Encoding::US_ASCII)
70
- error.sql_state.valid_encoding?
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 'UTF-16LE' do
75
- error.message.encoding.should eql(Encoding.default_internal)
76
- error.message.valid_encoding?
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.should eql(Encoding.default_internal)
79
- bad_err.message.valid_encoding?
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