mysql2 0.3.11-x86-mingw32 → 0.3.18-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +280 -75
- data/ext/mysql2/client.c +721 -206
- data/ext/mysql2/client.h +26 -12
- data/ext/mysql2/extconf.rb +120 -16
- data/ext/mysql2/infile.c +122 -0
- data/ext/mysql2/infile.h +1 -0
- data/ext/mysql2/mysql2_ext.h +7 -4
- data/ext/mysql2/mysql_enc_name_to_ruby.h +168 -0
- data/ext/mysql2/mysql_enc_to_ruby.h +246 -0
- data/ext/mysql2/result.c +230 -112
- data/ext/mysql2/result.h +4 -1
- data/lib/mysql2.rb +46 -3
- data/lib/mysql2/1.8/mysql2.so +0 -0
- data/lib/mysql2/1.9/mysql2.so +0 -0
- data/lib/mysql2/2.0/mysql2.so +0 -0
- data/lib/mysql2/2.1/mysql2.so +0 -0
- data/lib/mysql2/client.rb +48 -200
- data/lib/mysql2/console.rb +5 -0
- data/lib/mysql2/em.rb +22 -3
- data/lib/mysql2/error.rb +71 -6
- data/lib/mysql2/mysql2.rb +2 -0
- data/lib/mysql2/version.rb +1 -1
- data/spec/configuration.yml.example +17 -0
- data/spec/em/em_spec.rb +90 -5
- data/spec/my.cnf.example +9 -0
- data/spec/mysql2/client_spec.rb +501 -69
- data/spec/mysql2/error_spec.rb +58 -44
- data/spec/mysql2/result_spec.rb +191 -74
- data/spec/spec_helper.rb +23 -3
- data/spec/test_data +1 -0
- data/support/libmysql.def +219 -0
- data/support/mysql_enc_to_ruby.rb +82 -0
- data/support/ruby_enc_to_mysql.rb +61 -0
- data/vendor/README +654 -0
- data/vendor/libmysql.dll +0 -0
- metadata +86 -221
- data/.gitignore +0 -12
- data/.rspec +0 -3
- data/.rvmrc +0 -1
- data/.travis.yml +0 -7
- data/CHANGELOG.md +0 -244
- data/Gemfile +0 -3
- data/MIT-LICENSE +0 -20
- data/Rakefile +0 -5
- data/benchmark/active_record.rb +0 -51
- data/benchmark/active_record_threaded.rb +0 -42
- data/benchmark/allocations.rb +0 -33
- data/benchmark/escape.rb +0 -36
- data/benchmark/query_with_mysql_casting.rb +0 -80
- data/benchmark/query_without_mysql_casting.rb +0 -56
- data/benchmark/sequel.rb +0 -37
- data/benchmark/setup_db.rb +0 -119
- data/benchmark/threaded.rb +0 -44
- data/mysql2.gemspec +0 -29
- data/tasks/benchmarks.rake +0 -20
- data/tasks/compile.rake +0 -71
- data/tasks/rspec.rake +0 -16
- data/tasks/vendor_mysql.rake +0 -40
data/spec/mysql2/error_spec.rb
CHANGED
@@ -1,68 +1,82 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
describe Mysql2::Error do
|
5
|
-
|
6
|
-
@client = Mysql2::Client.new :encoding => "utf8"
|
7
|
-
begin
|
8
|
-
@client.query("HAHAHA")
|
9
|
-
rescue Mysql2::Error => e
|
10
|
-
@error = e
|
11
|
-
end
|
6
|
+
let(:client) { Mysql2::Client.new(DatabaseCredentials['root']) }
|
12
7
|
|
13
|
-
|
8
|
+
let :error do
|
14
9
|
begin
|
15
|
-
|
10
|
+
client.query("HAHAHA")
|
16
11
|
rescue Mysql2::Error => e
|
17
|
-
|
12
|
+
error = e
|
13
|
+
ensure
|
14
|
+
client.close
|
18
15
|
end
|
19
|
-
end
|
20
16
|
|
21
|
-
|
22
|
-
@error.should respond_to(:error_number)
|
17
|
+
error
|
23
18
|
end
|
24
19
|
|
25
|
-
it "
|
26
|
-
|
27
|
-
|
20
|
+
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)
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
# Mysql gem compatibility
|
25
|
+
error.should respond_to(:errno)
|
26
|
+
error.should respond_to(:error)
|
32
27
|
end
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
if "".respond_to? :encoding
|
30
|
+
let :error do
|
31
|
+
client = Mysql2::Client.new(DatabaseCredentials['root'])
|
32
|
+
begin
|
33
|
+
client.query("\xE9\x80\xA0\xE5\xAD\x97")
|
34
|
+
rescue Mysql2::Error => e
|
35
|
+
error = e
|
36
|
+
ensure
|
37
|
+
client.close
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
error
|
41
|
+
end
|
42
|
+
|
43
|
+
let :bad_err do
|
44
|
+
client = Mysql2::Client.new(DatabaseCredentials['root'])
|
45
|
+
begin
|
46
|
+
client.query("\xE5\xC6\x7D\x1F")
|
47
|
+
rescue Mysql2::Error => e
|
48
|
+
error = e
|
49
|
+
ensure
|
50
|
+
client.close
|
46
51
|
end
|
52
|
+
|
53
|
+
error
|
47
54
|
end
|
48
55
|
|
49
|
-
it "
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
it "returns error messages as UTF-8 by default" do
|
57
|
+
with_internal_encoding nil do
|
58
|
+
error.message.encoding.should eql(Encoding::UTF_8)
|
59
|
+
error.message.valid_encoding?
|
60
|
+
|
61
|
+
bad_err.message.encoding.should eql(Encoding::UTF_8)
|
62
|
+
bad_err.message.valid_encoding?
|
63
|
+
|
64
|
+
bad_err.message.should include("??}\u001F")
|
56
65
|
end
|
57
66
|
end
|
58
67
|
|
59
|
-
it "
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
68
|
+
it "returns sql state as ASCII" do
|
69
|
+
error.sql_state.encoding.should eql(Encoding::US_ASCII)
|
70
|
+
error.sql_state.valid_encoding?
|
71
|
+
end
|
72
|
+
|
73
|
+
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?
|
77
|
+
|
78
|
+
bad_err.message.encoding.should eql(Encoding.default_internal)
|
79
|
+
bad_err.message.valid_encoding?
|
66
80
|
end
|
67
81
|
end
|
68
82
|
end
|
data/spec/mysql2/result_spec.rb
CHANGED
@@ -2,10 +2,6 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Mysql2::Result do
|
5
|
-
before(:each) do
|
6
|
-
@client = Mysql2::Client.new :host => "localhost", :username => "root", :database => 'test'
|
7
|
-
end
|
8
|
-
|
9
5
|
before(:each) do
|
10
6
|
@result = @client.query "SELECT 1"
|
11
7
|
end
|
@@ -73,11 +69,29 @@ describe Mysql2::Result do
|
|
73
69
|
result = @client.query "SELECT 1", :cache_rows => false
|
74
70
|
result.first.object_id.should_not eql(result.first.object_id)
|
75
71
|
end
|
72
|
+
|
73
|
+
it "should yield different value for #first if streaming" do
|
74
|
+
result = @client.query "SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false
|
75
|
+
result.first.should_not eql(result.first)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should yield the same value for #first if streaming is disabled" do
|
79
|
+
result = @client.query "SELECT 1 UNION SELECT 2", :stream => false
|
80
|
+
result.first.should eql(result.first)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should throw an exception if we try to iterate twice when streaming is enabled" do
|
84
|
+
result = @client.query "SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false
|
85
|
+
|
86
|
+
expect {
|
87
|
+
result.each.to_a
|
88
|
+
result.each.to_a
|
89
|
+
}.to raise_exception(Mysql2::Error)
|
90
|
+
end
|
76
91
|
end
|
77
92
|
|
78
93
|
context "#fields" do
|
79
94
|
before(:each) do
|
80
|
-
@client.query "USE test"
|
81
95
|
@test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1")
|
82
96
|
end
|
83
97
|
|
@@ -91,20 +105,70 @@ describe Mysql2::Result do
|
|
91
105
|
end
|
92
106
|
end
|
93
107
|
|
108
|
+
context "streaming" do
|
109
|
+
it "should maintain a count while streaming" do
|
110
|
+
result = @client.query('SELECT 1')
|
111
|
+
|
112
|
+
result.count.should eql(1)
|
113
|
+
result.each.to_a
|
114
|
+
result.count.should eql(1)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should set the actual count of rows after streaming" do
|
118
|
+
result = @client.query("SELECT * FROM mysql2_test", :stream => true, :cache_rows => false)
|
119
|
+
result.count.should eql(0)
|
120
|
+
result.each {|r| }
|
121
|
+
result.count.should eql(1)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should not yield nil at the end of streaming" do
|
125
|
+
result = @client.query('SELECT * FROM mysql2_test', :stream => true, :cache_rows => false)
|
126
|
+
result.each { |r| r.should_not be_nil}
|
127
|
+
end
|
128
|
+
|
129
|
+
it "#count should be zero for rows after streaming when there were no results" do
|
130
|
+
result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", :stream => true, :cache_rows => false)
|
131
|
+
result.count.should eql(0)
|
132
|
+
result.each.to_a
|
133
|
+
result.count.should eql(0)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should raise an exception if streaming ended due to a timeout" do
|
137
|
+
# Create an extra client instance, since we're going to time it out
|
138
|
+
client = Mysql2::Client.new DatabaseCredentials['root']
|
139
|
+
client.query "CREATE TEMPORARY TABLE streamingTest (val BINARY(255)) ENGINE=MEMORY"
|
140
|
+
|
141
|
+
# Insert enough records to force the result set into multiple reads
|
142
|
+
# (the BINARY type is used simply because it forces full width results)
|
143
|
+
10000.times do |i|
|
144
|
+
client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')"
|
145
|
+
end
|
146
|
+
|
147
|
+
client.query "SET net_write_timeout = 1"
|
148
|
+
res = client.query "SELECT * FROM streamingTest", :stream => true, :cache_rows => false
|
149
|
+
|
150
|
+
lambda {
|
151
|
+
res.each_with_index do |row, i|
|
152
|
+
# Exhaust the first result packet then trigger a timeout
|
153
|
+
sleep 2 if i > 0 && i % 1000 == 0
|
154
|
+
end
|
155
|
+
}.should raise_error(Mysql2::Error, /Lost connection/)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
94
159
|
context "row data type mapping" do
|
95
160
|
before(:each) do
|
96
|
-
@client.query "USE test"
|
97
161
|
@test_result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
98
162
|
end
|
99
163
|
|
100
164
|
it "should return nil values for NULL and strings for everything else when :cast is false" do
|
101
165
|
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
|
102
166
|
result["null_test"].should be_nil
|
103
|
-
result["tiny_int_test"].should
|
104
|
-
result["bool_cast_test"].should
|
105
|
-
result["int_test"].should
|
106
|
-
result["date_test"].should
|
107
|
-
result["enum_test"].should
|
167
|
+
result["tiny_int_test"].should eql("1")
|
168
|
+
result["bool_cast_test"].should eql("1")
|
169
|
+
result["int_test"].should eql("10")
|
170
|
+
result["date_test"].should eql("2010-04-04")
|
171
|
+
result["enum_test"].should eql("val1")
|
108
172
|
end
|
109
173
|
|
110
174
|
it "should return nil for a NULL value" do
|
@@ -112,11 +176,16 @@ describe Mysql2::Result do
|
|
112
176
|
@test_result['null_test'].should eql(nil)
|
113
177
|
end
|
114
178
|
|
115
|
-
it "should return
|
179
|
+
it "should return String for a BIT(64) value" do
|
116
180
|
@test_result['bit_test'].class.should eql(String)
|
117
181
|
@test_result['bit_test'].should eql("\000\000\000\000\000\000\000\005")
|
118
182
|
end
|
119
183
|
|
184
|
+
it "should return String for a BIT(1) value" do
|
185
|
+
@test_result['single_bit_test'].class.should eql(String)
|
186
|
+
@test_result['single_bit_test'].should eql("\001")
|
187
|
+
end
|
188
|
+
|
120
189
|
it "should return Fixnum for a TINYINT value" do
|
121
190
|
[Fixnum, Bignum].should include(@test_result['tiny_int_test'].class)
|
122
191
|
@test_result['tiny_int_test'].should eql(1)
|
@@ -127,11 +196,29 @@ describe Mysql2::Result do
|
|
127
196
|
id1 = @client.last_id
|
128
197
|
@client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (0)'
|
129
198
|
id2 = @client.last_id
|
199
|
+
@client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'
|
200
|
+
id3 = @client.last_id
|
130
201
|
|
131
202
|
result1 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1', :cast_booleans => true
|
132
203
|
result2 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 0 LIMIT 1', :cast_booleans => true
|
204
|
+
result3 = @client.query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = -1 LIMIT 1', :cast_booleans => true
|
133
205
|
result1.first['bool_cast_test'].should be_true
|
134
206
|
result2.first['bool_cast_test'].should be_false
|
207
|
+
result3.first['bool_cast_test'].should be_true
|
208
|
+
|
209
|
+
@client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})"
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
|
213
|
+
@client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)'
|
214
|
+
id1 = @client.last_id
|
215
|
+
@client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'
|
216
|
+
id2 = @client.last_id
|
217
|
+
|
218
|
+
result1 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id1}", :cast_booleans => true
|
219
|
+
result2 = @client.query "SELECT single_bit_test FROM mysql2_test WHERE id = #{id2}", :cast_booleans => true
|
220
|
+
result1.first['single_bit_test'].should be_true
|
221
|
+
result2.first['single_bit_test'].should be_false
|
135
222
|
|
136
223
|
@client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
|
137
224
|
end
|
@@ -182,7 +269,7 @@ describe Mysql2::Result do
|
|
182
269
|
end
|
183
270
|
|
184
271
|
if 1.size == 4 # 32bit
|
185
|
-
|
272
|
+
unless RUBY_VERSION =~ /1.8/
|
186
273
|
klass = Time
|
187
274
|
else
|
188
275
|
klass = DateTime
|
@@ -200,7 +287,7 @@ describe Mysql2::Result do
|
|
200
287
|
r.first['test'].class.should eql(klass)
|
201
288
|
end
|
202
289
|
elsif 1.size == 8 # 64bit
|
203
|
-
|
290
|
+
unless RUBY_VERSION =~ /1.8/
|
204
291
|
it "should return Time when timestamp is < 1901-12-13 20:45:52" do
|
205
292
|
r = @client.query("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test")
|
206
293
|
r.first['test'].class.should eql(Time)
|
@@ -248,26 +335,40 @@ describe Mysql2::Result do
|
|
248
335
|
@test_result['enum_test'].should eql('val1')
|
249
336
|
end
|
250
337
|
|
338
|
+
it "should raise an error given an invalid DATETIME" do
|
339
|
+
begin
|
340
|
+
@client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each
|
341
|
+
rescue Mysql2::Error => e
|
342
|
+
error = e
|
343
|
+
end
|
344
|
+
|
345
|
+
error.message.should eql("Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")
|
346
|
+
end
|
347
|
+
|
251
348
|
if defined? Encoding
|
252
349
|
context "string encoding for ENUM values" do
|
253
350
|
it "should default to the connection's encoding if Encoding.default_internal is nil" do
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
351
|
+
with_internal_encoding nil do
|
352
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
353
|
+
result['enum_test'].encoding.should eql(Encoding.find('utf-8'))
|
354
|
+
|
355
|
+
client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
|
356
|
+
result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
357
|
+
result['enum_test'].encoding.should eql(Encoding.find('us-ascii'))
|
358
|
+
client2.close
|
359
|
+
end
|
262
360
|
end
|
263
361
|
|
264
362
|
it "should use Encoding.default_internal" do
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
363
|
+
with_internal_encoding 'utf-8' do
|
364
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
365
|
+
result['enum_test'].encoding.should eql(Encoding.default_internal)
|
366
|
+
end
|
367
|
+
|
368
|
+
with_internal_encoding 'us-ascii' do
|
369
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
370
|
+
result['enum_test'].encoding.should eql(Encoding.default_internal)
|
371
|
+
end
|
271
372
|
end
|
272
373
|
end
|
273
374
|
end
|
@@ -280,23 +381,27 @@ describe Mysql2::Result do
|
|
280
381
|
if defined? Encoding
|
281
382
|
context "string encoding for SET values" do
|
282
383
|
it "should default to the connection's encoding if Encoding.default_internal is nil" do
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
384
|
+
with_internal_encoding nil do
|
385
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
386
|
+
result['set_test'].encoding.should eql(Encoding.find('utf-8'))
|
387
|
+
|
388
|
+
client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
|
389
|
+
result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
390
|
+
result['set_test'].encoding.should eql(Encoding.find('us-ascii'))
|
391
|
+
client2.close
|
392
|
+
end
|
291
393
|
end
|
292
394
|
|
293
395
|
it "should use Encoding.default_internal" do
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
396
|
+
with_internal_encoding 'utf-8' do
|
397
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
398
|
+
result['set_test'].encoding.should eql(Encoding.default_internal)
|
399
|
+
end
|
400
|
+
|
401
|
+
with_internal_encoding 'us-ascii' do
|
402
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
403
|
+
result['set_test'].encoding.should eql(Encoding.default_internal)
|
404
|
+
end
|
300
405
|
end
|
301
406
|
end
|
302
407
|
end
|
@@ -309,18 +414,22 @@ describe Mysql2::Result do
|
|
309
414
|
if defined? Encoding
|
310
415
|
context "string encoding for BINARY values" do
|
311
416
|
it "should default to binary if Encoding.default_internal is nil" do
|
312
|
-
|
313
|
-
|
314
|
-
|
417
|
+
with_internal_encoding nil do
|
418
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
419
|
+
result['binary_test'].encoding.should eql(Encoding.find('binary'))
|
420
|
+
end
|
315
421
|
end
|
316
422
|
|
317
423
|
it "should not use Encoding.default_internal" do
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
424
|
+
with_internal_encoding 'utf-8' do
|
425
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
426
|
+
result['binary_test'].encoding.should eql(Encoding.find('binary'))
|
427
|
+
end
|
428
|
+
|
429
|
+
with_internal_encoding 'us-ascii' do
|
430
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
431
|
+
result['binary_test'].encoding.should eql(Encoding.find('binary'))
|
432
|
+
end
|
324
433
|
end
|
325
434
|
end
|
326
435
|
end
|
@@ -347,38 +456,46 @@ describe Mysql2::Result do
|
|
347
456
|
context "string encoding for #{type} values" do
|
348
457
|
if ['VARBINARY', 'TINYBLOB', 'BLOB', 'MEDIUMBLOB', 'LONGBLOB'].include?(type)
|
349
458
|
it "should default to binary if Encoding.default_internal is nil" do
|
350
|
-
|
351
|
-
|
352
|
-
|
459
|
+
with_internal_encoding nil do
|
460
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
461
|
+
result['binary_test'].encoding.should eql(Encoding.find('binary'))
|
462
|
+
end
|
353
463
|
end
|
354
464
|
|
355
465
|
it "should not use Encoding.default_internal" do
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
466
|
+
with_internal_encoding 'utf-8' do
|
467
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
468
|
+
result['binary_test'].encoding.should eql(Encoding.find('binary'))
|
469
|
+
end
|
470
|
+
|
471
|
+
with_internal_encoding 'us-ascii' do
|
472
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
473
|
+
result['binary_test'].encoding.should eql(Encoding.find('binary'))
|
474
|
+
end
|
362
475
|
end
|
363
476
|
else
|
364
477
|
it "should default to utf-8 if Encoding.default_internal is nil" do
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
478
|
+
with_internal_encoding nil do
|
479
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
480
|
+
result[field].encoding.should eql(Encoding.find('utf-8'))
|
481
|
+
|
482
|
+
client2 = Mysql2::Client.new(DatabaseCredentials['root'].merge(:encoding => 'ascii'))
|
483
|
+
result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
484
|
+
result[field].encoding.should eql(Encoding.find('us-ascii'))
|
485
|
+
client2.close
|
486
|
+
end
|
373
487
|
end
|
374
488
|
|
375
489
|
it "should use Encoding.default_internal" do
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
490
|
+
with_internal_encoding 'utf-8' do
|
491
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
492
|
+
result[field].encoding.should eql(Encoding.default_internal)
|
493
|
+
end
|
494
|
+
|
495
|
+
with_internal_encoding 'us-ascii' do
|
496
|
+
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
497
|
+
result[field].encoding.should eql(Encoding.default_internal)
|
498
|
+
end
|
382
499
|
end
|
383
500
|
end
|
384
501
|
end
|