| 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 1154
1154: def test_each()
1155: if @m.server_version >= 40100 then
1156: @m.query("create temporary table t (i int, c char(255), d datetime)")
1157: @m.query("insert into t values (1,'abc','19701224235905'),(2,'def','21120903123456'),(3,'123',null)")
1158: @s.prepare("select * from t")
1159: @s.execute
1160: c = 0
1161: @s.each do |a|
1162: case c
1163: when 0
1164: assert_equal([1,"abc",Mysql::Time.new(1970,12,24,23,59,05)], a)
1165: when 1
1166: assert_equal([2,"def",Mysql::Time.new(2112,9,3,12,34,56)], a)
1167: when 2
1168: assert_equal([3,"123",nil], a)
1169: else
1170: raise
1171: end
1172: c += 1
1173: end
1174: end
1175: 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: if @m.server_version >= 50000 then
800: assert_equal([9223372036854775807], @s.fetch)
801: else
802: assert_equal([-1], @s.fetch) # MySQL problem
803: end
804: assert_equal([-9223372036854775808], @s.fetch)
805: assert_equal([9223372036854775807], @s.fetch)
806: end
807: end
# File test.rb, line 809
809: def test_fetch_bigint_unsigned()
810: if @m.server_version >= 40100 then
811: @m.query("create temporary table t (i bigint unsigned)")
812: @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)")
813: @s.prepare("select i from t")
814: @s.execute
815: assert_equal([0], @s.fetch)
816: if @m.server_version >= 50000 then
817: assert_equal([0], @s.fetch)
818: else
819: assert_equal([-1], @s.fetch) # MySQL & MySQL/Ruby problem
820: end
821: assert_equal([9223372036854775807], @s.fetch)
822: if @m.server_version < 50000 then
823: assert_equal([-9223372036854775808], @s.fetch) # MySQL problem
824: else
825: assert_equal([0], @s.fetch)
826: end
827: assert_equal([-1], @s.fetch) # MySQL/Ruby problem
828: assert_equal([0], @s.fetch)
829: assert_equal([-1], @s.fetch) # MySQL/Ruby problem
830: end
831: end
# File test.rb, line 1006
1006: def test_fetch_binary()
1007: if @m.server_version >= 40100 then
1008: @m.query("create temporary table t (i binary(10))")
1009: @m.query("insert into t values (null),('abc')")
1010: @s.prepare("select i from t")
1011: @s.execute
1012: assert_equal([nil], @s.fetch)
1013: if @m.server_version >= 50000 then
1014: assert_equal(["abc\0\0\0\0\0\0\0"], @s.fetch)
1015: else
1016: assert_equal(["abc"], @s.fetch)
1017: end
1018: end
1019: end
# File test.rb, line 1054
1054: def test_fetch_blob()
1055: if @m.server_version >= 40100 then
1056: @m.query("create temporary table t (i blob)")
1057: @m.query("insert into t values (null),('abc')")
1058: @s.prepare("select i from t")
1059: @s.execute
1060: assert_equal([nil], @s.fetch)
1061: assert_equal(["abc"], @s.fetch)
1062: end
1063: end
# File test.rb, line 984
984: def test_fetch_char()
985: if @m.server_version >= 40100 then
986: @m.query("create temporary table t (i char(10))")
987: @m.query("insert into t values (null),('abc')")
988: @s.prepare("select i from t")
989: @s.execute
990: assert_equal([nil], @s.fetch)
991: assert_equal(["abc"], @s.fetch)
992: end
993: end
# File test.rb, line 923
923: def test_fetch_date()
924: if @m.server_version >= 40100 then
925: @m.query("create temporary table t (i date)")
926: @m.query("insert into t values ('0000-00-00'),('1000-01-01'),('9999-12-31')")
927: @s.prepare("select i from t")
928: @s.execute
929: assert_equal([Mysql::Time.new(0,0,0)], @s.fetch)
930: assert_equal([Mysql::Time.new(1000,1,1)], @s.fetch)
931: assert_equal([Mysql::Time.new(9999,12,31)], @s.fetch)
932: end
933: end
# File test.rb, line 935
935: def test_fetch_datetime()
936: if @m.server_version >= 40100 then
937: @m.query("create temporary table t (i datetime)")
938: @m.query("insert into t values ('0000-00-00 00:00:00'),('1000-01-01 00:00:00'),('9999-12-31 23:59:59')")
939: @s.prepare("select i from t")
940: @s.execute
941: assert_equal([Mysql::Time.new(0,0,0,0,0,0)], @s.fetch)
942: assert_equal([Mysql::Time.new(1000,1,1,0,0,0)], @s.fetch)
943: assert_equal([Mysql::Time.new(9999,12,31,23,59,59)], @s.fetch)
944: end
945: end
# File test.rb, line 889
889: def test_fetch_decimal()
890: if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then
891: @m.query("create temporary table t (i decimal)")
892: @m.query("insert into t values (0),(9999999999),(-9999999999),(10000000000),(-10000000000)")
893: @s.prepare("select i from t")
894: @s.execute
895: assert_equal(["0"], @s.fetch)
896: assert_equal(["9999999999"], @s.fetch)
897: assert_equal(["-9999999999"], @s.fetch)
898: if @m.server_version < 50000 then
899: assert_equal(["10000000000"], @s.fetch) # MySQL problem
900: else
901: assert_equal(["9999999999"], @s.fetch)
902: end
903: assert_equal(["-9999999999"], @s.fetch)
904: end
905: end
# File test.rb, line 907
907: def test_fetch_decimal_unsigned()
908: if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then
909: @m.query("create temporary table t (i decimal unsigned)")
910: @m.query("insert into t values (0),(9999999998),(9999999999),(-9999999998),(-9999999999),(10000000000),(-10000000000)")
911: @s.prepare("select i from t")
912: @s.execute
913: assert_equal(["0"], @s.fetch)
914: assert_equal(["9999999998"], @s.fetch)
915: assert_equal(["9999999999"], @s.fetch)
916: assert_equal(["0"], @s.fetch)
917: assert_equal(["0"], @s.fetch)
918: assert_equal(["9999999999"], @s.fetch)
919: assert_equal(["0"], @s.fetch)
920: end
921: end
# File test.rb, line 861
861: def test_fetch_double()
862: if @m.server_version >= 40100 then
863: @m.query("create temporary table t (i double)")
864: @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)")
865: @s.prepare("select i from t")
866: @s.execute
867: assert_equal([0], @s.fetch)
868: assert_in_delta(-Float::MAX, @s.fetch[0], Float::EPSILON)
869: assert_in_delta(-Float::MIN, @s.fetch[0], Float::EPSILON)
870: assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON)
871: assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON)
872: end
873: end
# File test.rb, line 875
875: def test_fetch_double_unsigned()
876: if @m.server_version >= 40100 then
877: @m.query("create temporary table t (i double unsigned)")
878: @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)")
879: @s.prepare("select i from t")
880: @s.execute
881: assert_equal([0], @s.fetch)
882: assert_equal([0], @s.fetch)
883: assert_equal([0], @s.fetch)
884: assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON)
885: assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON)
886: end
887: end
# File test.rb, line 1120
1120: def test_fetch_enum()
1121: if @m.server_version >= 40100 then
1122: @m.query("create temporary table t (i enum('abc','def'))")
1123: @m.query("insert into t values (null),(0),(1),(2),('abc'),('def'),('ghi')")
1124: @s.prepare("select i from t")
1125: @s.execute
1126: assert_equal([nil], @s.fetch)
1127: assert_equal([""], @s.fetch)
1128: assert_equal(["abc"], @s.fetch)
1129: assert_equal(["def"], @s.fetch)
1130: assert_equal(["abc"], @s.fetch)
1131: assert_equal(["def"], @s.fetch)
1132: assert_equal([""], @s.fetch)
1133: end
1134: end
# File test.rb, line 833
833: def test_fetch_float()
834: if @m.server_version >= 40100 then
835: @m.query("create temporary table t (i float)")
836: @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)")
837: @s.prepare("select i from t")
838: @s.execute
839: assert_equal([0], @s.fetch)
840: assert_in_delta(-3.402823466E+38, @s.fetch[0], 0.000000001E+38)
841: assert_in_delta(-1.175494351E-38, @s.fetch[0], 0.000000001E-38)
842: assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38)
843: assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38)
844: end
845: end
# File test.rb, line 847
847: def test_fetch_float_unsigned()
848: if @m.server_version >= 40100 then
849: @m.query("create temporary table t (i float unsigned)")
850: @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)")
851: @s.prepare("select i from t")
852: @s.execute
853: assert_equal([0], @s.fetch)
854: assert_equal([0], @s.fetch)
855: assert_equal([0], @s.fetch)
856: assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38)
857: assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38)
858: end
859: 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 1098
1098: def test_fetch_longblob()
1099: if @m.server_version >= 40100 then
1100: @m.query("create temporary table t (i longblob)")
1101: @m.query("insert into t values (null),('abc')")
1102: @s.prepare("select i from t")
1103: @s.execute
1104: assert_equal([nil], @s.fetch)
1105: assert_equal(["abc"], @s.fetch)
1106: end
1107: end
# File test.rb, line 1109
1109: def test_fetch_longtext()
1110: if @m.server_version >= 40100 then
1111: @m.query("create temporary table t (i longtext)")
1112: @m.query("insert into t values (null),('abc')")
1113: @s.prepare("select i from t")
1114: @s.execute
1115: assert_equal([nil], @s.fetch)
1116: assert_equal(["abc"], @s.fetch)
1117: end
1118: end
# File test.rb, line 1076
1076: def test_fetch_mediumblob()
1077: if @m.server_version >= 40100 then
1078: @m.query("create temporary table t (i mediumblob)")
1079: @m.query("insert into t values (null),('abc')")
1080: @s.prepare("select i from t")
1081: @s.execute
1082: assert_equal([nil], @s.fetch)
1083: assert_equal(["abc"], @s.fetch)
1084: end
1085: 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 1087
1087: def test_fetch_mediumtext()
1088: if @m.server_version >= 40100 then
1089: @m.query("create temporary table t (i mediumtext)")
1090: @m.query("insert into t values (null),('abc')")
1091: @s.prepare("select i from t")
1092: @s.execute
1093: assert_equal([nil], @s.fetch)
1094: assert_equal(["abc"], @s.fetch)
1095: end
1096: end
# File test.rb, line 1136
1136: def test_fetch_set()
1137: if @m.server_version >= 40100 then
1138: @m.query("create temporary table t (i set('abc','def'))")
1139: @m.query("insert into t values (null),(0),(1),(2),(3),('abc'),('def'),('abc,def'),('ghi')")
1140: @s.prepare("select i from t")
1141: @s.execute
1142: assert_equal([nil], @s.fetch)
1143: assert_equal([""], @s.fetch)
1144: assert_equal(["abc"], @s.fetch)
1145: assert_equal(["def"], @s.fetch)
1146: assert_equal(["abc,def"], @s.fetch)
1147: assert_equal(["abc"], @s.fetch)
1148: assert_equal(["def"], @s.fetch)
1149: assert_equal(["abc,def"], @s.fetch)
1150: assert_equal([""], @s.fetch)
1151: end
1152: 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 1065
1065: def test_fetch_text()
1066: if @m.server_version >= 40100 then
1067: @m.query("create temporary table t (i text)")
1068: @m.query("insert into t values (null),('abc')")
1069: @s.prepare("select i from t")
1070: @s.execute
1071: assert_equal([nil], @s.fetch)
1072: assert_equal(["abc"], @s.fetch)
1073: end
1074: end
# File test.rb, line 958
958: def test_fetch_time()
959: if @m.server_version >= 40100 then
960: @m.query("create temporary table t (i time)")
961: @m.query("insert into t values ('-838:59:59'),(0),('838:59:59')")
962: @s.prepare("select i from t")
963: @s.execute
964: assert_equal([Mysql::Time.new(0,0,0,838,59,59,true)], @s.fetch)
965: assert_equal([Mysql::Time.new(0,0,0,0,0,0,false)], @s.fetch)
966: assert_equal([Mysql::Time.new(0,0,0,838,59,59,false)], @s.fetch)
967: end
968: end
# File test.rb, line 947
947: def test_fetch_timestamp()
948: if @m.server_version >= 40100 then
949: @m.query("create temporary table t (i timestamp)")
950: @m.query("insert into t values ('1970-01-02 00:00:00'),('2037-12-30 23:59:59')")
951: @s.prepare("select i from t")
952: @s.execute
953: assert_equal([Mysql::Time.new(1970,1,2,0,0,0)], @s.fetch)
954: assert_equal([Mysql::Time.new(2037,12,30,23,59,59)], @s.fetch)
955: end
956: end
# File test.rb, line 1032
1032: def test_fetch_tinyblob()
1033: if @m.server_version >= 40100 then
1034: @m.query("create temporary table t (i tinyblob)")
1035: @m.query("insert into t values (null),('abc')")
1036: @s.prepare("select i from t")
1037: @s.execute
1038: assert_equal([nil], @s.fetch)
1039: assert_equal(["abc"], @s.fetch)
1040: end
1041: 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 1043
1043: def test_fetch_tinytext()
1044: if @m.server_version >= 40100 then
1045: @m.query("create temporary table t (i tinytext)")
1046: @m.query("insert into t values (null),('abc')")
1047: @s.prepare("select i from t")
1048: @s.execute
1049: assert_equal([nil], @s.fetch)
1050: assert_equal(["abc"], @s.fetch)
1051: end
1052: end
# File test.rb, line 1021
1021: def test_fetch_varbinary()
1022: if @m.server_version >= 40100 then
1023: @m.query("create temporary table t (i varbinary(10))")
1024: @m.query("insert into t values (null),('abc')")
1025: @s.prepare("select i from t")
1026: @s.execute
1027: assert_equal([nil], @s.fetch)
1028: assert_equal(["abc"], @s.fetch)
1029: end
1030: end
# File test.rb, line 995
995: def test_fetch_varchar()
996: if @m.server_version >= 40100 then
997: @m.query("create temporary table t (i varchar(10))")
998: @m.query("insert into t values (null),('abc')")
999: @s.prepare("select i from t")
1000: @s.execute
1001: assert_equal([nil], @s.fetch)
1002: assert_equal(["abc"], @s.fetch)
1003: end
1004: end
# File test.rb, line 970
970: def test_fetch_year()
971: if @m.server_version >= 40100 then
972: @m.query("create temporary table t (i year)")
973: @m.query("insert into t values (0),(70),(69),(1901),(2155)")
974: @s.prepare("select i from t")
975: @s.execute
976: assert_equal([0], @s.fetch)
977: assert_equal([1970], @s.fetch)
978: assert_equal([2069], @s.fetch)
979: assert_equal([1901], @s.fetch)
980: assert_equal([2155], @s.fetch)
981: end
982: end
# File test.rb, line 1177
1177: def test_field_count()
1178: if @m.server_version >= 40100 then
1179: @s.prepare("select 1,2,3")
1180: @s.execute()
1181: assert_equal(3, @s.field_count())
1182: @s.prepare("set @a=1")
1183: @s.execute()
1184: assert_equal(0, @s.field_count())
1185: end
1186: end
# File test.rb, line 1188
1188: def test_free_result()
1189: if @m.server_version >= 40100 then
1190: @s.free_result()
1191: @s.prepare("select 1,2,3")
1192: @s.execute()
1193: @s.free_result()
1194: end
1195: end
# File test.rb, line 1197
1197: def test_insert_id()
1198: if @m.server_version >= 40100 then
1199: @m.query("create temporary table t (i int auto_increment, unique(i))")
1200: @s.prepare("insert into t values (0)")
1201: @s.execute()
1202: assert_equal(1, @s.insert_id())
1203: @s.execute()
1204: assert_equal(2, @s.insert_id())
1205: end
1206: end
# File test.rb, line 1208
1208: def test_num_rows()
1209: if @m.server_version >= 40100 then
1210: @m.query("create temporary table t (i int)")
1211: @m.query("insert into t values (1),(2),(3),(4)")
1212: @s.prepare("select * from t")
1213: @s.execute
1214: assert_equal(4, @s.num_rows())
1215: end
1216: end
# File test.rb, line 1218
1218: def test_param_count()
1219: if @m.server_version >= 40100 then
1220: @m.query("create temporary table t (a int, b int, c int)")
1221: @s.prepare("select * from t")
1222: assert_equal(0, @s.param_count())
1223: @s.prepare("insert into t values (?,?,?)")
1224: assert_equal(3, @s.param_count())
1225: end
1226: end
# File test.rb, line 1234
1234: def test_prepare()
1235: if @m.server_version >= 40100 then
1236: @s.prepare("select 1")
1237: assert_raises(Mysql::Error){@s.prepare("invalid syntax")}
1238: end
1239: end
# File test.rb, line 1247
1247: def test_result_metadata()
1248: if @m.server_version >= 40100 then
1249: @s.prepare("select 1 foo, 2 bar")
1250: res = @s.result_metadata()
1251: f = res.fetch_fields
1252: assert_equal("foo", f[0].name)
1253: assert_equal("bar", f[1].name)
1254: end
1255: end
# File test.rb, line 1257
1257: def test_row_seek_tell()
1258: if @m.server_version >= 40100 then
1259: @m.query("create temporary table t (i int)")
1260: @m.query("insert into t values (0),(1),(2),(3),(4)")
1261: @s.prepare("select * from t")
1262: @s.execute
1263: row0 = @s.row_tell
1264: assert_equal([0], @s.fetch)
1265: assert_equal([1], @s.fetch)
1266: row2 = @s.row_seek(row0)
1267: assert_equal([0], @s.fetch)
1268: @s.row_seek(row2)
1269: assert_equal([2], @s.fetch)
1270: end
1271: end