mysql2 0.4.10-x64-mingw32 → 0.5.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +19 -6
- data/examples/eventmachine.rb +0 -2
- data/examples/threaded.rb +2 -4
- data/ext/mysql2/client.c +100 -51
- data/ext/mysql2/client.h +1 -39
- data/ext/mysql2/extconf.rb +22 -20
- data/ext/mysql2/mysql2_ext.c +2 -1
- data/ext/mysql2/mysql2_ext.h +8 -4
- data/ext/mysql2/result.c +15 -75
- data/ext/mysql2/result.h +2 -3
- data/ext/mysql2/statement.c +51 -66
- data/ext/mysql2/statement.h +0 -2
- data/ext/mysql2/wait_for_single_fd.h +2 -1
- data/lib/mysql2.rb +14 -15
- data/lib/mysql2/2.0/mysql2.so +0 -0
- data/lib/mysql2/2.1/mysql2.so +0 -0
- data/lib/mysql2/2.2/mysql2.so +0 -0
- data/lib/mysql2/2.3/mysql2.so +0 -0
- data/lib/mysql2/2.4/mysql2.so +0 -0
- data/lib/mysql2/2.5/mysql2.so +0 -0
- data/lib/mysql2/client.rb +33 -27
- data/lib/mysql2/em.rb +2 -4
- data/lib/mysql2/error.rb +49 -20
- data/lib/mysql2/mysql2.rb +0 -2
- data/lib/mysql2/result.rb +2 -0
- data/lib/mysql2/statement.rb +3 -9
- data/lib/mysql2/version.rb +1 -1
- data/spec/em/em_spec.rb +5 -6
- data/spec/mysql2/client_spec.rb +206 -173
- data/spec/mysql2/error_spec.rb +0 -4
- data/spec/mysql2/result_spec.rb +94 -154
- data/spec/mysql2/statement_spec.rb +101 -169
- data/spec/spec_helper.rb +6 -2
- data/support/mysql_enc_to_ruby.rb +2 -2
- data/support/ruby_enc_to_mysql.rb +5 -5
- data/vendor/README +8 -2
- metadata +10 -5
@@ -1,9 +1,8 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require './spec/spec_helper.rb'
|
3
2
|
|
4
3
|
RSpec.describe Mysql2::Statement do
|
5
4
|
before :each do
|
6
|
-
@client = new_client(:
|
5
|
+
@client = new_client(encoding: "utf8")
|
7
6
|
end
|
8
7
|
|
9
8
|
def stmt_count
|
@@ -87,6 +86,20 @@ RSpec.describe Mysql2::Statement do
|
|
87
86
|
expect(result.to_a).to eq(['max1' => int64_max1, 'max2' => int64_max2, 'max3' => int64_max3, 'min1' => int64_min1, 'min2' => int64_min2, 'min3' => int64_min3])
|
88
87
|
end
|
89
88
|
|
89
|
+
it "should accept keyword arguments on statement execute" do
|
90
|
+
stmt = @client.prepare 'SELECT 1 AS a'
|
91
|
+
|
92
|
+
expect(stmt.execute(as: :hash).first).to eq("a" => 1)
|
93
|
+
expect(stmt.execute(as: :array).first).to eq([1])
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should accept bind arguments and keyword arguments on statement execute" do
|
97
|
+
stmt = @client.prepare 'SELECT ? AS a'
|
98
|
+
|
99
|
+
expect(stmt.execute(1, as: :hash).first).to eq("a" => 1)
|
100
|
+
expect(stmt.execute(1, as: :array).first).to eq([1])
|
101
|
+
end
|
102
|
+
|
90
103
|
it "should keep its result after other query" do
|
91
104
|
@client.query 'USE test'
|
92
105
|
@client.query 'CREATE TABLE IF NOT EXISTS mysql2_stmt_q(a int)'
|
@@ -147,24 +160,16 @@ RSpec.describe Mysql2::Statement do
|
|
147
160
|
now = Time.now
|
148
161
|
statement = @client.prepare('SELECT ? AS a')
|
149
162
|
result = statement.execute(now)
|
150
|
-
|
151
|
-
|
152
|
-
else
|
153
|
-
# microseconds is six digits after the decimal, but only test on 5 significant figures
|
154
|
-
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
|
155
|
-
end
|
163
|
+
# microseconds is six digits after the decimal, but only test on 5 significant figures
|
164
|
+
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
|
156
165
|
end
|
157
166
|
|
158
167
|
it "should prepare DateTime values with microseconds" do
|
159
168
|
now = DateTime.now
|
160
169
|
statement = @client.prepare('SELECT ? AS a')
|
161
170
|
result = statement.execute(now)
|
162
|
-
|
163
|
-
|
164
|
-
else
|
165
|
-
# microseconds is six digits after the decimal, but only test on 5 significant figures
|
166
|
-
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
|
167
|
-
end
|
171
|
+
# microseconds is six digits after the decimal, but only test on 5 significant figures
|
172
|
+
expect(result.first['a'].strftime('%F %T.%5N %z')).to eql(now.strftime('%F %T.%5N %z'))
|
168
173
|
end
|
169
174
|
|
170
175
|
it "should tell us about the fields" do
|
@@ -178,7 +183,7 @@ RSpec.describe Mysql2::Statement do
|
|
178
183
|
|
179
184
|
it "should handle as a decimal binding a BigDecimal" do
|
180
185
|
stmt = @client.prepare('SELECT ? AS decimal_test')
|
181
|
-
test_result = stmt.execute(BigDecimal
|
186
|
+
test_result = stmt.execute(BigDecimal("123.45")).first
|
182
187
|
expect(test_result['decimal_test']).to be_an_instance_of(BigDecimal)
|
183
188
|
expect(test_result['decimal_test']).to eql(123.45)
|
184
189
|
end
|
@@ -188,17 +193,16 @@ RSpec.describe Mysql2::Statement do
|
|
188
193
|
@client.query 'DROP TABLE IF EXISTS mysql2_stmt_decimal_test'
|
189
194
|
@client.query 'CREATE TABLE mysql2_stmt_decimal_test (decimal_test DECIMAL(10,3))'
|
190
195
|
|
191
|
-
@client.prepare("INSERT INTO mysql2_stmt_decimal_test VALUES (?)").execute(BigDecimal
|
196
|
+
@client.prepare("INSERT INTO mysql2_stmt_decimal_test VALUES (?)").execute(BigDecimal("123.45"))
|
192
197
|
|
193
198
|
test_result = @client.query("SELECT * FROM mysql2_stmt_decimal_test").first
|
194
199
|
expect(test_result['decimal_test']).to eql(123.45)
|
195
200
|
end
|
196
201
|
|
197
202
|
it "should warn but still work if cache_rows is set to false" do
|
198
|
-
@client.query_options.merge!(:cache_rows => false)
|
199
203
|
statement = @client.prepare 'SELECT 1'
|
200
204
|
result = nil
|
201
|
-
expect { result = statement.execute.to_a }.to output(/:cache_rows is forced for prepared statements/).to_stderr
|
205
|
+
expect { result = statement.execute(cache_rows: false).to_a }.to output(/:cache_rows is forced for prepared statements/).to_stderr
|
202
206
|
expect(result.length).to eq(1)
|
203
207
|
end
|
204
208
|
|
@@ -217,7 +221,7 @@ RSpec.describe Mysql2::Statement do
|
|
217
221
|
|
218
222
|
it "should be able to retrieve utf8 field names correctly" do
|
219
223
|
stmt = @client.prepare 'SELECT * FROM `テーブル`'
|
220
|
-
expect(stmt.fields).to eq(%w
|
224
|
+
expect(stmt.fields).to eq(%w[整数 文字列])
|
221
225
|
result = stmt.execute
|
222
226
|
|
223
227
|
expect(result.to_a).to eq([{ "整数" => 1, "文字列" => "イチ" }, { "整数" => 2, "文字列" => "弐" }, { "整数" => 3, "文字列" => "さん" }])
|
@@ -241,16 +245,13 @@ RSpec.describe Mysql2::Statement do
|
|
241
245
|
|
242
246
|
expect(result.to_a).to eq([{ "整数" => 1 }])
|
243
247
|
end
|
244
|
-
end
|
248
|
+
end
|
245
249
|
|
246
250
|
context "streaming result" do
|
247
251
|
it "should be able to stream query result" do
|
248
252
|
n = 1
|
249
253
|
stmt = @client.prepare("SELECT 1 UNION SELECT 2")
|
250
|
-
|
251
|
-
@client.query_options.merge!(:stream => true, :cache_rows => false, :as => :array)
|
252
|
-
|
253
|
-
stmt.execute.each do |r|
|
254
|
+
stmt.execute(stream: true, cache_rows: false, as: :array).each do |r|
|
254
255
|
case n
|
255
256
|
when 1
|
256
257
|
expect(r).to eq([1])
|
@@ -276,23 +277,17 @@ RSpec.describe Mysql2::Statement do
|
|
276
277
|
end
|
277
278
|
|
278
279
|
it "should yield rows as hash's with symbol keys if :symbolize_keys was set to true" do
|
279
|
-
@client.
|
280
|
-
@result = @client.prepare("SELECT 1").execute
|
280
|
+
@result = @client.prepare("SELECT 1").execute(symbolize_keys: true)
|
281
281
|
@result.each do |row|
|
282
282
|
expect(row.keys.first).to be_an_instance_of(Symbol)
|
283
283
|
end
|
284
|
-
@client.query_options[:symbolize_keys] = false
|
285
284
|
end
|
286
285
|
|
287
286
|
it "should be able to return results as an array" do
|
288
|
-
@client.
|
289
|
-
|
290
|
-
@result = @client.prepare("SELECT 1").execute
|
287
|
+
@result = @client.prepare("SELECT 1").execute(as: :array)
|
291
288
|
@result.each do |row|
|
292
289
|
expect(row).to be_an_instance_of(Array)
|
293
290
|
end
|
294
|
-
|
295
|
-
@client.query_options[:as] = :hash
|
296
291
|
end
|
297
292
|
|
298
293
|
it "should cache previously yielded results by default" do
|
@@ -301,35 +296,21 @@ RSpec.describe Mysql2::Statement do
|
|
301
296
|
end
|
302
297
|
|
303
298
|
it "should yield different value for #first if streaming" do
|
304
|
-
@client.
|
305
|
-
@client.query_options[:cache_rows] = false
|
306
|
-
|
307
|
-
result = @client.prepare("SELECT 1 UNION SELECT 2").execute
|
299
|
+
result = @client.prepare("SELECT 1 UNION SELECT 2").execute(stream: true, cache_rows: true)
|
308
300
|
expect(result.first).not_to eql(result.first)
|
309
|
-
|
310
|
-
@client.query_options[:stream] = false
|
311
|
-
@client.query_options[:cache_rows] = true
|
312
301
|
end
|
313
302
|
|
314
303
|
it "should yield the same value for #first if streaming is disabled" do
|
315
|
-
@client.
|
316
|
-
result = @client.prepare("SELECT 1 UNION SELECT 2").execute
|
304
|
+
result = @client.prepare("SELECT 1 UNION SELECT 2").execute(stream: false)
|
317
305
|
expect(result.first).to eql(result.first)
|
318
306
|
end
|
319
307
|
|
320
308
|
it "should throw an exception if we try to iterate twice when streaming is enabled" do
|
321
|
-
@client.
|
322
|
-
|
323
|
-
|
324
|
-
result = @client.prepare("SELECT 1 UNION SELECT 2").execute
|
325
|
-
|
326
|
-
expect {
|
309
|
+
result = @client.prepare("SELECT 1 UNION SELECT 2").execute(stream: true, cache_rows: false)
|
310
|
+
expect do
|
327
311
|
result.each {}
|
328
312
|
result.each {}
|
329
|
-
|
330
|
-
|
331
|
-
@client.query_options[:stream] = false
|
332
|
-
@client.query_options[:cache_rows] = true
|
313
|
+
end.to raise_exception(Mysql2::Error)
|
333
314
|
end
|
334
315
|
end
|
335
316
|
|
@@ -341,7 +322,7 @@ RSpec.describe Mysql2::Statement do
|
|
341
322
|
|
342
323
|
it "should return an array of field names in proper order" do
|
343
324
|
stmt = @client.prepare("SELECT 'a', 'b', 'c'")
|
344
|
-
expect(stmt.fields).to eql(%w
|
325
|
+
expect(stmt.fields).to eql(%w[a b c])
|
345
326
|
end
|
346
327
|
|
347
328
|
it "should return nil for statement with no result fields" do
|
@@ -351,48 +332,44 @@ RSpec.describe Mysql2::Statement do
|
|
351
332
|
end
|
352
333
|
|
353
334
|
context "row data type mapping" do
|
354
|
-
|
355
|
-
@client.query "USE test"
|
356
|
-
@test_result = @client.prepare("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").execute.first
|
357
|
-
end
|
335
|
+
let(:test_result) { @client.prepare("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").execute.first }
|
358
336
|
|
359
337
|
it "should return nil for a NULL value" do
|
360
|
-
expect(
|
361
|
-
expect(
|
338
|
+
expect(test_result['null_test']).to be_an_instance_of(NilClass)
|
339
|
+
expect(test_result['null_test']).to eql(nil)
|
362
340
|
end
|
363
341
|
|
364
342
|
it "should return String for a BIT(64) value" do
|
365
|
-
expect(
|
366
|
-
expect(
|
343
|
+
expect(test_result['bit_test']).to be_an_instance_of(String)
|
344
|
+
expect(test_result['bit_test']).to eql("\000\000\000\000\000\000\000\005")
|
367
345
|
end
|
368
346
|
|
369
347
|
it "should return String for a BIT(1) value" do
|
370
|
-
expect(
|
371
|
-
expect(
|
348
|
+
expect(test_result['single_bit_test']).to be_an_instance_of(String)
|
349
|
+
expect(test_result['single_bit_test']).to eql("\001")
|
372
350
|
end
|
373
351
|
|
374
352
|
it "should return Fixnum for a TINYINT value" do
|
375
|
-
expect(
|
376
|
-
expect(
|
353
|
+
expect(num_classes).to include(test_result['tiny_int_test'].class)
|
354
|
+
expect(test_result['tiny_int_test']).to eql(1)
|
377
355
|
end
|
378
356
|
|
379
357
|
context "cast booleans for TINYINT if :cast_booleans is enabled" do
|
380
358
|
# rubocop:disable Style/Semicolon
|
381
|
-
let(:
|
382
|
-
let(:
|
383
|
-
let(:
|
384
|
-
let(:id3) { client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'; client.last_id }
|
359
|
+
let(:id1) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 1)'; @client.last_id }
|
360
|
+
let(:id2) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 0)'; @client.last_id }
|
361
|
+
let(:id3) { @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'; @client.last_id }
|
385
362
|
# rubocop:enable Style/Semicolon
|
386
363
|
|
387
364
|
after do
|
388
|
-
client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})"
|
365
|
+
@client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2},#{id3})"
|
389
366
|
end
|
390
367
|
|
391
368
|
it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
|
392
|
-
query = client.prepare 'SELECT bool_cast_test FROM mysql2_test WHERE id = ?'
|
393
|
-
result1 = query.execute id1
|
394
|
-
result2 = query.execute id2
|
395
|
-
result3 = query.execute id3
|
369
|
+
query = @client.prepare 'SELECT bool_cast_test FROM mysql2_test WHERE id = ?'
|
370
|
+
result1 = query.execute id1, cast_booleans: true
|
371
|
+
result2 = query.execute id2, cast_booleans: true
|
372
|
+
result3 = query.execute id3, cast_booleans: true
|
396
373
|
expect(result1.first['bool_cast_test']).to be true
|
397
374
|
expect(result2.first['bool_cast_test']).to be false
|
398
375
|
expect(result3.first['bool_cast_test']).to be true
|
@@ -401,134 +378,96 @@ RSpec.describe Mysql2::Statement do
|
|
401
378
|
|
402
379
|
context "cast booleans for BIT(1) if :cast_booleans is enabled" do
|
403
380
|
# rubocop:disable Style/Semicolon
|
404
|
-
let(:
|
405
|
-
let(:
|
406
|
-
let(:id2) { client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'; client.last_id }
|
381
|
+
let(:id1) { @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)'; @client.last_id }
|
382
|
+
let(:id2) { @client.query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'; @client.last_id }
|
407
383
|
# rubocop:enable Style/Semicolon
|
408
384
|
|
409
385
|
after do
|
410
|
-
client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
|
386
|
+
@client.query "DELETE from mysql2_test WHERE id IN(#{id1},#{id2})"
|
411
387
|
end
|
412
388
|
|
413
389
|
it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
|
414
|
-
query = client.prepare 'SELECT single_bit_test FROM mysql2_test WHERE id = ?'
|
415
|
-
result1 = query.execute id1
|
416
|
-
result2 = query.execute id2
|
390
|
+
query = @client.prepare 'SELECT single_bit_test FROM mysql2_test WHERE id = ?'
|
391
|
+
result1 = query.execute id1, cast_booleans: true
|
392
|
+
result2 = query.execute id2, cast_booleans: true
|
417
393
|
expect(result1.first['single_bit_test']).to be true
|
418
394
|
expect(result2.first['single_bit_test']).to be false
|
419
395
|
end
|
420
396
|
end
|
421
397
|
|
422
398
|
it "should return Fixnum for a SMALLINT value" do
|
423
|
-
expect(
|
424
|
-
expect(
|
399
|
+
expect(num_classes).to include(test_result['small_int_test'].class)
|
400
|
+
expect(test_result['small_int_test']).to eql(10)
|
425
401
|
end
|
426
402
|
|
427
403
|
it "should return Fixnum for a MEDIUMINT value" do
|
428
|
-
expect(
|
429
|
-
expect(
|
404
|
+
expect(num_classes).to include(test_result['medium_int_test'].class)
|
405
|
+
expect(test_result['medium_int_test']).to eql(10)
|
430
406
|
end
|
431
407
|
|
432
408
|
it "should return Fixnum for an INT value" do
|
433
|
-
expect(
|
434
|
-
expect(
|
409
|
+
expect(num_classes).to include(test_result['int_test'].class)
|
410
|
+
expect(test_result['int_test']).to eql(10)
|
435
411
|
end
|
436
412
|
|
437
413
|
it "should return Fixnum for a BIGINT value" do
|
438
|
-
expect(
|
439
|
-
expect(
|
414
|
+
expect(num_classes).to include(test_result['big_int_test'].class)
|
415
|
+
expect(test_result['big_int_test']).to eql(10)
|
440
416
|
end
|
441
417
|
|
442
418
|
it "should return Fixnum for a YEAR value" do
|
443
|
-
expect(
|
444
|
-
expect(
|
419
|
+
expect(num_classes).to include(test_result['year_test'].class)
|
420
|
+
expect(test_result['year_test']).to eql(2009)
|
445
421
|
end
|
446
422
|
|
447
423
|
it "should return BigDecimal for a DECIMAL value" do
|
448
|
-
expect(
|
449
|
-
expect(
|
424
|
+
expect(test_result['decimal_test']).to be_an_instance_of(BigDecimal)
|
425
|
+
expect(test_result['decimal_test']).to eql(10.3)
|
450
426
|
end
|
451
427
|
|
452
428
|
it "should return Float for a FLOAT value" do
|
453
|
-
expect(
|
454
|
-
expect(
|
429
|
+
expect(test_result['float_test']).to be_an_instance_of(Float)
|
430
|
+
expect(test_result['float_test']).to be_within(1e-5).of(10.3)
|
455
431
|
end
|
456
432
|
|
457
433
|
it "should return Float for a DOUBLE value" do
|
458
|
-
expect(
|
459
|
-
expect(
|
434
|
+
expect(test_result['double_test']).to be_an_instance_of(Float)
|
435
|
+
expect(test_result['double_test']).to eql(10.3)
|
460
436
|
end
|
461
437
|
|
462
438
|
it "should return Time for a DATETIME value when within the supported range" do
|
463
|
-
expect(
|
464
|
-
expect(
|
439
|
+
expect(test_result['date_time_test']).to be_an_instance_of(Time)
|
440
|
+
expect(test_result['date_time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
|
465
441
|
end
|
466
442
|
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
Time
|
472
|
-
end
|
473
|
-
|
474
|
-
it "should return DateTime when timestamp is < 1901-12-13 20:45:52" do
|
475
|
-
# 1901-12-13T20:45:52 is the min for 32bit Ruby 1.8
|
476
|
-
r = @client.prepare("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test").execute
|
477
|
-
expect(r.first['test']).to be_an_instance_of(klass)
|
478
|
-
end
|
479
|
-
|
480
|
-
it "should return DateTime when timestamp is > 2038-01-19T03:14:07" do
|
481
|
-
# 2038-01-19T03:14:07 is the max for 32bit Ruby 1.8
|
482
|
-
r = @client.prepare("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test").execute
|
483
|
-
expect(r.first['test']).to be_an_instance_of(klass)
|
484
|
-
end
|
485
|
-
elsif 1.size == 8 # 64bit
|
486
|
-
if RUBY_VERSION =~ /1.8/
|
487
|
-
it "should return Time when timestamp is > 0138-12-31 11:59:59" do
|
488
|
-
r = @client.prepare("SELECT CAST('0139-1-1 00:00:00' AS DATETIME) as test").execute
|
489
|
-
expect(r.first['test']).to be_an_instance_of(Time)
|
490
|
-
end
|
491
|
-
|
492
|
-
it "should return DateTime when timestamp is < 0139-1-1T00:00:00" do
|
493
|
-
r = @client.prepare("SELECT CAST('0138-12-31 11:59:59' AS DATETIME) as test").execute
|
494
|
-
expect(r.first['test']).to be_an_instance_of(DateTime)
|
495
|
-
end
|
496
|
-
|
497
|
-
it "should return Time when timestamp is > 2038-01-19T03:14:07" do
|
498
|
-
r = @client.prepare("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test").execute
|
499
|
-
expect(r.first['test']).to be_an_instance_of(Time)
|
500
|
-
end
|
501
|
-
else
|
502
|
-
it "should return Time when timestamp is < 1901-12-13 20:45:52" do
|
503
|
-
r = @client.prepare("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test").execute
|
504
|
-
expect(r.first['test']).to be_an_instance_of(Time)
|
505
|
-
end
|
443
|
+
it "should return Time when timestamp is < 1901-12-13 20:45:52" do
|
444
|
+
r = @client.prepare("SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test").execute
|
445
|
+
expect(r.first['test']).to be_an_instance_of(Time)
|
446
|
+
end
|
506
447
|
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
end
|
511
|
-
end
|
448
|
+
it "should return Time when timestamp is > 2038-01-19T03:14:07" do
|
449
|
+
r = @client.prepare("SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test").execute
|
450
|
+
expect(r.first['test']).to be_an_instance_of(Time)
|
512
451
|
end
|
513
452
|
|
514
453
|
it "should return Time for a TIMESTAMP value when within the supported range" do
|
515
|
-
expect(
|
516
|
-
expect(
|
454
|
+
expect(test_result['timestamp_test']).to be_an_instance_of(Time)
|
455
|
+
expect(test_result['timestamp_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2010-04-04 11:44:00')
|
517
456
|
end
|
518
457
|
|
519
458
|
it "should return Time for a TIME value" do
|
520
|
-
expect(
|
521
|
-
expect(
|
459
|
+
expect(test_result['time_test']).to be_an_instance_of(Time)
|
460
|
+
expect(test_result['time_test'].strftime("%Y-%m-%d %H:%M:%S")).to eql('2000-01-01 11:44:00')
|
522
461
|
end
|
523
462
|
|
524
463
|
it "should return Date for a DATE value" do
|
525
|
-
expect(
|
526
|
-
expect(
|
464
|
+
expect(test_result['date_test']).to be_an_instance_of(Date)
|
465
|
+
expect(test_result['date_test'].strftime("%Y-%m-%d")).to eql('2010-04-04')
|
527
466
|
end
|
528
467
|
|
529
468
|
it "should return String for an ENUM value" do
|
530
|
-
expect(
|
531
|
-
expect(
|
469
|
+
expect(test_result['enum_test']).to be_an_instance_of(String)
|
470
|
+
expect(test_result['enum_test']).to eql('val1')
|
532
471
|
end
|
533
472
|
|
534
473
|
it "should raise an error given an invalid DATETIME" do
|
@@ -537,14 +476,12 @@ RSpec.describe Mysql2::Statement do
|
|
537
476
|
end
|
538
477
|
|
539
478
|
context "string encoding for ENUM values" do
|
540
|
-
before { pending('Encoding is undefined') unless defined?(Encoding) }
|
541
|
-
|
542
479
|
it "should default to the connection's encoding if Encoding.default_internal is nil" do
|
543
480
|
with_internal_encoding nil do
|
544
481
|
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
545
482
|
expect(result['enum_test'].encoding).to eql(Encoding::UTF_8)
|
546
483
|
|
547
|
-
client2 = new_client(:
|
484
|
+
client2 = new_client(encoding: 'ascii')
|
548
485
|
result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
549
486
|
expect(result['enum_test'].encoding).to eql(Encoding::US_ASCII)
|
550
487
|
end
|
@@ -564,19 +501,17 @@ RSpec.describe Mysql2::Statement do
|
|
564
501
|
end
|
565
502
|
|
566
503
|
it "should return String for a SET value" do
|
567
|
-
expect(
|
568
|
-
expect(
|
504
|
+
expect(test_result['set_test']).to be_an_instance_of(String)
|
505
|
+
expect(test_result['set_test']).to eql('val1,val2')
|
569
506
|
end
|
570
507
|
|
571
508
|
context "string encoding for SET values" do
|
572
|
-
before { pending('Encoding is undefined') unless defined?(Encoding) }
|
573
|
-
|
574
509
|
it "should default to the connection's encoding if Encoding.default_internal is nil" do
|
575
510
|
with_internal_encoding nil do
|
576
511
|
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
577
512
|
expect(result['set_test'].encoding).to eql(Encoding::UTF_8)
|
578
513
|
|
579
|
-
client2 = new_client(:
|
514
|
+
client2 = new_client(encoding: 'ascii')
|
580
515
|
result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
581
516
|
expect(result['set_test'].encoding).to eql(Encoding::US_ASCII)
|
582
517
|
end
|
@@ -596,13 +531,11 @@ RSpec.describe Mysql2::Statement do
|
|
596
531
|
end
|
597
532
|
|
598
533
|
it "should return String for a BINARY value" do
|
599
|
-
expect(
|
600
|
-
expect(
|
534
|
+
expect(test_result['binary_test']).to be_an_instance_of(String)
|
535
|
+
expect(test_result['binary_test']).to eql("test#{"\000" * 6}")
|
601
536
|
end
|
602
537
|
|
603
538
|
context "string encoding for BINARY values" do
|
604
|
-
before { pending('Encoding is undefined') unless defined?(Encoding) }
|
605
|
-
|
606
539
|
it "should default to binary if Encoding.default_internal is nil" do
|
607
540
|
with_internal_encoding nil do
|
608
541
|
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
@@ -637,14 +570,12 @@ RSpec.describe Mysql2::Statement do
|
|
637
570
|
'long_text_test' => 'LONGTEXT',
|
638
571
|
}.each do |field, type|
|
639
572
|
it "should return a String for #{type}" do
|
640
|
-
expect(
|
641
|
-
expect(
|
573
|
+
expect(test_result[field]).to be_an_instance_of(String)
|
574
|
+
expect(test_result[field]).to eql("test")
|
642
575
|
end
|
643
576
|
|
644
577
|
context "string encoding for #{type} values" do
|
645
|
-
|
646
|
-
|
647
|
-
if %w(VARBINARY TINYBLOB BLOB MEDIUMBLOB LONGBLOB).include?(type)
|
578
|
+
if %w[VARBINARY TINYBLOB BLOB MEDIUMBLOB LONGBLOB].include?(type)
|
648
579
|
it "should default to binary if Encoding.default_internal is nil" do
|
649
580
|
with_internal_encoding nil do
|
650
581
|
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
@@ -669,7 +600,7 @@ RSpec.describe Mysql2::Statement do
|
|
669
600
|
result = @client.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
670
601
|
expect(result[field].encoding).to eql(Encoding::UTF_8)
|
671
602
|
|
672
|
-
client2 = new_client(:
|
603
|
+
client2 = new_client(encoding: 'ascii')
|
673
604
|
result = client2.query("SELECT * FROM mysql2_test ORDER BY id DESC LIMIT 1").first
|
674
605
|
expect(result[field].encoding).to eql(Encoding::US_ASCII)
|
675
606
|
end
|
@@ -731,7 +662,6 @@ RSpec.describe Mysql2::Statement do
|
|
731
662
|
|
732
663
|
it 'should return number of rows affected by an insert' do
|
733
664
|
stmt = @client.prepare 'INSERT INTO lastIdTest (blah) VALUES (?)'
|
734
|
-
expect(stmt.affected_rows).to eq 0
|
735
665
|
stmt.execute 1
|
736
666
|
expect(stmt.affected_rows).to eq 1
|
737
667
|
end
|
@@ -764,7 +694,9 @@ RSpec.describe Mysql2::Statement do
|
|
764
694
|
context 'close' do
|
765
695
|
it 'should free server resources' do
|
766
696
|
stmt = @client.prepare 'SELECT 1'
|
697
|
+
GC.disable
|
767
698
|
expect { stmt.close }.to change(&method(:stmt_count)).by(-1)
|
699
|
+
GC.enable
|
768
700
|
end
|
769
701
|
|
770
702
|
it 'should raise an error on subsequent execution' do
|