mysql2 0.3.8 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -220
  3. data/LICENSE +21 -0
  4. data/README.md +370 -79
  5. data/examples/eventmachine.rb +1 -1
  6. data/examples/threaded.rb +4 -6
  7. data/ext/mysql2/client.c +1017 -305
  8. data/ext/mysql2/client.h +35 -11
  9. data/ext/mysql2/extconf.rb +222 -34
  10. data/ext/mysql2/infile.c +122 -0
  11. data/ext/mysql2/infile.h +1 -0
  12. data/ext/mysql2/mysql2_ext.c +1 -0
  13. data/ext/mysql2/mysql2_ext.h +12 -14
  14. data/ext/mysql2/mysql_enc_name_to_ruby.h +168 -0
  15. data/ext/mysql2/mysql_enc_to_ruby.h +249 -0
  16. data/ext/mysql2/result.c +664 -166
  17. data/ext/mysql2/result.h +16 -6
  18. data/ext/mysql2/statement.c +595 -0
  19. data/ext/mysql2/statement.h +19 -0
  20. data/lib/mysql2/client.rb +118 -211
  21. data/lib/mysql2/console.rb +5 -0
  22. data/lib/mysql2/em.rb +23 -5
  23. data/lib/mysql2/error.rb +62 -6
  24. data/lib/mysql2/field.rb +3 -0
  25. data/lib/mysql2/statement.rb +17 -0
  26. data/lib/mysql2/version.rb +1 -1
  27. data/lib/mysql2.rb +66 -3
  28. data/spec/configuration.yml.example +11 -0
  29. data/spec/em/em_spec.rb +96 -10
  30. data/spec/my.cnf.example +9 -0
  31. data/spec/mysql2/client_spec.rb +779 -205
  32. data/spec/mysql2/error_spec.rb +58 -45
  33. data/spec/mysql2/result_spec.rb +316 -159
  34. data/spec/mysql2/statement_spec.rb +776 -0
  35. data/spec/spec_helper.rb +97 -56
  36. data/spec/ssl/ca-cert.pem +17 -0
  37. data/spec/ssl/ca-key.pem +27 -0
  38. data/spec/ssl/ca.cnf +22 -0
  39. data/spec/ssl/cert.cnf +22 -0
  40. data/spec/ssl/client-cert.pem +17 -0
  41. data/spec/ssl/client-key.pem +27 -0
  42. data/spec/ssl/client-req.pem +15 -0
  43. data/spec/ssl/gen_certs.sh +48 -0
  44. data/spec/ssl/pkcs8-client-key.pem +28 -0
  45. data/spec/ssl/pkcs8-server-key.pem +28 -0
  46. data/spec/ssl/server-cert.pem +17 -0
  47. data/spec/ssl/server-key.pem +27 -0
  48. data/spec/ssl/server-req.pem +15 -0
  49. data/spec/test_data +1 -0
  50. data/support/5072E1F5.asc +432 -0
  51. data/support/libmysql.def +219 -0
  52. data/support/mysql_enc_to_ruby.rb +81 -0
  53. data/support/ruby_enc_to_mysql.rb +61 -0
  54. metadata +77 -196
  55. data/.gitignore +0 -12
  56. data/.rspec +0 -3
  57. data/.rvmrc +0 -1
  58. data/.travis.yml +0 -7
  59. data/Gemfile +0 -3
  60. data/MIT-LICENSE +0 -20
  61. data/Rakefile +0 -5
  62. data/benchmark/active_record.rb +0 -51
  63. data/benchmark/active_record_threaded.rb +0 -42
  64. data/benchmark/allocations.rb +0 -33
  65. data/benchmark/escape.rb +0 -36
  66. data/benchmark/query_with_mysql_casting.rb +0 -80
  67. data/benchmark/query_without_mysql_casting.rb +0 -56
  68. data/benchmark/sequel.rb +0 -37
  69. data/benchmark/setup_db.rb +0 -119
  70. data/benchmark/threaded.rb +0 -44
  71. data/mysql2.gemspec +0 -29
  72. data/tasks/benchmarks.rake +0 -20
  73. data/tasks/compile.rake +0 -71
  74. data/tasks/rspec.rake +0 -16
  75. data/tasks/vendor_mysql.rake +0 -40
data/spec/em/em_spec.rb CHANGED
@@ -4,45 +4,131 @@ begin
4
4
  require 'eventmachine'
5
5
  require 'mysql2/em'
6
6
 
7
- describe Mysql2::EM::Client do
7
+ RSpec.describe Mysql2::EM::Client do
8
8
  it "should support async queries" do
