Class: TC_MysqlStmt2

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
ext/test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



408
409
410
411
412
413
414
415
416
# File 'ext/test.rb', line 408

def setup()
  @host, @user, @pass, db, port, sock, flag = ARGV
  @db = db || "test"
  @port = port.to_i
  @sock = sock.nil? || sock.empty? ? nil : sock
  @flag = flag.to_i
  @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
  @s = @m.stmt_init()
end

#teardownObject



417
418
419
420
# File 'ext/test.rb', line 417

def teardown()
  @s.close
  @m.close
end

#test_affected_rowsObject



422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'ext/test.rb', line 422

def test_affected_rows()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(10))")
    @s.prepare("insert into t values (?,?)")
    @s.execute(1, "hoge")
    assert_equal(1, @s.affected_rows())
    @s.execute(2, "hoge")
    @s.execute(3, "hoge")
    @s.prepare("update t set c=?")
    @s.execute("fuga")
    assert_equal(3, @s.affected_rows())
  end
end

#test_bind_result_fixnumObject



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'ext/test.rb', line 504

def test_bind_result_fixnum()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
    @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
    @s.prepare("select * from t")
    @s.bind_result(Fixnum, Fixnum, Fixnum, Fixnum)
    @s.execute
    a = @s.fetch
    if Mysql.client_version < 50000 then
      assert_equal([123, 9, 1, 2005], a) 
    else
      assert_equal([123, 9, 1, 20050802235011.0], a)
    end
  end
end

#test_bind_result_floatObject



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
# File 'ext/test.rb', line 532

def test_bind_result_float()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
    @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
    @s.prepare("select * from t")
    @s.bind_result(Float, Float, Float, Float)
    @s.execute
    a = @s.fetch
    if Mysql.client_version < 50000 then
      assert_equal([123.0, 9.0, 1.2345, 2005.0], a)
    else
      assert_equal([123.0, 9.0, 1.2345, 20050802235011.0], a)
    end
  end
end

#test_bind_result_integerObject



488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'ext/test.rb', line 488

def test_bind_result_integer()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
    @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
    @s.prepare("select * from t")
    @s.bind_result(Integer, Integer, Integer, Integer)
    @s.execute
    a = @s.fetch
    if Mysql.client_version < 50000 then
      assert_equal([123, 9, 1, 2005], a)
    else
      assert_equal([123, 9, 1, 20050802235011], a)
    end
  end
end

#test_bind_result_mysqltimeObject



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
# File 'ext/test.rb', line 548

def test_bind_result_mysqltime()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
    @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
    @s.prepare("select * from t")
    @s.bind_result(Mysql::Time, Mysql::Time, Mysql::Time, Mysql::Time)
    @s.execute
    a = @s.fetch
    if Mysql.client_version < 50000 then
      assert_equal([Mysql::Time.new, Mysql::Time.new, Mysql::Time.new, Mysql::Time.new(2005,8,2,23,50,11)], a)
    else
      assert_equal([Mysql::Time.new(2000,1,23), Mysql::Time.new, Mysql::Time.new, Mysql::Time.new(2005,8,2,23,50,11)], a)
    end
  end
end

#test_bind_result_nilObject

def test_attr_get()

  assert_equal(false, @s.attr_get(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH))
  assert_raises(Mysql::Error){@s.attr_get(999)}
end

def test_attr_set()
  @s.attr_set(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH, true)
  assert_equal(true, @s.attr_get(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH))
  @s.attr_set(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH, false)
  assert_equal(false, @s.attr_get(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH))
  assert_raises(Mysql::Error){@s.attr_set(999, true)}
end

def test_bind_param()
  @s.prepare("insert into t values (?,?)")
  @s.bind_param(123, "abc")
  @s.bind_param(Time.now, nil)
  assert_raises(Mysql::Error){@s.bind_param(1, 2, 3)}
  b = @s.bind_param(Bind.new(Mysql::TYPE_TINY, 99, false))
  @s.bind_param(98.765, b)
end


460
461
462
463
464
465
466
467
468
469
470
# File 'ext/test.rb', line 460

def test_bind_result_nil() 
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
    @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
    @s.prepare("select * from t")
    @s.bind_result(nil,nil,nil,nil)
    @s.execute
    a = @s.fetch
    assert_equal([123, "9abcdefg", 1.2345, Mysql::Time.new(2005,8,2,23,50,11)], a)
  end
end

#test_bind_result_numericObject



