| Class | TC_MysqlStmt2 |
| In: |
test.rb
|
| Parent: | Test::Unit::TestCase |
# File test.rb, line 408
408: def setup()
409: @host, @user, @pass, db, port, sock, flag = ARGV
410: @db = db || "test"
411: @port = port.to_i
412: @sock = sock.nil? || sock.empty? ? nil : sock
413: @flag = flag.to_i
414: @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
415: @s = @m.stmt_init()
416: end
# File test.rb, line 422
422: def test_affected_rows()
423: if @m.server_version >= 40100 then
424: @m.query("create temporary table t (i int, c char(10))")
425: @s.prepare("insert into t values (?,?)")
426: @s.execute(1, "hoge")
427: assert_equal(1, @s.affected_rows())
428: @s.execute(2, "hoge")
429: @s.execute(3, "hoge")
430: @s.prepare("update t set c=?")
431: @s.execute("fuga")
432: assert_equal(3, @s.affected_rows())
433: end
434: end
# File test.rb, line 504
504: def test_bind_result_fixnum()
505: if @m.server_version >= 40100 then
506: @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
507: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
508: @s.prepare("select * from t")
509: @s.bind_result(Fixnum, Fixnum, Fixnum, Fixnum)
510: @s.execute
511: a = @s.fetch
512: if Mysql.client_version < 50000 then
513: assert_equal([123, 9, 1, 2005], a)
514: else
515: assert_equal([123, 9, 1, 20050802235011.0], a)
516: end
517: end
518: end
# File test.rb, line 532
532: def test_bind_result_float()
533: if @m.server_version >= 40100 then
534: @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
535: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
536: @s.prepare("select * from t")
537: @s.bind_result(Float, Float, Float, Float)
538: @s.execute
539: a = @s.fetch
540: if Mysql.client_version < 50000 then
541: assert_equal([123.0, 9.0, 1.2345, 2005.0], a)
542: else
543: assert_equal([123.0, 9.0, 1.2345, 20050802235011.0], a)
544: end
545: end
546: end
# File test.rb, line 488
488: def test_bind_result_integer()
489: if @m.server_version >= 40100 then
490: @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
491: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
492: @s.prepare("select * from t")
493: @s.bind_result(Integer, Integer, Integer, Integer)
494: @s.execute
495: a = @s.fetch
496: if Mysql.client_version < 50000 then
497: assert_equal([123, 9, 1, 2005], a)
498: else
499: assert_equal([123, 9, 1, 20050802235011], a)
500: end
501: end
502: end
# File test.rb, line 548
548: def test_bind_result_mysqltime()
549: if @m.server_version >= 40100 then
550: @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
551: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
552: @s.prepare("select * from t")
553: @s.bind_result(Mysql::Time, Mysql::Time, Mysql::Time, Mysql::Time)
554: @s.execute
555: a = @s.fetch
556: if Mysql.client_version < 50000 then
557: assert_equal([Mysql::Time.new, Mysql::Time.new, Mysql::Time.new, Mysql::Time.new(2005,8,2,23,50,11)], a)
558: else
559: assert_equal([Mysql::Time.new(2000,1,23), Mysql::Time.new, Mysql::Time.new, Mysql::Time.new(2005,8,2,23,50,11)], a)
560: end
561: end
562: end
# File test.rb, line 460
460: def test_bind_result_nil()
461: if @m.server_version >= 40100 then
462: @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
463: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
464: @s.prepare("select * from t")
465: @s.bind_result(nil,nil,nil,nil)
466: @s.execute
467: a = @s.fetch
468: assert_equal([123, "9abcdefg", 1.2345, Mysql::Time.new(2005,8,2,23,50,11)], a)
469: end
470: end
# File test.rb, line 472
472: def test_bind_result_numeric()
473: if @m.server_version >= 40100 then
474: @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
475: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
476: @s.prepare("select * from t")
477: @s.bind_result(Numeric, Numeric, Numeric, Numeric)
478: @s.execute
479: a = @s.fetch
480: if Mysql.client_version < 50000 then
481: assert_equal([123, 9, 1, 2005], a)
482: else
483: assert_equal([123, 9, 1, 20050802235011], a)
484: end
485: end
486: end
# File test.rb, line 520
520: def test_bind_result_string()
521: if @m.server_version >= 40100 then
522: @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
523: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
524: @s.prepare("select * from t")
525: @s.bind_result(String, String, String, String)
526: @s.execute
527: a = @s.fetch
528: assert_equal(["123", "9abcdefg", "1.2345", "2005-08-02 23:50:11"], a)
529: end
530: end
# File test.rb, line 564
564: def test_bind_result_unknown()
565: if @m.server_version >= 40100 then
566: @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
567: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
568: @s.prepare("select * from t")
569: assert_raises(TypeError){@s.bind_result(Time, nil, nil, nil)}
570: end
571: end
# File test.rb, line 573
573: def test_bind_result_unmatch_count()
574: if @m.server_version >= 40100 then
575: @m.query("create temporary table t (i int, c char(10), d double, t datetime)")
576: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
577: @s.prepare("select * from t")
578: assert_raises(Mysql::Error){@s.bind_result(nil, nil)}
579: end
580: end
# File test.rb, line 582
582: def test_data_seek()
583: if @m.server_version >= 40100 then
584: @m.query("create temporary table t (i int)")
585: @m.query("insert into t values (0),(1),(2),(3),(4),(5)")
586: @s.prepare("select i from t")
587: @s.execute
588: assert_equal([0], @s.fetch)
589: assert_equal([1], @s.fetch)
590: assert_equal([2], @s.fetch)
591: @s.data_seek(5)
592: assert_equal([5], @s.fetch)
593: @s.data_seek(1)
594: assert_equal([1], @s.fetch)
595: end
596: end
# File test.rb, line 1146
1146: def test_each()
1147: if @m.server_version >= 40100 then
1148: @m.query("create temporary table t (i int, c char(255), d datetime)")
1149: @m.query("insert into t values (1,'abc','19701224235905'),(2,'def','21120903123456'),(3,'123',null)")
1150: @s.prepare("select * from t")
1151: @s.execute
1152: c = 0
1153: @s.each do |a|
1154: case c
1155: when 0
1156: assert_equal([1,"abc",Mysql::Time.new(1970,12,24,23,59,05)], a)
1157: when 1
1158: assert_equal([2,"def",Mysql::Time.new(2112,9,3,12,34,56)], a)
1159: when 2
1160: assert_equal([3,"123",nil], a)
1161: else
1162: raise
1163: end
1164: c += 1
1165: end
1166: end
1167: end
# File test.rb, line 608
608: def test_execute()
609: if @m.server_version >= 40100 then
610: @m.query("create temporary table t (i int)")
611: @s.prepare("insert into t values (123)")
612: @s.execute()
613: assert_equal(1, @s.affected_rows)
614: @s.execute()
615: assert_equal(1, @s.affected_rows)
616: assert_equal(2, @m.query("select count(*) from t").fetch_row[0].to_i)
617: end
618: end
# File test.rb, line 620
620: def test_execute2()
621: if @m.server_version >= 40100 then
622: @m.query("create temporary table t (i int)")
623: @s.prepare("insert into t values (?)")
624: @s.execute(123)
625: @s.execute("456")
626: @s.prepare("select * from t")
627: @s.execute
628: assert_equal([123], @s.fetch)
629: assert_equal([456], @s.fetch)
630: end
631: end
# File test.rb, line 633
633: def test_execute3()
634: if @m.server_version >= 40100 then
635: @m.query("create temporary table t (i int, c char(255), t timestamp)")
636: @s.prepare("insert into t values (?,?,?)")
637: @s.execute(123, "hoge", Time.local(2005,7,19,23,53,0));
638: assert_raises(Mysql::Error){@s.execute(123, "hoge")}
639: assert_raises(Mysql::Error){@s.execute(123, "hoge", 0, "fuga")}
640: @s.prepare("select * from t")
641: @s.execute
642: assert_equal([123, "hoge", Mysql::Time.new(2005,7,19,23,53,0)], @s.fetch)
643: end
644: end
# File test.rb, line 646
646: def test_execute4()
647: if @m.server_version >= 40100 then
648: @m.query("create temporary table t (i int, c char(255), t timestamp)")
649: @s.prepare("insert into t values (?,?,?)")
650: @s.execute(nil, "hoge", Mysql::Time.new(2005,7,19,23,53,0));
651: @s.prepare("select * from t")
652: @s.execute
653: assert_equal([nil, "hoge", Mysql::Time.new(2005,7,19,23,53,0)], @s.fetch)
654: end
655: end
# File test.rb, line 657
657: def test_fetch()
658: if @m.server_version >= 40100 then
659: @s.prepare("select 123, 'abc', null")
660: @s.execute()
661: assert_equal([123, "abc", nil], @s.fetch())
662: end
663: end
# File test.rb, line 789
789: def test_fetch_bigint()
790: if @m.server_version >= 40100 then
791: @m.query("create temporary table t (i bigint)")
792: @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)")
793: @s.prepare("select i from t")
794: @s.execute
795: assert_equal([0], @s.fetch)
796: assert_equal([-1], @s.fetch)
797: assert_equal([9223372036854775807], @s.fetch)
798: assert_equal([-9223372036854775808], @s.fetch)
799: assert_equal([-1], @s.fetch) # MySQL problem
800: assert_equal([-9223372036854775808], @s.fetch)
801: assert_equal([9223372036854775807], @s.fetch)
802: end
803: end
# File test.rb, line 805
805: def test_fetch_bigint_unsigned()
806: if @m.server_version >= 40100 then
807: @m.query("create temporary table t (i bigint unsigned)")
808: @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)")
809: @s.prepare("select i from t")
810: @s.execute
811: assert_equal([0], @s.fetch)
812: assert_equal([-1], @s.fetch) # MySQL & MySQL/Ruby problem
813: assert_equal([9223372036854775807], @s.fetch)
814: if @m.server_version < 50000 then
815: assert_equal([-9223372036854775808], @s.fetch) # MySQL problem
816: else
817: assert_equal([0], @s.fetch)
818: end
819: assert_equal([-1], @s.fetch) # MySQL/Ruby problem
820: assert_equal([0], @s.fetch)
821: assert_equal([-1], @s.fetch) # MySQL/Ruby problem
822: end
823: end
# File test.rb, line 1002
1002: def test_fetch_binary()
1003: if @m.server_version >= 40100 then
1004: @m.query("create temporary table t (i binary(10))")
1005: @m.query("insert into t values (null),('abc')")
1006: @s.prepare("select i from t")
1007: @s.execute
1008: assert_equal([nil], @s.fetch)
1009: assert_equal(["abc"], @s.fetch)
1010: end
1011: end
# File test.rb, line 1046
1046: def test_fetch_blob()
1047: if @m.server_version >= 40100 then
1048: @m.query("create temporary table t (i blob)")
1049: @m.query("insert into t values (null),('abc')")
1050: @s.prepare("select i from t")
1051: @s.execute
1052: assert_equal([nil], @s.fetch)
1053: assert_equal(["abc"], @s.fetch)
1054: end
1055: end
# File test.rb, line 980
980: def test_fetch_char()
981: if @m.server_version >= 40100 then
982: @m.query("create temporary table t (i char(10))")
983: @m.query("insert into t values (null),('abc')")
984: @s.prepare("select i from t")
985: @s.execute
986: assert_equal([nil], @s.fetch)
987: assert_equal(["abc"], @s.fetch)
988: end
989: end
# File test.rb, line 919
919: def test_fetch_date()
920: if @m.server_version >= 40100 then
921: @m.query("create temporary table t (i date)")
922: @m.query("insert into t values ('0000-00-00'),('1000-01-01'),('9999-12-31')")
923: @s.prepare("select i from t")
924: @s.execute
925: assert_equal([Mysql::Time.new(0,0,0)], @s.fetch)
926: assert_equal([Mysql::Time.new(1000,1,1)], @s.fetch)
927: assert_equal([Mysql::Time.new(9999,12,31)], @s.fetch)
928: end
929: end
# File test.rb, line 931
931: def test_fetch_datetime()
932: if @m.server_version >= 40100 then
933: @m.query("create temporary table t (i datetime)")
934: @m.query("insert into t values ('0000-00-00 00:00:00'),('1000-01-01 00:00:00'),('9999-12-31 23:59:59')")
935: @s.prepare("select i from t")
936: @s.execute
937: assert_equal([Mysql::Time.new(0,0,0,0,0,0)], @s.fetch)
938: assert_equal([Mysql::Time.new(1000,1,1,0,0,0)], @s.fetch)
939: assert_equal([Mysql::Time.new(9999,12,31,23,59,59)], @s.fetch)
940: end
941: end
# File test.rb, line 885
885: def test_fetch_decimal()
886: if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then
887: @m.query("create temporary table t (i decimal)")
888: @m.query("insert into t values (0),(9999999999),(-9999999999),(10000000000),(-10000000000)")
889: @s.prepare("select i from t")
890: @s.execute
891: assert_equal(["0"], @s.fetch)
892: assert_equal(["9999999999"], @s.fetch)
893: assert_equal(["-9999999999"], @s.fetch)
894: if @m.server_version < 50000 then
895: assert_equal(["10000000000"], @s.fetch) # MySQL problem
896: else
897: assert_equal(["9999999999"], @s.fetch)
898: end
899: assert_equal(["-9999999999"], @s.fetch)
900: end
901: end
# File test.rb, line 903
903: def test_fetch_decimal_unsigned()
904: if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then
905: @m.query("create temporary table t (i decimal unsigned)")
906: @m.query("insert into t values (0),(9999999998),(9999999999),(-9999999998),(-9999999999),(10000000000),(-10000000000)")
907: @s.prepare("select i from t")
908: @s.execute
909: assert_equal(["0"], @s.fetch)
910: assert_equal(["9999999998"], @s.fetch)
911: assert_equal(["9999999999"], @s.fetch)
912: assert_equal(["0"], @s.fetch)
913: assert_equal(["0"], @s.fetch)
914: assert_equal(["9999999999"], @s.fetch)
915: assert_equal(["0"], @s.fetch)
916: end
917: end
# File test.rb, line 853
853: def test_fetch_double()
854: if @m.server_version >= 40100 then
855: @m.query("create temporary table t (i double)")
856: @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)")
857: @s.prepare("select i from t")
858: @s.execute
859: assert_equal([0], @s.fetch)
860: assert_equal(-Float::MAX, @s.fetch[0])
861: if Mysql.client_version <= 40109 then # higher version has bug
862: assert_equal(-Float::MIN, @s.fetch[0])
863: assert_equal(Float::MIN, @s.fetch[0])
864: assert_equal(Float::MAX, @s.fetch[0])
865: end
866: end
867: end
# File test.rb, line 869
869: def test_fetch_double_unsigned()
870: if @m.server_version >= 40100 then
871: @m.query("create temporary table t (i double unsigned)")
872: @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)")
873: @s.prepare("select i from t")
874: @s.execute
875: assert_equal([0], @s.fetch)
876: assert_equal([0], @s.fetch)
877: if Mysql.client_version <= 40109 then # higher version has bug
878: assert_equal([0], @s.fetch)
879: assert_equal(Float::MIN, @s.fetch[0])
880: assert_equal(Float::MAX, @s.fetch[0])
881: end
882: end
883: end
# File test.rb, line 1112
1112: def test_fetch_enum()
1113: if @m.server_version >= 40100 then
1114: @m.query("create temporary table t (i enum('abc','def'))")
1115: @m.query("insert into t values (null),(0),(1),(2),('abc'),('def'),('ghi')")
1116: @s.prepare("select i from t")
1117: @s.execute
1118: assert_equal([nil], @s.fetch)
1119: assert_equal([""], @s.fetch)
1120: assert_equal(["abc"], @s.fetch)
1121: assert_equal(["def"], @s.fetch)
1122: assert_equal(["abc"], @s.fetch)
1123: assert_equal(["def"], @s.fetch)
1124: assert_equal([""], @s.fetch)
1125: end
1126: end
# File test.rb, line 825
825: def test_fetch_float()
826: if @m.server_version >= 40100 then
827: @m.query("create temporary table t (i float)")
828: @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)")
829: @s.prepare("select i from t")
830: @s.execute
831: assert_equal([0], @s.fetch)
832: assert_in_delta(-3.402823466E+38, @s.fetch[0], 0.000000001E+38)
833: assert_in_delta(-1.175494351E-38, @s.fetch[0], 0.000000001E-38)
834: assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38)
835: assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38)
836: end
837: end
# File test.rb, line 839
839: def test_fetch_float_unsigned()
840: if @m.server_version >= 40100 then
841: @m.query("create temporary table t (i float unsigned)")
842: @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)")
843: @s.prepare("select i from t")
844: @s.execute
845: assert_equal([0], @s.fetch)
846: assert_equal([0], @s.fetch)
847: assert_equal([0], @s.fetch)
848: assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38)
849: assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38)
850: end
851: end
# File test.rb, line 758
758: def test_fetch_int()
759: if @m.server_version >= 40100 then
760: @m.query("create temporary table t (i int)")
761: @m.query("insert into t values (0),(-1),(2147483647),(-2147483648),(4294967295),(-4294967295),(4294967296)")
762: @s.prepare("select i from t")
763: @s.execute
764: assert_equal([0], @s.fetch)
765: assert_equal([-1], @s.fetch)
766: assert_equal([2147483647], @s.fetch)
767: assert_equal([-2147483648], @s.fetch)
768: assert_equal([2147483647], @s.fetch)
769: assert_equal([-2147483648], @s.fetch)
770: end
771: end
# File test.rb, line 773
773: def test_fetch_int_unsigned()
774: if @m.server_version >= 40100 then
775: @m.query("create temporary table t (i int unsigned)")
776: @m.query("insert into t values (0),(-1),(2147483647),(-2147483648),(4294967295),(-4294967295),(4294967296)")
777: @s.prepare("select i from t")
778: @s.execute
779: assert_equal([0], @s.fetch)
780: assert_equal([0], @s.fetch)
781: assert_equal([2147483647], @s.fetch)
782: assert_equal([0], @s.fetch)
783: assert_equal([4294967295], @s.fetch)
784: assert_equal([0], @s.fetch)
785: assert_equal([4294967295], @s.fetch)
786: end
787: end
# File test.rb, line 1090
1090: def test_fetch_longblob()
1091: if @m.server_version >= 40100 then
1092: @m.query("create temporary table t (i longblob)")
1093: @m.query("insert into t values (null),('abc')")
1094: @s.prepare("select i from t")
1095: @s.execute
1096: assert_equal([nil], @s.fetch)
1097: assert_equal(["abc"], @s.fetch)
1098: end
1099: end
# File test.rb, line 1101
1101: def test_fetch_longtext()
1102: if @m.server_version >= 40100 then
1103: @m.query("create temporary table t (i longtext)")
1104: @m.query("insert into t values (null),('abc')")
1105: @s.prepare("select i from t")
1106: @s.execute
1107: assert_equal([nil], @s.fetch)
1108: assert_equal(["abc"], @s.fetch)
1109: end
1110: end
# File test.rb, line 1068
1068: def test_fetch_mediumblob()
1069: if @m.server_version >= 40100 then
1070: @m.query("create temporary table t (i mediumblob)")
1071: @m.query("insert into t values (null),('abc')")
1072: @s.prepare("select i from t")
1073: @s.execute
1074: assert_equal([nil], @s.fetch)
1075: assert_equal(["abc"], @s.fetch)
1076: end
1077: end
# File test.rb, line 727
727: def test_fetch_mediumint()
728: if @m.server_version >= 40100 then
729: @m.query("create temporary table t (i mediumint)")
730: @m.query("insert into t values (0),(-1),(8388607),(-8388608),(16777215),(-16777215),(16777216)")
731: @s.prepare("select i from t")
732: @s.execute
733: assert_equal([0], @s.fetch)
734: assert_equal([-1], @s.fetch)
735: assert_equal([8388607], @s.fetch)
736: assert_equal([-8388608], @s.fetch)
737: assert_equal([8388607], @s.fetch)
738: assert_equal([-8388608], @s.fetch)
739: end
740: end
# File test.rb, line 742
742: def test_fetch_mediumint_unsigned()
743: if @m.server_version >= 40100 then
744: @m.query("create temporary table t (i mediumint unsigned)")
745: @m.query("insert into t values (0),(-1),(8388607),(-8388608),(16777215),(-16777215),(16777216)")
746: @s.prepare("select i from t")
747: @s.execute
748: assert_equal([0], @s.fetch)
749: assert_equal([0], @s.fetch)
750: assert_equal([8388607], @s.fetch)
751: assert_equal([0], @s.fetch)
752: assert_equal([16777215], @s.fetch)
753: assert_equal([0], @s.fetch)
754: assert_equal([16777215], @s.fetch)
755: end
756: end
# File test.rb, line 1079
1079: def test_fetch_mediumtext()
1080: if @m.server_version >= 40100 then
1081: @m.query("create temporary table t (i mediumtext)")
1082: @m.query("insert into t values (null),('abc')")
1083: @s.prepare("select i from t")
1084: @s.execute
1085: assert_equal([nil], @s.fetch)
1086: assert_equal(["abc"], @s.fetch)
1087: end
1088: end
# File test.rb, line 1128
1128: def test_fetch_set()
1129: if @m.server_version >= 40100 then
1130: @m.query("create temporary table t (i set('abc','def'))")
1131: @m.query("insert into t values (null),(0),(1),(2),(3),('abc'),('def'),('abc,def'),('ghi')")
1132: @s.prepare("select i from t")
1133: @s.execute
1134: assert_equal([nil], @s.fetch)
1135: assert_equal([""], @s.fetch)
1136: assert_equal(["abc"], @s.fetch)
1137: assert_equal(["def"], @s.fetch)
1138: assert_equal(["abc,def"], @s.fetch)
1139: assert_equal(["abc"], @s.fetch)
1140: assert_equal(["def"], @s.fetch)
1141: assert_equal(["abc,def"], @s.fetch)
1142: assert_equal([""], @s.fetch)
1143: end
1144: end
# File test.rb, line 696
696: def test_fetch_smallint()
697: if @m.server_version >= 40100 then
698: @m.query("create temporary table t (i smallint)")
699: @m.query("insert into t values (0),(-1),(32767),(-32768),(65535),(-65535),(65536)")
700: @s.prepare("select i from t")
701: @s.execute
702: assert_equal([0], @s.fetch)
703: assert_equal([-1], @s.fetch)
704: assert_equal([32767], @s.fetch)
705: assert_equal([-32768], @s.fetch)
706: assert_equal([32767], @s.fetch)
707: assert_equal([-32768], @s.fetch)
708: end
709: end
# File test.rb, line 711
711: def test_fetch_smallint_unsigned()
712: if @m.server_version >= 40100 then
713: @m.query("create temporary table t (i smallint unsigned)")
714: @m.query("insert into t values (0),(-1),(32767),(-32768),(65535),(-65535),(65536)")
715: @s.prepare("select i from t")
716: @s.execute
717: assert_equal([0], @s.fetch)
718: assert_equal([0], @s.fetch)
719: assert_equal([32767], @s.fetch)
720: assert_equal([0], @s.fetch)
721: assert_equal([65535], @s.fetch)
722: assert_equal([0], @s.fetch)
723: assert_equal([65535], @s.fetch)
724: end
725: end
# File test.rb, line 1057
1057: def test_fetch_text()
1058: if @m.server_version >= 40100 then
1059: @m.query("create temporary table t (i text)")
1060: @m.query("insert into t values (null),('abc')")
1061: @s.prepare("select i from t")
1062: @s.execute
1063: assert_equal([nil], @s.fetch)
1064: assert_equal(["abc"], @s.fetch)
1065: end
1066: end
# File test.rb, line 954
954: def test_fetch_time()
955: if @m.server_version >= 40100 then
956: @m.query("create temporary table t (i time)")
957: @m.query("insert into t values ('-838:59:59'),(0),('838:59:59')")
958: @s.prepare("select i from t")
959: @s.execute
960: assert_equal([Mysql::Time.new(0,0,0,838,59,59,true)], @s.fetch)
961: assert_equal([Mysql::Time.new(0,0,0,0,0,0,false)], @s.fetch)
962: assert_equal([Mysql::Time.new(0,0,0,838,59,59,false)], @s.fetch)
963: end
964: end
# File test.rb, line 943
943: def test_fetch_timestamp()
944: if @m.server_version >= 40100 then
945: @m.query("create temporary table t (i timestamp)")
946: @m.query("insert into t values ('1970-01-01 12:00:00'),('2037-12-31 23:59:59')")
947: @s.prepare("select i from t")
948: @s.execute
949: assert_equal([Mysql::Time.new(1970,1,1,12,0,0)], @s.fetch)
950: assert_equal([Mysql::Time.new(2037,12,31,23,59,59)], @s.fetch)
951: end
952: end
# File test.rb, line 1024
1024: def test_fetch_tinyblob()
1025: if @m.server_version >= 40100 then
1026: @m.query("create temporary table t (i tinyblob)")
1027: @m.query("insert into t values (null),('abc')")
1028: @s.prepare("select i from t")
1029: @s.execute
1030: assert_equal([nil], @s.fetch)
1031: assert_equal(["abc"], @s.fetch)
1032: end
1033: end
# File test.rb, line 665
665: def test_fetch_tinyint()
666: if @m.server_version >= 40100 then
667: @m.query("create temporary table t (i tinyint)")
668: @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255)")
669: @s.prepare("select i from t")
670: @s.execute
671: assert_equal([0], @s.fetch)
672: assert_equal([-1], @s.fetch)
673: assert_equal([127], @s.fetch)
674: assert_equal([-128], @s.fetch)
675: assert_equal([127], @s.fetch)
676: assert_equal([-128], @s.fetch)
677: end
678: end
# File test.rb, line 680
680: def test_fetch_tinyint_unsigned()
681: if @m.server_version >= 40100 then
682: @m.query("create temporary table t (i tinyint unsigned)")
683: @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255),(256)")
684: @s.prepare("select i from t")
685: @s.execute
686: assert_equal([0], @s.fetch)
687: assert_equal([0], @s.fetch)
688: assert_equal([127], @s.fetch)
689: assert_equal([0], @s.fetch)
690: assert_equal([255], @s.fetch)
691: assert_equal([0], @s.fetch)
692: assert_equal([255], @s.fetch)
693: end
694: end
# File test.rb, line 1035
1035: def test_fetch_tinytext()
1036: if @m.server_version >= 40100 then
1037: @m.query("create temporary table t (i tinytext)")
1038: @m.query("insert into t values (null),('abc')")
1039: @s.prepare("select i from t")
1040: @s.execute
1041: assert_equal([nil], @s.fetch)
1042: assert_equal(["abc"], @s.fetch)
1043: end
1044: end
# File test.rb, line 1013
1013: def test_fetch_varbinary()
1014: if @m.server_version >= 40100 then
1015: @m.query("create temporary table t (i varbinary(10))")
1016: @m.query("insert into t values (null),('abc')")
1017: @s.prepare("select i from t")
1018: @s.execute
1019: assert_equal([nil], @s.fetch)
1020: assert_equal(["abc"], @s.fetch)
1021: end
1022: end
# File test.rb, line 991
991: def test_fetch_varchar()
992: if @m.server_version >= 40100 then
993: @m.query("create temporary table t (i varchar(10))")
994: @m.query("insert into t values (null),('abc')")
995: @s.prepare("select i from t")
996: @s.execute
997: assert_equal([nil], @s.fetch)
998: assert_equal(["abc"], @s.fetch)
999: end
1000: end
# File test.rb, line 966
966: def test_fetch_year()
967: if @m.server_version >= 40100 then
968: @m.query("create temporary table t (i year)")
969: @m.query("insert into t values (0),(70),(69),(1901),(2155)")
970: @s.prepare("select i from t")
971: @s.execute
972: assert_equal([0], @s.fetch)
973: assert_equal([1970], @s.fetch)
974: assert_equal([2069], @s.fetch)
975: assert_equal([1901], @s.fetch)
976: assert_equal([2155], @s.fetch)
977: end
978: end
# File test.rb, line 1169
1169: def test_field_count()
1170: if @m.server_version >= 40100 then
1171: @s.prepare("select 1,2,3")
1172: @s.execute()
1173: assert_equal(3, @s.field_count())
1174: @s.prepare("set @a=1")
1175: @s.execute()
1176: assert_equal(0, @s.field_count())
1177: end
1178: end
# File test.rb, line 1180
1180: def test_free_result()
1181: if @m.server_version >= 40100 then
1182: @s.free_result()
1183: @s.prepare("select 1,2,3")
1184: @s.execute()
1185: @s.free_result()
1186: end
1187: end
# File test.rb, line 1189
1189: def test_insert_id()
1190: if @m.server_version >= 40100 then
1191: @m.query("create temporary table t (i int auto_increment, unique(i))")
1192: @s.prepare("insert into t values (0)")
1193: @s.execute()
1194: assert_equal(1, @s.insert_id())
1195: @s.execute()
1196: assert_equal(2, @s.insert_id())
1197: end
1198: end
# File test.rb, line 1200
1200: def test_num_rows()
1201: if @m.server_version >= 40100 then
1202: @m.query("create temporary table t (i int)")
1203: @m.query("insert into t values (1),(2),(3),(4)")
1204: @s.prepare("select * from t")
1205: @s.execute
1206: assert_equal(4, @s.num_rows())
1207: end
1208: end
# File test.rb, line 1210
1210: def test_param_count()
1211: if @m.server_version >= 40100 then
1212: @m.query("create temporary table t (a int, b int, c int)")
1213: @s.prepare("select * from t")
1214: assert_equal(0, @s.param_count())
1215: @s.prepare("insert into t values (?,?,?)")
1216: assert_equal(3, @s.param_count())
1217: end
1218: end
# File test.rb, line 1226
1226: def test_prepare()
1227: if @m.server_version >= 40100 then
1228: @s.prepare("select 1")
1229: assert_raises(Mysql::Error){@s.prepare("invalid syntax")}
1230: end
1231: end
# File test.rb, line 1239
1239: def test_result_metadata()
1240: if @m.server_version >= 40100 then
1241: @s.prepare("select 1 foo, 2 bar")
1242: res = @s.result_metadata()
1243: f = res.fetch_fields
1244: assert_equal("foo", f[0].name)
1245: assert_equal("bar", f[1].name)
1246: end
1247: end
# File test.rb, line 1249
1249: def test_row_seek_tell()
1250: if @m.server_version >= 40100 then
1251: @m.query("create temporary table t (i int)")
1252: @m.query("insert into t values (0),(1),(2),(3),(4)")
1253: @s.prepare("select * from t")
1254: @s.execute
1255: row0 = @s.row_tell
1256: assert_equal([0], @s.fetch)
1257: assert_equal([1], @s.fetch)
1258: row2 = @s.row_seek(row0)
1259: assert_equal([0], @s.fetch)
1260: @s.row_seek(row2)
1261: assert_equal([2], @s.fetch)
1262: end
1263: end