@@ -374,36 +374,47 @@ def stmt_count
374
374
expect ( @test_result [ 'tiny_int_test' ] ) . to eql ( 1 )
375
375
end
376
376
377
- it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
378
- @client . query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (1)'
379
- id1 = @client . last_id
380
- @client . query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (0)'
381
- id2 = @client . last_id
382
- @client . query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)'
383
- id3 = @client . last_id
384
-
385
- result1 = @client . query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 1 LIMIT 1' , :cast_booleans => true
386
- result2 = @client . query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = 0 LIMIT 1' , :cast_booleans => true
387
- result3 = @client . query 'SELECT bool_cast_test FROM mysql2_test WHERE bool_cast_test = -1 LIMIT 1' , :cast_booleans => true
388
- expect ( result1 . first [ 'bool_cast_test' ] ) . to be true
389
- expect ( result2 . first [ 'bool_cast_test' ] ) . to be false
390
- expect ( result3 . first [ 'bool_cast_test' ] ) . to be true
377
+ context "cast booleans for TINYINY if :cast_booleans is enabled" do
378
+ # rubocop:disable Style/Semicolon
379
+ let ( :client ) { new_client ( :cast_booleans => true ) }
380
+ let ( :id1 ) { client . query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 1)' ; client . last_id }
381
+ let ( :id2 ) { client . query 'INSERT INTO mysql2_test (bool_cast_test) VALUES ( 0)' ; client . last_id }
382
+ let ( :id3 ) { client . query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (-1)' ; client . last_id }
383
+ # rubocop:enable Style/Semicolon
384
+
385
+ after do
386
+ client . query "DELETE from mysql2_test WHERE id IN(#{ id1 } ,#{ id2 } ,#{ id3 } )"
387
+ end
391
388
392
- @client . query "DELETE from mysql2_test WHERE id IN(#{ id1 } ,#{ id2 } ,#{ id3 } )"
389
+ it "should return TrueClass or FalseClass for a TINYINT value if :cast_booleans is enabled" do
390
+ query = client . prepare 'SELECT bool_cast_test FROM mysql2_test WHERE id = ?'
391
+ result1 = query . execute id1
392
+ result2 = query . execute id2
393
+ result3 = query . execute id3
394
+ expect ( result1 . first [ 'bool_cast_test' ] ) . to be true
395
+ expect ( result2 . first [ 'bool_cast_test' ] ) . to be false
396
+ expect ( result3 . first [ 'bool_cast_test' ] ) . to be true
397
+ end
393
398
end
394
399
395
- it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
396
- @client . query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)'
397
- id1 = @client . last_id
398
- @client . query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)'
399
- id2 = @client . last_id
400
+ context "cast booleans for BIT(1) if :cast_booleans is enabled" do
401
+ # rubocop:disable Style/Semicolon
402
+ let ( :client ) { new_client ( :cast_booleans => true ) }
403
+ let ( :id1 ) { client . query 'INSERT INTO mysql2_test (single_bit_test) VALUES (1)' ; client . last_id }
404
+ let ( :id2 ) { client . query 'INSERT INTO mysql2_test (single_bit_test) VALUES (0)' ; client . last_id }
405
+ # rubocop:enable Style/Semicolon
400
406
401
- result1 = @client . query "SELECT single_bit_test FROM mysql2_test WHERE id = #{ id1 } " , :cast_booleans => true
402
- result2 = @client . query "SELECT single_bit_test FROM mysql2_test WHERE id = #{ id2 } " , :cast_booleans => true
403
- expect ( result1 . first [ 'single_bit_test' ] ) . to be true
404
- expect ( result2 . first [ 'single_bit_test' ] ) . to be false
407
+ after do
408
+ client . query "DELETE from mysql2_test WHERE id IN(#{ id1 } ,#{ id2 } )"
409
+ end
405
410
406
- @client . query "DELETE from mysql2_test WHERE id IN(#{ id1 } ,#{ id2 } )"
411
+ it "should return TrueClass or FalseClass for a BIT(1) value if :cast_booleans is enabled" do
412
+ query = client . prepare 'SELECT single_bit_test FROM mysql2_test WHERE id = ?'
413
+ result1 = query . execute id1
414
+ result2 = query . execute id2
415
+ expect ( result1 . first [ 'single_bit_test' ] ) . to be true
416
+ expect ( result2 . first [ 'single_bit_test' ] ) . to be false
417
+ end
407
418
end
408
419
409
420
it "should return Fixnum for a SMALLINT value" do
@@ -460,39 +471,39 @@ def stmt_count
460
471
461
472
it "should return DateTime when timestamp is < 1901-12-13 20:45:52" do
462
473
# 1901-12-13T20:45:52 is the min for 32bit Ruby 1.8
463
- r = @client . query ( "SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test" )
474
+ r = @client . prepare ( "SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test" ) . execute
464
475
expect ( r . first [ 'test' ] ) . to be_an_instance_of ( klass )
465
476
end
466
477
467
478
it "should return DateTime when timestamp is > 2038-01-19T03:14:07" do
468
479
# 2038-01-19T03:14:07 is the max for 32bit Ruby 1.8
469
- r = @client . query ( "SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test" )
480
+ r = @client . prepare ( "SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test" ) . execute
470
481
expect ( r . first [ 'test' ] ) . to be_an_instance_of ( klass )
471
482
end
472
483
elsif 1 . size == 8 # 64bit
473
484
if RUBY_VERSION =~ /1.8/
474
485
it "should return Time when timestamp is > 0138-12-31 11:59:59" do
475
- r = @client . query ( "SELECT CAST('0139-1-1 00:00:00' AS DATETIME) as test" )
486
+ r = @client . prepare ( "SELECT CAST('0139-1-1 00:00:00' AS DATETIME) as test" ) . execute
476
487
expect ( r . first [ 'test' ] ) . to be_an_instance_of ( Time )
477
488
end
478
489
479
490
it "should return DateTime when timestamp is < 0139-1-1T00:00:00" do
480
- r = @client . query ( "SELECT CAST('0138-12-31 11:59:59' AS DATETIME) as test" )
491
+ r = @client . prepare ( "SELECT CAST('0138-12-31 11:59:59' AS DATETIME) as test" ) . execute
481
492
expect ( r . first [ 'test' ] ) . to be_an_instance_of ( DateTime )
482
493
end
483
494
484
495
it "should return Time when timestamp is > 2038-01-19T03:14:07" do
485
- r = @client . query ( "SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test" )
496
+ r = @client . prepare ( "SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test" ) . execute
486
497
expect ( r . first [ 'test' ] ) . to be_an_instance_of ( Time )
487
498
end
488
499
else
489
500
it "should return Time when timestamp is < 1901-12-13 20:45:52" do
490
- r = @client . query ( "SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test" )
501
+ r = @client . prepare ( "SELECT CAST('1901-12-13 20:45:51' AS DATETIME) as test" ) . execute
491
502
expect ( r . first [ 'test' ] ) . to be_an_instance_of ( Time )
492
503
end
493
504
494
505
it "should return Time when timestamp is > 2038-01-19T03:14:07" do
495
- r = @client . query ( "SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test" )
506
+ r = @client . prepare ( "SELECT CAST('2038-01-19 03:14:08' AS DATETIME) as test" ) . execute
496
507
expect ( r . first [ 'test' ] ) . to be_an_instance_of ( Time )
497
508
end
498
509
end
0 commit comments