472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'ext/test.rb', line 472

def test_bind_result_numeric()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
    @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
    @s.prepare("select * from t")
    @s.bind_result(Numeric, Numeric, Numeric, Numeric)
    @s.execute
    a = @s.fetch
    if Mysql.client_version < 50000 then
      assert_equal([123, 9, 1, 2005], a)
    else
      assert_equal([123, 9, 1, 20050802235011], a)
    end
  end
end

#test_bind_result_stringObject



520
521
522
523
524
525
526
527
528
529
530
# File 'ext/test.rb', line 520

def test_bind_result_string()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
    @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
    @s.prepare("select * from t")
    @s.bind_result(String, String, String, String)
    @s.execute
    a = @s.fetch
    assert_equal(["123", "9abcdefg", "1.2345", "2005-08-02 23:50:11"], a)
  end
end

#test_bind_result_unknownObject



564
565
566
567
568
569
570
571
# File 'ext/test.rb', line 564

def test_bind_result_unknown()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
    @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
    @s.prepare("select * from t")
    assert_raises(TypeError){@s.bind_result(Time, nil, nil, nil)}
  end
end

#test_bind_result_unmatch_countObject



573
574
575
576
577
578
579
580
# File 'ext/test.rb', line 573

def test_bind_result_unmatch_count()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
    @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
    @s.prepare("select * from t")
    assert_raises(Mysql::Error){@s.bind_result(nil, nil)}
  end
end

#test_data_seekObject



582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# File 'ext/test.rb', line 582

def test_data_seek()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int)")
    @m.query("insert into t values (0),(1),(2),(3),(4),(5)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([1], @s.fetch)
    assert_equal([2], @s.fetch)
    @s.data_seek(5)
    assert_equal([5], @s.fetch)
    @s.data_seek(1)
    assert_equal([1], @s.fetch)
  end
end

#test_eachObject



1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
# File 'ext/test.rb', line 1154

def test_each()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(255), d datetime)")
    @m.query("insert into t values (1,'abc','19701224235905'),(2,'def','21120903123456'),(3,'123',null)")
    @s.prepare("select * from t")
    @s.execute
    c = 0
    @s.each do |a|
      case c
      when 0
        assert_equal([1,"abc",Mysql::Time.new(1970,12,24,23,59,05)], a)
      when 1
        assert_equal([2,"def",Mysql::Time.new(2112,9,3,12,34,56)], a)
      when 2
        assert_equal([3,"123",nil], a)
      else
        raise
      end
      c += 1
    end
  end
end

#test_executeObject

def test_errno()

  @s.errno()
end

def test_error()
  @s.error()
end


608
609
610
611
612
613
614
615
616
617
618
# File 'ext/test.rb', line 608

def test_execute()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int)")
    @s.prepare("insert into t values (123)")
    @s.execute()
    assert_equal(1, @s.affected_rows)
    @s.execute()
    assert_equal(1, @s.affected_rows)
    assert_equal(2, @m.query("select count(*) from t").fetch_row[0].to_i)
  end
end

#test_execute2Object



620
621
622
623
624
625
626
627
628
629
630
631
# File 'ext/test.rb', line 620

def test_execute2()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int)")
    @s.prepare("insert into t values (?)")
    @s.execute(123)
    @s.execute("456")
    @s.prepare("select * from t")
    @s.execute
    assert_equal([123], @s.fetch)
    assert_equal([456], @s.fetch)
  end
end

#test_execute3Object



633
634
635
636
637
638
639
640
641
642
643
644
# File 'ext/test.rb', line 633

def test_execute3()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(255), t timestamp)")
    @s.prepare("insert into t values (?,?,?)")
    @s.execute(123, "hoge", Time.local(2005,7,19,23,53,0));
    assert_raises(Mysql::Error){@s.execute(123, "hoge")}
    assert_raises(Mysql::Error){@s.execute(123, "hoge", 0, "fuga")}
    @s.prepare("select * from t")
    @s.execute
    assert_equal([123, "hoge", Mysql::Time.new(2005,7,19,23,53,0)], @s.fetch)
  end
end

#test_execute4Object



646
647
648
649
650
651
652
653
654
655
# File 'ext/test.rb', line 646

def test_execute4()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int, c char(255), t timestamp)")
    @s.prepare("insert into t values (?,?,?)")
    @s.execute(nil, "hoge", Mysql::Time.new(2005,7,19,23,53,0));
    @s.prepare("select * from t")
    @s.execute
    assert_equal([nil, "hoge", Mysql::Time.new(2005,7,19,23,53,0)], @s.fetch)
  end
