mysql2 0.5.0 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +150 -44
- data/ext/mysql2/client.c +217 -58
- data/ext/mysql2/client.h +9 -2
- data/ext/mysql2/extconf.rb +60 -7
- data/ext/mysql2/mysql2_ext.c +6 -1
- data/ext/mysql2/mysql2_ext.h +13 -0
- data/ext/mysql2/mysql_enc_name_to_ruby.h +60 -56
- data/ext/mysql2/mysql_enc_to_ruby.h +64 -3
- data/ext/mysql2/result.c +287 -21
- data/ext/mysql2/result.h +1 -0
- data/ext/mysql2/statement.c +95 -24
- data/lib/mysql2/client.rb +24 -3
- data/lib/mysql2/error.rb +4 -3
- data/lib/mysql2/statement.rb +1 -3
- data/lib/mysql2/version.rb +1 -1
- data/lib/mysql2.rb +8 -3
- data/support/3A79BD29.asc +49 -0
- data/support/5072E1F5.asc +5 -5
- data/support/C74CD1D8.asc +104 -0
- data/support/mysql_enc_to_ruby.rb +6 -1
- data/support/ruby_enc_to_mysql.rb +2 -0
- metadata +11 -55
- data/examples/eventmachine.rb +0 -19
- data/examples/threaded.rb +0 -16
- data/spec/configuration.yml.example +0 -11
- data/spec/em/em_spec.rb +0 -135
- data/spec/my.cnf.example +0 -9
- data/spec/mysql2/client_spec.rb +0 -1072
- data/spec/mysql2/error_spec.rb +0 -78
- data/spec/mysql2/result_spec.rb +0 -485
- data/spec/mysql2/statement_spec.rb +0 -708
- data/spec/rcov.opts +0 -3
- data/spec/spec_helper.rb +0 -112
- data/spec/ssl/ca-cert.pem +0 -17
- data/spec/ssl/ca-key.pem +0 -27
- data/spec/ssl/ca.cnf +0 -22
- data/spec/ssl/cert.cnf +0 -22
- data/spec/ssl/client-cert.pem +0 -17
- data/spec/ssl/client-key.pem +0 -27
- data/spec/ssl/client-req.pem +0 -15
- data/spec/ssl/gen_certs.sh +0 -48
- data/spec/ssl/pkcs8-client-key.pem +0 -28
- data/spec/ssl/pkcs8-server-key.pem +0 -28
- data/spec/ssl/server-cert.pem +0 -17
- data/spec/ssl/server-key.pem +0 -27
- data/spec/ssl/server-req.pem +0 -15
- data/spec/test_data +0 -1
data/spec/mysql2/error_spec.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Mysql2::Error do
|
4
|
-
let(:error) do
|
5
|
-
begin
|
6
|
-
@client.query("HAHAHA")
|
7
|
-
rescue Mysql2::Error => e
|
8
|
-
error = e
|
9
|
-
end
|
10
|
-
|
11
|
-
error
|
12
|
-
end
|
13
|
-
|
14
|
-
it "responds to error_number and sql_state, with aliases" do
|
15
|
-
expect(error).to respond_to(:error_number)
|
16
|
-
expect(error).to respond_to(:sql_state)
|
17
|
-
|
18
|
-
# Mysql gem compatibility
|
19
|
-
expect(error).to respond_to(:errno)
|
20
|
-
expect(error).to respond_to(:error)
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'encoding' do
|
24
|
-
let(:valid_utf8) { '造字' }
|
25
|
-
let(:error) do
|
26
|
-
begin
|
27
|
-
@client.query(valid_utf8)
|
28
|
-
rescue Mysql2::Error => e
|
29
|
-
e
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
let(:invalid_utf8) { ["e5c67d1f"].pack('H*').force_encoding(Encoding::UTF_8) }
|
34
|
-
let(:bad_err) do
|
35
|
-
begin
|
36
|
-
@client.query(invalid_utf8)
|
37
|
-
rescue Mysql2::Error => e
|
38
|
-
e
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
before do
|
43
|
-
# sanity check
|
44
|
-
expect(valid_utf8.encoding).to eql(Encoding::UTF_8)
|
45
|
-
expect(valid_utf8).to be_valid_encoding
|
46
|
-
|
47
|
-
expect(invalid_utf8.encoding).to eql(Encoding::UTF_8)
|
48
|
-
expect(invalid_utf8).to_not be_valid_encoding
|
49
|
-
end
|
50
|
-
|
51
|
-
it "returns error messages as UTF-8 by default" do
|
52
|
-
with_internal_encoding nil do
|
53
|
-
expect(error.message.encoding).to eql(Encoding::UTF_8)
|
54
|
-
expect(error.message).to be_valid_encoding
|
55
|
-
|
56
|
-
expect(bad_err.message.encoding).to eql(Encoding::UTF_8)
|
57
|
-
expect(bad_err.message).to be_valid_encoding
|
58
|
-
|
59
|
-
expect(bad_err.message).to include("??}\u001F")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it "returns sql state as ASCII" do
|
64
|
-
expect(error.sql_state.encoding).to eql(Encoding::US_ASCII)
|
65
|
-
expect(error.sql_state).to be_valid_encoding
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns error messages and sql state in Encoding.default_internal if set" do
|
69
|
-
with_internal_encoding Encoding::UTF_16LE do
|
70
|
-
expect(error.message.encoding).to eql(Encoding.default_internal)
|
71
|
-
expect(error.message).to be_valid_encoding
|
72
|
-
|
73
|
-
expect(bad_err.message.encoding).to eql(Encoding.default_internal)
|
74
|
-
expect(bad_err.message).to be_valid_encoding
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/spec/mysql2/result_spec.rb
DELETED
@@ -1,485 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Mysql2::Result do
|
4
|
-
before(:each) do
|
5
|
-
@result = @client.query "SELECT 1"
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should raise a TypeError exception when it doesn't wrap a result set" do
|
9
|
-
r = Mysql2::Result.new
|
10
|
-
expect { r.count }.to raise_error(TypeError)
|
11
|
-
expect { r.fields }.to raise_error(TypeError)
|
12
|
-
expect { r.size }.to raise_error(TypeError)
|
13
|
-
expect { r.each }.to raise_error(TypeError)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should have included Enumerable" do
|
17
|
-
expect(Mysql2::Result.ancestors.include?(Enumerable)).to be true
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should respond to #each" do
|
21
|
-
expect(@result).to respond_to(:each)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should respond to #free" do
|
25
|
-
expect(@result).to respond_to(:free)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should raise a Mysql2::Error exception upon a bad query" do
|
29
|
-
expect do
|
30
|
-
@client.query "bad sql"
|
31
|
-
end.to raise_error(Mysql2::Error)
|
32
|
-
|
33
|
-
expect do
|
34
|
-
@client.query "SELECT 1"
|
35
|
-
end.not_to raise_error
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should respond to #count, which is aliased as #size" do
|
39
|
-
r = @client.query "SELECT 1"
|
40
|
-
expect(r).to respond_to :count
|
41
|
-
expect(r).to respond_to :size
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should be able to return the number of rows in the result set" do
|
45
|
-
r = @client.query "SELECT 1"
|
46
|
-
expect(r.count).to eql(1)
|
47
|
-
expect(r.size).to eql(1)
|
48
|
-
end
|
49
|
-
|
50
|
-
context "metadata queries" do
|
51
|
-
it "should show tables" do
|
52
|
-
@result = @client.query "SHOW TABLES"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "#each" do
|
57
|
-
it "should yield rows as hash's" do
|
58
|
-
@result.each do |row|
|
59
|
-
expect(row).to be_an_instance_of(Hash)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should yield rows as hash's with symbol keys if :symbolize_keys was set to true" do
|
64
|
-
@result.each(symbolize_keys: true) do |row|
|
65
|
-
expect(row.keys.first).to be_an_instance_of(Symbol)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should be able to return results as an array" do
|
70
|
-
@result.each(as: :array) do |row|
|
71
|
-
expect(row).to be_an_instance_of(Array)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should cache previously yielded results by default" do
|
76
|
-
expect(@result.first.object_id).to eql(@result.first.object_id)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should not cache previously yielded results if cache_rows is disabled" do
|
80
|
-
result = @client.query "SELECT 1", cache_rows: false
|
81
|
-
expect(result.first.object_id).not_to eql(result.first.object_id)
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should be able to iterate a second time even if cache_rows is disabled" do
|
85
|
-
result = @client.query "SELECT 1 UNION SELECT 2", cache_rows: false
|
86
|
-
expect(result.to_a).to eql(result.to_a)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should yield different value for #first if streaming" do
|
90
|
-
result = @client.query "SELECT 1 UNION SELECT 2", stream: true, cache_rows: false
|
91
|
-
expect(result.first).not_to eql(result.first)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should yield the same value for #first if streaming is disabled" do
|
95
|
-
result = @client.query "SELECT 1 UNION SELECT 2", stream: false
|
96
|
-
expect(result.first).to eql(result.first)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should throw an exception if we try to iterate twice when streaming is enabled" do
|
100
|
-
result = @client.query "SELECT 1 UNION SELECT 2", stream: true, cache_rows: false
|
101
|
-
|
102
|
-
expect do
|
103
|
-
result.each.to_a
|
104
|
-
result.each.to_a
|
105
|
-
end.to raise_exception(Mysql2::Error)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "#fields" do
|
110
|
-
let(:test_result) { @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1") }
|
111
|
-
|
112
|
-
it "method should exist" do
|
113
|
-
expect(test_result).to respond_to(:fields)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should return an array of field names in proper order" do
|
117
|
-
result = @client.query "SELECT 'a', 'b', 'c'"
|
118
|
-
expect(result.fields).to eql(%w[a b c])
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context "streaming" do
|
123
|
-
it "should maintain a count while streaming" do
|
124
|
-
result = @client.query('SELECT 1', stream: true, cache_rows: false)
|
125
|
-
expect(result.count).to eql(0)
|
126
|
-
result.each.to_a
|
127
|
-
expect(result.count).to eql(1)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should retain the count when mixing first and each" do
|
131
|
-
result = @client.query("SELECT 1 UNION SELECT 2", stream: true, cache_rows: false)
|
132
|
-
expect(result.count).to eql(0)
|
133
|
-
result.first
|
134
|
-
expect(result.count).to eql(1)
|
135
|
-
result.each.to_a
|
136
|
-
expect(result.count).to eql(2)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should not yield nil at the end of streaming" do
|
140
|
-
result = @client.query('SELECT * FROM mysql2_test', stream: true, cache_rows: false)
|
141
|
-
result.each { |r| expect(r).not_to be_nil }
|
142
|
-
end
|
143
|
-
|
144
|
-
it "#count should be zero for rows after streaming when there were no results" do
|
145
|
-
@client.query "USE test"
|
146
|
-
result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", stream: true, cache_rows: false)
|
147
|
-
expect(result.count).to eql(0)
|
148
|
-
result.each.to_a
|
149
|
-
expect(result.count).to eql(0)
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should raise an exception if streaming ended due to a timeout" do
|
153
|
-
@client.query "CREATE TEMPORARY TABLE streamingTest (val BINARY(255)) ENGINE=MEMORY"
|
154
|
-
|
155
|
-
# Insert enough records to force the result set into multiple reads
|
156
|
-
# (the BINARY type is used simply because it forces full width results)
|
157
|
-
10000.times do |i|
|
158
|
-
@client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')"
|
159
|
-
end
|
160
|
-
|
161
|
-
@client.query "SET net_write_timeout = 1"
|
162
|
-
res = @client.query "SELECT * FROM streamingTest", stream: true, cache_rows: false
|
163
|
-
|
164
|
-
expect do
|
165
|
-
res.each_with_index do |_, i|
|
166
|
-
# Exhaust the first result packet then trigger a timeout
|
167
|
-
sleep 2 if i > 0 && i % 1000 == 0
|
168
|
-
end
|
169
|
-
end.to raise_error(Mysql2::Error, /Lost connection/)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
context "row data type mapping" do
|
174
|
-
let(:test_result) { @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first }
|
175
|
-
|
176
|
-
it "should return nil values for NULL and strings for everything else when :cast is false" do
|
177
|
-
result = @client.query('SELECT null_test, tiny_int_test, bool_cast_test, int_test, date_test, enum_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', cast: false).first
|
178
|
-
expect(result["null_test"]).to be_nil
|
179
|
-
expect(result["tiny_int_test"]).to eql("1")
|
180
|
-
expect(result["bool_cast_test"]).to eql("1")
|
181
|
-
expect(result["int_test"]).to eql("10")
|
182
|
-
expect(result["date_test"]).to eql("2010-04-04")
|
183
|
-
expect(result["enum_test"]).to eql("val1")
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should return nil for a NULL value" do
|
187
|
-
expect(test_result['null_test']).to be_an_instance_of(NilClass)
|
188
|
-
expect(test_result['null_test']).to eql(nil)
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should return String for a BIT(64) value" do
|
192
|
-
expect(test_result['bit_test']).to be_an_instance_of(String)
|
193
|
-
expect(test_result['bit_test']).to eql("\000\000\000\000\000\000\000\005")
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should return String for a BIT(1) value" do
|
197
|
-
expect(test_result['single_bit_test']).to be_an_instance_of(String)
|
198
|
-
expect(test_result['single_bit_test']).to eql("\001")
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should return Fixnum for a TINYINT value" do
|
202
|
-
expect(num_classes).to include(test_result['tiny_int_test'].class)
|
203
|
-
expect(test_result['tiny_int_test']).to eql(1)
|
204
|
-
end
|
205
|
-
|
206
|
-
context "cast booleans for TINYINT if :cast_booleans is enabled" do
|
207
|
-
# rubocop:disable Style/Semicolon
|
208
|
-
let(:id1) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 1)'; @client.last_id }
|
209
|
-
let(:id2) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 0)'; @client.last_id }
|
210
|
-
let(:id3) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'; @client.last_id }
|
211
|
-
# rubocop:enable Style/Semicolon
|
212
|
-
|
213
|
-
after do
|
214
|
-
@client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})"
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
|
218
|
-
result1 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id1} LIMIT 1", cast_booleans: true
|
219
|
-
result2 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id2} LIMIT 1", cast_booleans: true
|
220
|
-
result3 = @client.query "SELECT bool_cast_test FROM mysql2_test WHERE id = #{id3} LIMIT 1", cast_booleans: true
|
221
|
-
expect(result1.first['bool_cast_test']).to be true
|
222
|
-
expect(result2.first['bool_cast_test']).to be false
|
223
|
-
expect(result3.first['bool_cast_test']).to be true
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
context "cast booleans for BIT(1) if :cast_booleans is enabled" do
|
228
|
-
# rubocop:disable Style/Semicolon
|
229
|
-
let(:id1) { @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)'; @client.last_id }
|
230
|
-
let(:id2) { @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'; @client.last_id }
|
231
|
-
# rubocop:enable Style/Semicolon
|
232
|
-
|
233
|
-
after do
|
234
|
-
@client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
|
238
|
-
result1 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id1}", cast_booleans: true
|
239
|
-
result2 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id2}", cast_booleans: true
|
240
|
-
expect(result1.first['single_bit_test']).to be true
|
241
|
-
expect(result2.first['single_bit_test']).to be false
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
it "should return Fixnum for a SMALLINT value" do
|
246
|
-
expect(num_classes).to include(test_result['small_int_test'].class)
|
247
|
-
expect(test_result['small_int_test']).to eql(10)
|
248
|
-
end
|
249
|
-
|
250
|
-
it "should return Fixnum for a MEDIUMINT value" do
|
251
|
-
expect(num_classes).to include(test_result['medium_int_test'].class)
|
252
|
-
expect(test_result['medium_int_test']).to eql(10)
|
253
|
-
end
|
254
|
-
|
255
|
-
it "should return Fixnum for an INT value" do
|
256
|
-
expect(num_classes).to include(test_result['int_test'].class)
|
257
|
-
expect(test_result['int_test']).to eql(10)
|
258
|
-
end
|
259
|
-
|
260
|
-
it "should return Fixnum for a BIGINT value" do
|
261
|
-
expect(num_classes).to include(test_result['big_int_test'].class)
|
262
|
-
expect(test_result['big_int_test']).to eql(10)
|
263
|
-
end
|
264
|
-
|
265
|
-
it "should return Fixnum for a YEAR value" do
|
266
|
-
expect(num_classes).to include(test_result['year_test'].class)
|
267
|
-
expect(test_result['year_test']).to eql(2009)
|
268
|
-
end
|
269
|
-
|
270
|
-
it "should return BigDecimal for a DECIMAL value" do
|
271
|
-
expect(test_result['decimal_test']).to be_an_instance_of(BigDecimal)
|
272
|
-
expect(test_result['decimal_test']).to eql(10.3)
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should return Float for a FLOAT value" do
|
276
|
-
expect(test_result['float_test']).to be_an_instance_of(Float)
|
277
|
-
expect(test_result['float_test']).to eql(10.3)
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should return Float for a DOUBLE value" do
|
281
|
-
expect(test_result['double_test']).to be_an_instance_of(Float)
|
282
|
-
expect(test_result['double_test']).to eql(10.3)
|
283
|
-
end
|
284
|
-
|
285
|
-
it "should return Time for a DATETIME value when within the supported range" do
|
286
|
-
expect(test_result['date_time_test']).to be_an_instance_of(Time)
|
287
|
-
expect(test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
|
288
|
-
end
|
289
|
-
|
290
|
-
it "should return Time when timestamp is < 1901-12-13 20:45:52" do
|
291
|
-
r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
|
292
|
-
expect(r.first['test']).to be_an_instance_of(Time)
|
293
|
-
end
|
294
|
-
|
295
|
-
it "should return Time when timestamp is > 2038-01-19T03:14:07" do
|
296
|
-
r = @client.query("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test")
|
297
|
-
expect(r.first['test']).to be_an_instance_of(Time)
|
298
|
-
end
|
299
|
-
|
300
|
-
it "should return Time for a TIMESTAMP value when within the supported range" do
|
301
|
-
expect(test_result['timestamp_test']).to be_an_instance_of(Time)
|
302
|
-
expect(test_result['timestamp_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
|
303
|
-
end
|
304
|
-
|
305
|
-
it "should return Time for a TIME value" do
|
306
|
-
expect(test_result['time_test']).to be_an_instance_of(Time)
|
307
|
-
expect(test_result['time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2000-01-01 11:44:00')
|
308
|
-
end
|
309
|
-
|
310
|
-
it "should return Date for a DATE value" do
|
311
|
-
expect(test_result['date_test']).to be_an_instance_of(Date)
|
312
|
-
expect(test_result['date_test'].strftime("%Y-%m-%d")).to eql('2010-04-04')
|
313
|
-
end
|
314
|
-
|
315
|
-
it "should return String for an ENUM value" do
|
316
|
-
expect(test_result['enum_test']).to be_an_instance_of(String)
|
317
|
-
expect(test_result['enum_test']).to eql('val1')
|
318
|
-
end
|
319
|
-
|
320
|
-
it "should raise an error given an invalid DATETIME" do
|
321
|
-
expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \
|
322
|
-
raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
|
323
|
-
end
|
324
|
-
|
325
|
-
context "string encoding for ENUM values" do
|
326
|
-
it "should default to the connection's encoding if Encoding.default_internal is nil" do
|
327
|
-
with_internal_encoding nil do
|
328
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
329
|
-
expect(result['enum_test'].encoding).to eql(Encoding::UTF_8)
|
330
|
-
|
331
|
-
client2 = new_client(encoding: 'ascii')
|
332
|
-
result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
333
|
-
expect(result['enum_test'].encoding).to eql(Encoding::ASCII)
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
it "should use Encoding.default_internal" do
|
338
|
-
with_internal_encoding Encoding::UTF_8 do
|
339
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
340
|
-
expect(result['enum_test'].encoding).to eql(Encoding.default_internal)
|
341
|
-
end
|
342
|
-
|
343
|
-
with_internal_encoding Encoding::ASCII do
|
344
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
345
|
-
expect(result['enum_test'].encoding).to eql(Encoding.default_internal)
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
it "should return String for a SET value" do
|
351
|
-
expect(test_result['set_test']).to be_an_instance_of(String)
|
352
|
-
expect(test_result['set_test']).to eql('val1,val2')
|
353
|
-
end
|
354
|
-
|
355
|
-
context "string encoding for SET values" do
|
356
|
-
it "should default to the connection's encoding if Encoding.default_internal is nil" do
|
357
|
-
with_internal_encoding nil do
|
358
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
359
|
-
expect(result['set_test'].encoding).to eql(Encoding::UTF_8)
|
360
|
-
|
361
|
-
client2 = new_client(encoding: 'ascii')
|
362
|
-
result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
363
|
-
expect(result['set_test'].encoding).to eql(Encoding::ASCII)
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
it "should use Encoding.default_internal" do
|
368
|
-
with_internal_encoding Encoding::UTF_8 do
|
369
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
370
|
-
expect(result['set_test'].encoding).to eql(Encoding.default_internal)
|
371
|
-
end
|
372
|
-
|
373
|
-
with_internal_encoding Encoding::ASCII do
|
374
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
375
|
-
expect(result['set_test'].encoding).to eql(Encoding.default_internal)
|
376
|
-
end
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
it "should return String for a BINARY value" do
|
381
|
-
expect(test_result['binary_test']).to be_an_instance_of(String)
|
382
|
-
expect(test_result['binary_test']).to eql("test#{"\000" * 6}")
|
383
|
-
end
|
384
|
-
|
385
|
-
context "string encoding for BINARY values" do
|
386
|
-
it "should default to binary if Encoding.default_internal is nil" do
|
387
|
-
with_internal_encoding nil do
|
388
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
389
|
-
expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
it "should not use Encoding.default_internal" do
|
394
|
-
with_internal_encoding Encoding::UTF_8 do
|
395
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
396
|
-
expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
|
397
|
-
end
|
398
|
-
|
399
|
-
with_internal_encoding Encoding::ASCII do
|
400
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
401
|
-
expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
|
402
|
-
end
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
{
|
407
|
-
'char_test' => 'CHAR',
|
408
|
-
'varchar_test' => 'VARCHAR',
|
409
|
-
'varbinary_test' => 'VARBINARY',
|
410
|
-
'tiny_blob_test' => 'TINYBLOB',
|
411
|
-
'tiny_text_test' => 'TINYTEXT',
|
412
|
-
'blob_test' => 'BLOB',
|
413
|
-
'text_test' => 'TEXT',
|
414
|
-
'medium_blob_test' => 'MEDIUMBLOB',
|
415
|
-
'medium_text_test' => 'MEDIUMTEXT',
|
416
|
-
'long_blob_test' => 'LONGBLOB',
|
417
|
-
'long_text_test' => 'LONGTEXT',
|
418
|
-
}.each do |field, type|
|
419
|
-
it "should return a String for #{type}" do
|
420
|
-
expect(test_result[field]).to be_an_instance_of(String)
|
421
|
-
expect(test_result[field]).to eql("test")
|
422
|
-
end
|
423
|
-
|
424
|
-
context "string encoding for #{type} values" do
|
425
|
-
if %w[VARBINARY TINYBLOB BLOB MEDIUMBLOB LONGBLOB].include?(type)
|
426
|
-
it "should default to binary if Encoding.default_internal is nil" do
|
427
|
-
with_internal_encoding nil do
|
428
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
429
|
-
expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
it "should not use Encoding.default_internal" do
|
434
|
-
with_internal_encoding Encoding::UTF_8 do
|
435
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
436
|
-
expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
|
437
|
-
end
|
438
|
-
|
439
|
-
with_internal_encoding Encoding::ASCII do
|
440
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
441
|
-
expect(result['binary_test'].encoding).to eql(Encoding::BINARY)
|
442
|
-
end
|
443
|
-
end
|
444
|
-
else
|
445
|
-
it "should default to utf-8 if Encoding.default_internal is nil" do
|
446
|
-
with_internal_encoding nil do
|
447
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
448
|
-
expect(result[field].encoding).to eql(Encoding::UTF_8)
|
449
|
-
|
450
|
-
client2 = new_client(encoding: 'ascii')
|
451
|
-
result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
452
|
-
expect(result[field].encoding).to eql(Encoding::ASCII)
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
it "should use Encoding.default_internal" do
|
457
|
-
with_internal_encoding Encoding::UTF_8 do
|
458
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
459
|
-
expect(result[field].encoding).to eql(Encoding.default_internal)
|
460
|
-
end
|
461
|
-
|
462
|
-
with_internal_encoding Encoding::ASCII do
|
463
|
-
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
464
|
-
expect(result[field].encoding).to eql(Encoding.default_internal)
|
465
|
-
end
|
466
|
-
end
|
467
|
-
end
|
468
|
-
end
|
469
|
-
end
|
470
|
-
end
|
471
|
-
|
472
|
-
context "server flags" do
|
473
|
-
let(:test_result) { @client.query("SELECT * FROM mysql2_test ORDER BY null_test DESC LIMIT 1") }
|
474
|
-
|
475
|
-
it "should set a definitive value for query_was_slow" do
|
476
|
-
expect(test_result.server_flags[:query_was_slow]).to eql(false)
|
477
|
-
end
|
478
|
-
it "should set a definitive value for no_index_used" do
|
479
|
-
expect(test_result.server_flags[:no_index_used]).to eql(true)
|
480
|
-
end
|
481
|
-
it "should set a definitive value for no_good_index_used" do
|
482
|
-
expect(test_result.server_flags[:no_good_index_used]).to eql(false)
|
483
|
-
end
|
484
|
-
end
|
485
|
-
end
|