mysql2 0.3.18 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/LICENSE +21 -0
  4. data/README.md +132 -55
  5. data/examples/eventmachine.rb +1 -1
  6. data/examples/threaded.rb +4 -6
  7. data/ext/mysql2/client.c +374 -197
  8. data/ext/mysql2/client.h +13 -3
  9. data/ext/mysql2/extconf.rb +119 -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 +7 -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 +512 -138
  16. data/ext/mysql2/result.h +13 -6
  17. data/ext/mysql2/statement.c +595 -0
  18. data/ext/mysql2/statement.h +19 -0
  19. data/lib/mysql2/client.rb +85 -26
  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/configuration.yml.example +0 -6
  28. data/spec/em/em_spec.rb +22 -21
  29. data/spec/mysql2/client_spec.rb +530 -388
  30. data/spec/mysql2/error_spec.rb +38 -39
  31. data/spec/mysql2/result_spec.rb +223 -214
  32. data/spec/mysql2/statement_spec.rb +763 -0
  33. data/spec/spec_helper.rb +80 -59
  34. data/spec/ssl/ca-cert.pem +17 -0
  35. data/spec/ssl/ca-key.pem +27 -0
  36. data/spec/ssl/ca.cnf +22 -0
  37. data/spec/ssl/cert.cnf +22 -0
  38. data/spec/ssl/client-cert.pem +17 -0
  39. data/spec/ssl/client-key.pem +27 -0
  40. data/spec/ssl/client-req.pem +15 -0
  41. data/spec/ssl/gen_certs.sh +48 -0
  42. data/spec/ssl/pkcs8-client-key.pem +28 -0
  43. data/spec/ssl/pkcs8-server-key.pem +28 -0
  44. data/spec/ssl/server-cert.pem +17 -0
  45. data/spec/ssl/server-key.pem +27 -0
  46. data/spec/ssl/server-req.pem +15 -0
  47. data/support/mysql_enc_to_ruby.rb +7 -8
  48. data/support/ruby_enc_to_mysql.rb +1 -1
  49. metadata +42 -47
@@ -2,81 +2,80 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Mysql2::Error do
6
- let(:client) { Mysql2::Client.new(DatabaseCredentials['root']) }
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.should respond_to(:error_number)
22
- error.should respond_to(:sql_state)
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.should respond_to(:errno)
26
- error.should respond_to(:error)
21
+ expect(error).to respond_to(:errno)
22
+ expect(error).to respond_to(:error)
27
23
  end
28
24
 
29
- if "".respond_to? :encoding
30
- let :error do
31
- client = Mysql2::Client.new(DatabaseCredentials['root'])
25
+ context 'encoding' do
26
+ let(:valid_utf8) { '造字' }
27
+ let(:error) do
32
28
  begin
33
- client.query("\xE9\x80\xA0\xE5\xAD\x97")
29
+ @client.query(valid_utf8)
34
30
  rescue Mysql2::Error => e
35
- error = e
36
- ensure
37
- client.close
31
+ e
38
32
  end
39
-
40
- error
41
33
  end
42
34
 
43
- let :bad_err do
44
- client = Mysql2::Client.new(DatabaseCredentials['root'])
35
+ let(:invalid_utf8) { ["e5c67d1f"].pack('H*').force_encoding(Encoding::UTF_8) }
36
+ let(:bad_err) do
45
37
  begin
46
- client.query("\xE5\xC6\x7D\x1F")
38
+ @client.query(invalid_utf8)
47
39
  rescue Mysql2::Error => e
48
- error = e
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
- error
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.should eql(Encoding::UTF_8)
59
- error.message.valid_encoding?
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.should eql(Encoding::UTF_8)
62
- bad_err.message.valid_encoding?
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.should include("??}\u001F")
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.should eql(Encoding::US_ASCII)
70
- error.sql_state.valid_encoding?
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 'UTF-16LE' do
75
- error.message.encoding.should eql(Encoding.default_internal)
76
- error.message.valid_encoding?
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.should eql(Encoding.default_internal)
79
- bad_err.message.valid_encoding?
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