end

#test_fetchObject



657
658
659
660
661
662
663
# File 'ext/test.rb', line 657

def test_fetch()
  if @m.server_version >= 40100 then
    @s.prepare("select 123, 'abc', null")
    @s.execute()
    assert_equal([123, "abc", nil], @s.fetch())
  end
end

#test_fetch_bigintObject



789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
# File 'ext/test.rb', line 789

def test_fetch_bigint()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i bigint)")
    @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([-1], @s.fetch)
    assert_equal([9223372036854775807], @s.fetch)
    assert_equal([-9223372036854775808], @s.fetch)
    if @m.server_version >= 50000 then
      assert_equal([9223372036854775807], @s.fetch)
    else
      assert_equal([-1], @s.fetch)                       # MySQL problem
    end
    assert_equal([-9223372036854775808], @s.fetch)
    assert_equal([9223372036854775807], @s.fetch)
  end
end

#test_fetch_bigint_unsignedObject



809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
# File 'ext/test.rb', line 809

def test_fetch_bigint_unsigned()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i bigint unsigned)")
    @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    if @m.server_version >= 50000 then
      assert_equal([0], @s.fetch)
    else
      assert_equal([-1], @s.fetch)                   # MySQL & MySQL/Ruby problem
    end
    assert_equal([9223372036854775807], @s.fetch)
    if @m.server_version < 50000 then
      assert_equal([-9223372036854775808], @s.fetch) # MySQL problem
    else
      assert_equal([0], @s.fetch)
    end
    assert_equal([-1], @s.fetch)                   # MySQL/Ruby problem
    assert_equal([0], @s.fetch)
    assert_equal([-1], @s.fetch)                   # MySQL/Ruby problem
  end
end

#test_fetch_binaryObject



1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
# File 'ext/test.rb', line 1006

def test_fetch_binary()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i binary(10))")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    if @m.server_version >= 50000 then
      assert_equal(["abc\0\0\0\0\0\0\0"], @s.fetch)
    else
      assert_equal(["abc"], @s.fetch)
    end
  end
end

#test_fetch_blobObject



1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
# File 'ext/test.rb', line 1054

def test_fetch_blob()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i blob)")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_charObject



984
985
986
987
988
989
990
991
992
993
# File 'ext/test.rb', line 984

def test_fetch_char()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i char(10))")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_dateObject



923
924
925
926
927
928
929
930
931
932
933
# File 'ext/test.rb', line 923

def test_fetch_date()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i date)")
    @m.query("insert into t values ('0000-00-00'),('1000-01-01'),('9999-12-31')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([Mysql::Time.new(0,0,0)], @s.fetch)
    assert_equal([Mysql::Time.new(1000,1,1)], @s.fetch)
    assert_equal([Mysql::Time.new(9999,12,31)], @s.fetch)
  end
end

#test_fetch_datetimeObject



935
936
937
938
939
940
941
942
943
944
945
# File 'ext/test.rb', line 935

def test_fetch_datetime()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i datetime)")
    @m.query("insert into t values ('0000-00-00 00:00:00'),('1000-01-01 00:00:00'),('9999-12-31 23:59:59')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([Mysql::Time.new(0,0,0,0,0,0)], @s.fetch)
    assert_equal([Mysql::Time.new(1000,1,1,0,0,0)], @s.fetch)
    assert_equal([Mysql::Time.new(9999,12,31,23,59,59)], @s.fetch)
  end
end

#test_fetch_decimalObject



889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
# File 'ext/test.rb', line 889

def test_fetch_decimal()
  if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then
    @m.query("create temporary table t (i decimal)")
    @m.query("insert into t values (0),(9999999999),(-9999999999),(10000000000),(-10000000000)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal(["0"], @s.fetch)
    assert_equal(["9999999999"], @s.fetch)
    assert_equal(["-9999999999"], @s.fetch)
    if @m.server_version < 50000 then
      assert_equal(["10000000000"], @s.fetch)    # MySQL problem
    else
      assert_equal(["9999999999"], @s.fetch)
    end
    assert_equal(["-9999999999"], @s.fetch)
  end
end

#test_fetch_decimal_unsignedObject



907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
# File 'ext/test.rb', line 907

def test_fetch_decimal_unsigned()
  if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then
    @m.query("create temporary table t (i decimal unsigned)")
    @m.query("insert into t values (0),(9999999998),(9999999999),(-9999999998),(-9999999999),(10000000000),(-10000000000)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal(["0"], @s.fetch)
    assert_equal(["9999999998"], @s.fetch)
    assert_equal(["9999999999"], @s.fetch)
    assert_equal(["0"], @s.fetch)
    assert_equal(["0"], @s.fetch)
    assert_equal(["9999999999"], @s.fetch)
    assert_equal(["0"], @s.fetch)
  end
end

#test_fetch_doubleObject



861
862
863
864
865
866
867
868
869
870
871
872
873
# File 'ext/test.rb', line 861

def test_fetch_double()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i double)")
    @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_in_delta(-Float::MAX, @s.fetch[0], Float::EPSILON)
    assert_in_delta(-Float::MIN, @s.fetch[0], Float::EPSILON)
    assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON)
    assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON)
  end