9
9
  results = []
10
10
  EM.run do
11
- client1 = Mysql2::EM::Client.new
11
+ client1 = Mysql2::EM::Client.new DatabaseCredentials['root']
12
12
  defer1 = client1.query "SELECT sleep(0.1) as first_query"
13
13
  defer1.callback do |result|
14
14
  results << result.first
15
+ client1.close
15
16
  EM.stop_event_loop
16
17
  end
17
18
 
18
- client2 = Mysql2::EM::Client.new
19
+ client2 = Mysql2::EM::Client.new DatabaseCredentials['root']
19
20
  defer2 = client2.query "SELECT sleep(0.025) second_query"
20
21
  defer2.callback do |result|
21
22
  results << result.first
23
+ client2.close
22
24
  end
23
25
  end
24
26
 
25
- results[0].keys.should include("second_query")
26
- results[1].keys.should include("first_query")
27
+ expect(results[0].keys).to include("second_query")
28
+ expect(results[1].keys).to include("first_query")
27
29
  end
28
30
 
29
31
  it "should support queries in callbacks" do
30
32
  results = []
31
33
  EM.run do
32
- client = Mysql2::EM::Client.new
34
+ client = Mysql2::EM::Client.new DatabaseCredentials['root']
33
35
  defer1 = client.query "SELECT sleep(0.025) as first_query"
34
36
  defer1.callback do |result|
35
37
  results << result.first
36
38
  defer2 = client.query "SELECT sleep(0.025) as second_query"
37
- defer2.callback do |result|
38
- results << result.first
39
+ defer2.callback do |r|
40
+ results << r.first
41
+ client.close
39
42
  EM.stop_event_loop
40
43
  end
41
44
  end
42
45
  end
43
46
 
44
- results[0].keys.should include("first_query")
45
- results[1].keys.should include("second_query")
47
+ expect(results[0].keys).to include("first_query")
48
+ expect(results[1].keys).to include("second_query")
49
+ end
50
+
51
+ it "should not swallow exceptions raised in callbacks" do
52
+ expect {
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
57
+ client.close
58
+ fail 'some error'
59
+ end
60
+ defer.errback do
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
+ }.to raise_error('some 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 { allow(client).to receive(:async_result).and_raise(error) }
73
+ after { client.close }
74
+
75
+ it "should swallow exceptions raised in by the client" do
76
+ errors = []
77
+ EM.run do
78
+ defer = client.query "SELECT sleep(0.1) as first_query"
79
+ defer.callback do
80
+ # This _shouldn't_ be run, but it is needed to prevent the specs from
81
+ # freezing if this test fails.
82
+ EM.stop_event_loop
83
+ end
84
+ defer.errback do |err|
85
+ errors << err
86
+ EM.stop_event_loop
87
+ end
88
+ end
89
+ expect(errors).to eq([error])
90
+ end
91
+
92
+ it "should fail the deferrable" do
93
+ callbacks_run = []
94
+ EM.run do
95
+ defer = client.query "SELECT sleep(0.025) as first_query"
96
+ EM.add_timer(0.1) do
97
+ defer.callback do
98
+ callbacks_run << :callback
99
+ # This _shouldn't_ be run, but it is needed to prevent the specs from
100
+ # freezing if this test fails.
101
+ EM.stop_event_loop
102
+ end
103
+ defer.errback do
104
+ callbacks_run << :errback
105
+ EM.stop_event_loop
106
+ end
107
+ end
108
+ end
109
+ expect(callbacks_run).to eq([:errback])
110
+ end
111
+ end
112
+
113
+ it "should not raise error when closing client with no query running" do
114
+ callbacks_run = []
115
+ EM.run do
116
+ client = Mysql2::EM::Client.new DatabaseCredentials['root']
117
+ defer = client.query("select sleep(0.025)")
118
+ defer.callback do
119
+ callbacks_run << :callback
120
+ end
121
+ defer.errback do
122
+ callbacks_run << :errback
123
+ end
124
+ EM.add_timer(0.1) do
125
+ expect(callbacks_run).to eq([:callback])
126
+ expect {
127
+ client.close
128
+ }.not_to raise_error
129
+ EM.stop_event_loop
130
+ end
131
+ end
46
132
  end
47
133
  end
48
134
  rescue LoadError
@@ -0,0 +1,9 @@
1
+ [root]
2
+ host=localhost
3
+ user=LOCALUSERNAME
4
+ password=
5
+
6
+ [client]
7
+ host=localhost
8
+ user=LOCALUSERNAME
9
+ password=