end

#test_fetch_double_unsignedObject



875
876
877
878
879
880
881
882
883
884
885
886
887
# File 'ext/test.rb', line 875

def test_fetch_double_unsigned()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i double unsigned)")
    @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON)
    assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON)
  end
end

#test_fetch_enumObject



1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
# File 'ext/test.rb', line 1120

def test_fetch_enum()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i enum('abc','def'))")
    @m.query("insert into t values (null),(0),(1),(2),('abc'),('def'),('ghi')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal([""], @s.fetch)
    assert_equal(["abc"], @s.fetch)
    assert_equal(["def"], @s.fetch)
    assert_equal(["abc"], @s.fetch)
    assert_equal(["def"], @s.fetch)
    assert_equal([""], @s.fetch)
  end
end

#test_fetch_floatObject



833
834
835
836
837
838
839
840
841
842
843
844
845
# File 'ext/test.rb', line 833

def test_fetch_float()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i float)")
    @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_in_delta(-3.402823466E+38, @s.fetch[0], 0.000000001E+38)
    assert_in_delta(-1.175494351E-38, @s.fetch[0], 0.000000001E-38)
    assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38)
    assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38)
  end
end

#test_fetch_float_unsignedObject



847
848
849
850
851
852
853
854
855
856
857
858
859
# File 'ext/test.rb', line 847

def test_fetch_float_unsigned()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i float unsigned)")
    @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38)
    assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38)
  end
end

#test_fetch_intObject



758
759
760
761
762
763
764
765
766
767
768
769
770
771
# File 'ext/test.rb', line 758

def test_fetch_int()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int)")
    @m.query("insert into t values (0),(-1),(2147483647),(-2147483648),(4294967295),(-4294967295),(4294967296)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([-1], @s.fetch)
    assert_equal([2147483647], @s.fetch)
    assert_equal([-2147483648], @s.fetch)
    assert_equal([2147483647], @s.fetch)
    assert_equal([-2147483648], @s.fetch)
  end
end

#test_fetch_int_unsignedObject



773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
# File 'ext/test.rb', line 773

def test_fetch_int_unsigned()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int unsigned)")
    @m.query("insert into t values (0),(-1),(2147483647),(-2147483648),(4294967295),(-4294967295),(4294967296)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([2147483647], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([4294967295], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([4294967295], @s.fetch)
  end
end

#test_fetch_longblobObject



1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
# File 'ext/test.rb', line 1098

def test_fetch_longblob()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i longblob)")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_longtextObject



1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
# File 'ext/test.rb', line 1109

def test_fetch_longtext()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i longtext)")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_mediumblobObject



1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
# File 'ext/test.rb', line 1076

def test_fetch_mediumblob()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i mediumblob)")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_mediumintObject



727
728
729
730
731
732
733
734
735
736
737
738
739
740
# File 'ext/test.rb', line 727

def test_fetch_mediumint()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i mediumint)")
    @m.query("insert into t values (0),(-1),(8388607),(-8388608),(16777215),(-16777215),(16777216)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([-1], @s.fetch)
    assert_equal([8388607], @s.fetch)
    assert_equal([-8388608], @s.fetch)
    assert_equal([8388607], @s.fetch)
    assert_equal([-8388608], @s.fetch)
  end
end

#test_fetch_mediumint_unsignedObject



742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
# File 'ext/test.rb', line 742

def test_fetch_mediumint_unsigned()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i mediumint unsigned)")
    @m.query("insert into t values (0),(-1),(8388607),(-8388608),(16777215),(-16777215),(16777216)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([8388607], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([16777215], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([16777215], @s.fetch)
  end
end

#test_fetch_mediumtextObject



1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
# File 'ext/test.rb', line 1087

def test_fetch_mediumtext()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i mediumtext)")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_setObject



1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
# File 'ext/test.rb', line 1136

def test_fetch_set()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i set('abc','def'))")
    @m.query("insert into t values (null),(0),(1),(2),(3),('abc'),('def'),('abc,def'),('ghi')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal([""], @s.fetch)
    assert_equal(["abc"], @s.fetch)
    assert_equal(["def"], @s.fetch)
    assert_equal(["abc,def"], @s.fetch)
    assert_equal(["abc"], @s.fetch)
    assert_equal(["def"], @s.fetch)
    assert_equal(["abc,def"], @s.fetch)
    assert_equal([""], @s.fetch)
  end
end

#test_fetch_smallintObject



696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'ext/test.rb', line 696

def test_fetch_smallint()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i smallint)")
    @m.query("insert into t values (0),(-1),(32767),(-32768),(65535),(-65535),(65536)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([-1], @s.fetch)
    assert_equal([32767], @s.fetch)
    assert_equal([-32768], @s.fetch)
    assert_equal([32767], @s.fetch)
    assert_equal([-32768], @s.fetch)
  end
end

#test_fetch_smallint_unsignedObject



711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
# File 'ext/test.rb', line 711

def test_fetch_smallint_unsigned()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i smallint unsigned)")
    @m.query("insert into t values (0),(-1),(32767),(-32768),(65535),(-65535),(65536)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([32767], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([65535], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([65535], @s.fetch)
  end
end

#test_fetch_textObject



1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
# File 'ext/test.rb', line 1065

def test_fetch_text()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i text)")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_timeObject



958
959
960
961
962
963
964
965
966
967
968
# File 'ext/test.rb', line 958

def test_fetch_time()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i time)")
    @m.query("insert into t values ('-838:59:59'),(0),('838:59:59')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([Mysql::Time.new(0,0,0,838,59,59,true)], @s.fetch)
    assert_equal([Mysql::Time.new(0,0,0,0,0,0,false)], @s.fetch)
    assert_equal([Mysql::Time.new(0,0,0,838,59,59,false)], @s.fetch)
  end
end

#test_fetch_timestampObject



947
948
949
950
951
952
953
954
955
956
# File 'ext/test.rb', line 947

def test_fetch_timestamp()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i timestamp)")
    @m.query("insert into t values ('1970-01-02 00:00:00'),('2037-12-30 23:59:59')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([Mysql::Time.new(1970,1,2,0,0,0)], @s.fetch)
    assert_equal([Mysql::Time.new(2037,12,30,23,59,59)], @s.fetch)
  end
end

#test_fetch_tinyblobObject



1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
# File 'ext/test.rb', line 1032

def test_fetch_tinyblob()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i tinyblob)")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_tinyintObject



665
666
667
668
669
670
671
672
673
674
675
676
677
678
# File 'ext/test.rb', line 665

def test_fetch_tinyint()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i tinyint)")
    @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([-1], @s.fetch)
    assert_equal([127], @s.fetch)
    assert_equal([-128], @s.fetch)
    assert_equal([127], @s.fetch)
    assert_equal([-128], @s.fetch)
  end
end

#test_fetch_tinyint_unsignedObject



680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
# File 'ext/test.rb', line 680

def test_fetch_tinyint_unsigned()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i tinyint unsigned)")
    @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255),(256)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([127], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([255], @s.fetch)
    assert_equal([0], @s.fetch)
    assert_equal([255], @s.fetch)
  end
end

#test_fetch_tinytextObject



1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
# File 'ext/test.rb', line 1043

def test_fetch_tinytext()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i tinytext)")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_varbinaryObject



1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
# File 'ext/test.rb', line 1021

def test_fetch_varbinary()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i varbinary(10))")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_varcharObject



995
996
997
998
999
1000
1001
1002
1003
1004
# File 'ext/test.rb', line 995

def test_fetch_varchar()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i varchar(10))")
    @m.query("insert into t values (null),('abc')")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([nil], @s.fetch)
    assert_equal(["abc"], @s.fetch)
  end
end

#test_fetch_yearObject



970
971
972
973
974
975
976
977
978
979
980
981
982
# File 'ext/test.rb', line 970

def test_fetch_year()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i year)")
    @m.query("insert into t values (0),(70),(69),(1901),(2155)")
    @s.prepare("select i from t")
    @s.execute
    assert_equal([0], @s.fetch)
    assert_equal([1970], @s.fetch)
    assert_equal([2069], @s.fetch)
    assert_equal([1901], @s.fetch)
    assert_equal([2155], @s.fetch)
  end
end

#test_field_countObject



1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
# File 'ext/test.rb', line 1177

def test_field_count()
  if @m.server_version >= 40100 then
    @s.prepare("select 1,2,3")
    @s.execute()
    assert_equal(3, @s.field_count())
    @s.prepare("set @a=1")
    @s.execute()
    assert_equal(0, @s.field_count())
  end
end

#test_free_resultObject



1188
1189
1190
1191
1192
1193
1194
1195
# File 'ext/test.rb', line 1188

def test_free_result()
  if @m.server_version >= 40100 then
    @s.free_result()
    @s.prepare("select 1,2,3")
    @s.execute()
    @s.free_result()
  end
end

#test_insert_idObject



1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
# File 'ext/test.rb', line 1197

def test_insert_id()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int auto_increment, unique(i))")
    @s.prepare("insert into t values (0)")
    @s.execute()
    assert_equal(1, @s.insert_id())
    @s.execute()
    assert_equal(2, @s.insert_id())
  end
end

#test_num_rowsObject



1208
1209
1210
1211
1212
1213
1214
1215
1216
# File 'ext/test.rb', line 1208

def test_num_rows()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int)")
    @m.query("insert into t values (1),(2),(3),(4)")
    @s.prepare("select * from t")
    @s.execute
    assert_equal(4, @s.num_rows())
  end
end

#test_param_countObject



1218
1219
1220
1221
1222
1223
1224
1225
1226
# File 'ext/test.rb', line 1218

def test_param_count()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (a int, b int, c int)")
    @s.prepare("select * from t")
    assert_equal(0, @s.param_count())
    @s.prepare("insert into t values (?,?,?)")
    assert_equal(3, @s.param_count())
  end
end

#test_prepareObject

def test_param_metadata()

  @s.param_metadata()
end


1234
1235
1236
1237
1238
1239
# File 'ext/test.rb', line 1234

def test_prepare()
  if @m.server_version >= 40100 then
    @s.prepare("select 1")
    assert_raises(Mysql::Error){@s.prepare("invalid syntax")}
  end
end

#test_result_metadataObject

def test_reset()

  @s.reset()
end


1247
1248
1249
1250
1251
1252
1253
1254
1255
# File 'ext/test.rb', line 1247

def ()
  if @m.server_version >= 40100 then
    @s.prepare("select 1 foo, 2 bar")
    res = @s.()
    f = res.fetch_fields
    assert_equal("foo", f[0].name)
    assert_equal("bar", f[1].name)
  end
end

#test_row_seek_tellObject



1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
# File 'ext/test.rb', line 1257

def test_row_seek_tell()
  if @m.server_version >= 40100 then
    @m.query("create temporary table t (i int)")
    @m.query("insert into t values (0),(1),(2),(3),(4)")
    @s.prepare("select * from t")
    @s.execute
    row0 = @s.row_tell
    assert_equal([0], @s.fetch)
    assert_equal([1], @s.fetch)
    row2 = @s.row_seek(row0)
    assert_equal([0], @s.fetch)
    @s.row_seek(row2)
    assert_equal([2], @s.fetch)
  end
end

#test_sqlstateObject

def test_send_long_data()

  @m.query("create temporary table t (i int, t text)")
  @s.prepare("insert into t values (?,?)")
  @s.send_long_data(1, "long long data ")
  @s.send_long_data(1, "long long data2")
  assert_raises(Mysql::Error){@s.send_long_data(9, "invalid param number")}
  @s.execute(99, "hoge")
  assert_equal("long long data long long data2", @m.query("select t from t").fetch_row[0])
end


1285
1286
1287
1288
1289
1290
1291
1292
# File 'ext/test.rb', line 1285

def test_sqlstate()
  if @m.server_version >= 40100 then
    @s.prepare("select 1")
    assert_equal("", @s.sqlstate)
    assert_raises(Mysql::Error){@s.prepare("hogehoge")}
    assert_equal("42000", @s.sqlstate)
  end
end