Test::Unit::TestCase
# File test.rb, line 443 443: def setup() 444: @host, @user, @pass, db, port, sock, flag = ARGV 445: @db = db || "test" 446: @port = port.to_i 447: @sock = sock.nil? || sock.empty? ? nil : sock 448: @flag = flag.to_i 449: @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag) 450: @s = @m.stmt_init() 451: end
# File test.rb, line 452 452: def teardown() 453: @s.close 454: @m.close 455: end
# File test.rb, line 457 457: def test_affected_rows() 458: if @m.server_version >= 40100 then 459: @m.query("create temporary table t (i int, c char(10))") 460: @s.prepare("insert into t values (?,?)") 461: @s.execute(1, "hoge") 462: assert_equal(1, @s.affected_rows()) 463: @s.execute(2, "hoge") 464: @s.execute(3, "hoge") 465: @s.prepare("update t set c=?") 466: @s.execute("fuga") 467: assert_equal(3, @s.affected_rows()) 468: end 469: end
# File test.rb, line 539 539: def test_bind_result_fixnum() 540: if @m.server_version >= 40100 then 541: @m.query("create temporary table t (i int, c char(10), d double, t datetime)") 542: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") 543: @s.prepare("select * from t") 544: @s.bind_result(Fixnum, Fixnum, Fixnum, Fixnum) 545: @s.execute 546: a = @s.fetch 547: if Mysql.client_version < 50000 then 548: assert_equal([123, 9, 1, 2005], a) 549: else 550: assert_equal([123, 9, 1, 20050802235011.0], a) 551: end 552: end 553: end
# File test.rb, line 567 567: def test_bind_result_float() 568: if @m.server_version >= 40100 then 569: @m.query("create temporary table t (i int, c char(10), d double, t datetime)") 570: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") 571: @s.prepare("select * from t") 572: @s.bind_result(Float, Float, Float, Float) 573: @s.execute 574: a = @s.fetch 575: if Mysql.client_version < 50000 then 576: assert_equal([123.0, 9.0, 1.2345, 2005.0], a) 577: else 578: assert_equal([123.0, 9.0, 1.2345, 20050802235011.0], a) 579: end 580: end 581: end
# File test.rb, line 523 523: def test_bind_result_integer() 524: if @m.server_version >= 40100 then 525: @m.query("create temporary table t (i int, c char(10), d double, t datetime)") 526: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") 527: @s.prepare("select * from t") 528: @s.bind_result(Integer, Integer, Integer, Integer) 529: @s.execute 530: a = @s.fetch 531: if Mysql.client_version < 50000 then 532: assert_equal([123, 9, 1, 2005], a) 533: else 534: assert_equal([123, 9, 1, 20050802235011], a) 535: end 536: end 537: end
# File test.rb, line 583 583: def test_bind_result_mysqltime() 584: if @m.server_version >= 40100 then 585: @m.query("create temporary table t (i int, c char(10), d double, t datetime)") 586: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") 587: @s.prepare("select * from t") 588: @s.bind_result(Mysql::Time, Mysql::Time, Mysql::Time, Mysql::Time) 589: @s.execute 590: a = @s.fetch 591: if Mysql.client_version < 50000 then 592: assert_equal([Mysql::Time.new, Mysql::Time.new, Mysql::Time.new, Mysql::Time.new(2005,8,2,23,50,11)], a) 593: else 594: assert_equal([Mysql::Time.new(2000,1,23), Mysql::Time.new, Mysql::Time.new, Mysql::Time.new(2005,8,2,23,50,11)], a) 595: end 596: end 597: end
# File test.rb, line 495 495: def test_bind_result_nil() 496: if @m.server_version >= 40100 then 497: @m.query("create temporary table t (i int, c char(10), d double, t datetime)") 498: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") 499: @s.prepare("select * from t") 500: @s.bind_result(nil,nil,nil,nil) 501: @s.execute 502: a = @s.fetch 503: assert_equal([123, "9abcdefg", 1.2345, Mysql::Time.new(2005,8,2,23,50,11)], a) 504: end 505: end
# File test.rb, line 507 507: def test_bind_result_numeric() 508: if @m.server_version >= 40100 then 509: @m.query("create temporary table t (i int, c char(10), d double, t datetime)") 510: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") 511: @s.prepare("select * from t") 512: @s.bind_result(Numeric, Numeric, Numeric, Numeric) 513: @s.execute 514: a = @s.fetch 515: if Mysql.client_version < 50000 then 516: assert_equal([123, 9, 1, 2005], a) 517: else 518: assert_equal([123, 9, 1, 20050802235011], a) 519: end 520: end 521: end
# File test.rb, line 555 555: def test_bind_result_string() 556: if @m.server_version >= 40100 then 557: @m.query("create temporary table t (i int, c char(10), d double, t datetime)") 558: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") 559: @s.prepare("select * from t") 560: @s.bind_result(String, String, String, String) 561: @s.execute 562: a = @s.fetch 563: assert_equal(["123", "9abcdefg", "1.2345", "2005-08-02 23:50:11"], a) 564: end 565: end
# File test.rb, line 599 599: def test_bind_result_unknown() 600: if @m.server_version >= 40100 then 601: @m.query("create temporary table t (i int, c char(10), d double, t datetime)") 602: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") 603: @s.prepare("select * from t") 604: assert_raises(TypeError){@s.bind_result(Time, nil, nil, nil)} 605: end 606: end
# File test.rb, line 608 608: def test_bind_result_unmatch_count() 609: if @m.server_version >= 40100 then 610: @m.query("create temporary table t (i int, c char(10), d double, t datetime)") 611: @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") 612: @s.prepare("select * from t") 613: assert_raises(Mysql::Error){@s.bind_result(nil, nil)} 614: end 615: end
# File test.rb, line 617 617: def test_data_seek() 618: if @m.server_version >= 40100 then 619: @m.query("create temporary table t (i int)") 620: @m.query("insert into t values (0),(1),(2),(3),(4),(5)") 621: @s.prepare("select i from t") 622: @s.execute 623: assert_equal([0], @s.fetch) 624: assert_equal([1], @s.fetch) 625: assert_equal([2], @s.fetch) 626: @s.data_seek(5) 627: assert_equal([5], @s.fetch) 628: @s.data_seek(1) 629: assert_equal([1], @s.fetch) 630: end 631: end
# File test.rb, line 1227 1227: def test_each() 1228: if @m.server_version >= 40100 then 1229: @m.query("create temporary table t (i int, c char(255), d datetime)") 1230: @m.query("insert into t values (1,'abc','19701224235905'),(2,'def','21120903123456'),(3,'123',null)") 1231: @s.prepare("select * from t") 1232: @s.execute 1233: c = 0 1234: @s.each do |a| 1235: case c 1236: when 0 1237: assert_equal([1,"abc",Mysql::Time.new(1970,12,24,23,59,05)], a) 1238: assert_equal(Encoding.default_external, a[1].encoding) if RUBY_VERSION =~ /1.9/ 1239: when 1 1240: assert_equal([2,"def",Mysql::Time.new(2112,9,3,12,34,56)], a) 1241: when 2 1242: assert_equal([3,"123",nil], a) 1243: else 1244: raise 1245: end 1246: c += 1 1247: end 1248: end 1249: end
# File test.rb, line 643 643: def test_execute() 644: if @m.server_version >= 40100 then 645: @m.query("create temporary table t (i int)") 646: @s.prepare("insert into t values (123)") 647: @s.execute() 648: assert_equal(1, @s.affected_rows) 649: @s.execute() 650: assert_equal(1, @s.affected_rows) 651: assert_equal(2, @m.query("select count(*) from t").fetch_row[0].to_i) 652: end 653: end
# File test.rb, line 655 655: def test_execute2() 656: if @m.server_version >= 40100 then 657: @m.query("create temporary table t (i int)") 658: @s.prepare("insert into t values (?)") 659: @s.execute(123) 660: @s.execute("456") 661: @s.prepare("select * from t") 662: @s.execute 663: assert_equal([123], @s.fetch) 664: assert_equal([456], @s.fetch) 665: end 666: end
# File test.rb, line 668 668: def test_execute3() 669: if @m.server_version >= 40100 then 670: @m.query("create temporary table t (i int, c char(255), t timestamp)") 671: @s.prepare("insert into t values (?,?,?)") 672: @s.execute(123, "hoge", Time.local(2005,7,19,23,53,0)); 673: assert_raises(Mysql::Error){@s.execute(123, "hoge")} 674: assert_raises(Mysql::Error){@s.execute(123, "hoge", 0, "fuga")} 675: @s.prepare("select * from t") 676: @s.execute 677: assert_equal([123, "hoge", Mysql::Time.new(2005,7,19,23,53,0)], @s.fetch) 678: end 679: end
# File test.rb, line 681 681: def test_execute4() 682: if @m.server_version >= 40100 then 683: @m.query("create temporary table t (i int, c char(255), t timestamp)") 684: @s.prepare("insert into t values (?,?,?)") 685: @s.execute(nil, "hoge", Mysql::Time.new(2005,7,19,23,53,0)); 686: @s.prepare("select * from t") 687: @s.execute 688: assert_equal([nil, "hoge", Mysql::Time.new(2005,7,19,23,53,0)], @s.fetch) 689: end 690: end
# File test.rb, line 692 692: def test_execute5() 693: if @m.server_version >= 40100 then 694: [30, 31, 32, 62, 63].each do |i| 695: v, = @m.prepare("select cast(? as signed)").execute(2**i-1).fetch 696: assert_equal(2**i-1, v) 697: v, = @m.prepare("select cast(? as signed)").execute(-(2**i)).fetch 698: assert_equal(-(2**i), v) 699: end 700: end 701: end
# File test.rb, line 703 703: def test_fetch() 704: if @m.server_version >= 40100 then 705: @s.prepare("select 123, 'abc', null") 706: @s.execute() 707: assert_equal([123, "abc", nil], @s.fetch()) 708: end 709: end
# File test.rb, line 860 860: def test_fetch_bigint() 861: if @m.server_version >= 40100 then 862: @m.query("create temporary table t (i bigint)") 863: @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)") 864: @s.prepare("select i from t") 865: @s.execute 866: assert_equal([0], @s.fetch) 867: assert_equal([1], @s.fetch) 868: assert_equal([9223372036854775807], @s.fetch) 869: assert_equal([9223372036854775808], @s.fetch) 870: if @m.server_version >= 50000 then 871: assert_equal([9223372036854775807], @s.fetch) 872: else 873: assert_equal([1], @s.fetch) # MySQL problem 874: end 875: assert_equal([9223372036854775808], @s.fetch) 876: assert_equal([9223372036854775807], @s.fetch) 877: end 878: end
# File test.rb, line 880 880: def test_fetch_bigint_unsigned() 881: if @m.server_version >= 40100 then 882: @m.query("create temporary table t (i bigint unsigned)") 883: @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)") 884: @s.prepare("select i from t") 885: @s.execute 886: assert_equal([0], @s.fetch) 887: if @m.server_version >= 50000 then 888: assert_equal([0], @s.fetch) 889: else 890: assert_equal([18446744073709551615], @s.fetch) # MySQL problem 891: end 892: assert_equal([9223372036854775807], @s.fetch) 893: if @m.server_version >= 50000 then 894: assert_equal([0], @s.fetch) 895: else 896: assert_equal([9223372036854775808], @s.fetch) # MySQL problem 897: end 898: assert_equal([18446744073709551615], @s.fetch) 899: assert_equal([0], @s.fetch) 900: assert_equal([18446744073709551615], @s.fetch) 901: end 902: end
# File test.rb, line 1077 1077: def test_fetch_binary() 1078: if @m.server_version >= 40100 then 1079: @m.query("create temporary table t (i binary(10))") 1080: @m.query("insert into t values (null),('abc')") 1081: @s.prepare("select i from t") 1082: @s.execute 1083: assert_equal([nil], @s.fetch) 1084: if @m.server_version >= 50000 then 1085: assert_equal(["abc\00\\00\\00\\00\\00\\00\\00""], @s.fetch) 1086: else 1087: assert_equal(["abc"], @s.fetch) 1088: end 1089: end 1090: end
# File test.rb, line 711 711: def test_fetch_bit() 712: if @m.client_version >= 50003 and @m.server_version >= 50003 then 713: @m.query("create temporary table t (i bit(8))") 714: @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255),(256)") 715: @s.prepare("select i from t") 716: @s.execute 717: assert_equal(["\x00"], @s.fetch) 718: assert_equal(["\xff"], @s.fetch) 719: assert_equal(["\x7f"], @s.fetch) 720: assert_equal(["\xff"], @s.fetch) 721: assert_equal(["\xff"], @s.fetch) 722: assert_equal(["\xff"], @s.fetch) 723: assert_equal(["\xff"], @s.fetch) 724: @m.query("create temporary table t2 (i bit(64))") 725: @m.query("insert into t2 values (0),(-1),(4294967296),(18446744073709551615),(18446744073709551616)") 726: @s.prepare("select i from t2") 727: @s.execute 728: assert_equal(["\x00\x00\x00\x00\x00\x00\x00\x00"], @s.fetch) 729: assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch) 730: assert_equal(["\x00\x00\x00\x01\x00\x00\x00\x00"], @s.fetch) 731: assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch) 732: assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch) 733: end 734: end
# File test.rb, line 1125 1125: def test_fetch_blob() 1126: if @m.server_version >= 40100 then 1127: @m.query("create temporary table t (i blob)") 1128: @m.query("insert into t values (null),('abc')") 1129: @s.prepare("select i from t") 1130: @s.execute 1131: assert_equal([nil], @s.fetch) 1132: assert_equal(["abc"], @s.fetch) 1133: end 1134: end
# File test.rb, line 1055 1055: def test_fetch_char() 1056: if @m.server_version >= 40100 then 1057: @m.query("create temporary table t (i char(10))") 1058: @m.query("insert into t values (null),('abc')") 1059: @s.prepare("select i from t") 1060: @s.execute 1061: assert_equal([nil], @s.fetch) 1062: assert_equal(["abc"], @s.fetch) 1063: end 1064: end
# File test.rb, line 994 994: def test_fetch_date() 995: if @m.server_version >= 40100 then 996: @m.query("create temporary table t (i date)") 997: @m.query("insert into t values ('0000-00-00'),('1000-01-01'),('9999-12-31')") 998: @s.prepare("select i from t") 999: @s.execute 1000: assert_equal([Mysql::Time.new(0,0,0)], @s.fetch) 1001: assert_equal([Mysql::Time.new(1000,1,1)], @s.fetch) 1002: assert_equal([Mysql::Time.new(9999,12,31)], @s.fetch) 1003: end 1004: end
# File test.rb, line 1006 1006: def test_fetch_datetime() 1007: if @m.server_version >= 40100 then 1008: @m.query("create temporary table t (i datetime)") 1009: @m.query("insert into t values ('0000-00-00 00:00:00'),('1000-01-01 00:00:00'),('9999-12-31 23:59:59')") 1010: @s.prepare("select i from t") 1011: @s.execute 1012: assert_equal([Mysql::Time.new(0,0,0,0,0,0)], @s.fetch) 1013: assert_equal([Mysql::Time.new(1000,1,1,0,0,0)], @s.fetch) 1014: assert_equal([Mysql::Time.new(9999,12,31,23,59,59)], @s.fetch) 1015: end 1016: end
# File test.rb, line 960 960: def test_fetch_decimal() 961: if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then 962: @m.query("create temporary table t (i decimal)") 963: @m.query("insert into t values (0),(9999999999),(-9999999999),(10000000000),(-10000000000)") 964: @s.prepare("select i from t") 965: @s.execute 966: assert_equal(["0"], @s.fetch) 967: assert_equal(["9999999999"], @s.fetch) 968: assert_equal(["-9999999999"], @s.fetch) 969: if @m.server_version < 50000 then 970: assert_equal(["10000000000"], @s.fetch) # MySQL problem 971: else 972: assert_equal(["9999999999"], @s.fetch) 973: end 974: assert_equal(["-9999999999"], @s.fetch) 975: end 976: end
# File test.rb, line 978 978: def test_fetch_decimal_unsigned() 979: if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then 980: @m.query("create temporary table t (i decimal unsigned)") 981: @m.query("insert into t values (0),(9999999998),(9999999999),(-9999999998),(-9999999999),(10000000000),(-10000000000)") 982: @s.prepare("select i from t") 983: @s.execute 984: assert_equal(["0"], @s.fetch) 985: assert_equal(["9999999998"], @s.fetch) 986: assert_equal(["9999999999"], @s.fetch) 987: assert_equal(["0"], @s.fetch) 988: assert_equal(["0"], @s.fetch) 989: assert_equal(["9999999999"], @s.fetch) 990: assert_equal(["0"], @s.fetch) 991: end 992: end
# File test.rb, line 932 932: def test_fetch_double() 933: if @m.server_version >= 40100 then 934: @m.query("create temporary table t (i double)") 935: @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)") 936: @s.prepare("select i from t") 937: @s.execute 938: assert_equal([0], @s.fetch) 939: assert_in_delta(-Float::MAX, @s.fetch[0], Float::EPSILON) 940: assert_in_delta(-Float::MIN, @s.fetch[0], Float::EPSILON) 941: assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON) 942: assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON) 943: end 944: end
# File test.rb, line 946 946: def test_fetch_double_unsigned() 947: if @m.server_version >= 40100 then 948: @m.query("create temporary table t (i double unsigned)") 949: @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)") 950: @s.prepare("select i from t") 951: @s.execute 952: assert_equal([0], @s.fetch) 953: assert_equal([0], @s.fetch) 954: assert_equal([0], @s.fetch) 955: assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON) 956: assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON) 957: end 958: end
# File test.rb, line 1191 1191: def test_fetch_enum() 1192: if @m.server_version >= 40100 then 1193: @m.query("create temporary table t (i enum('abc','def'))") 1194: @m.query("insert into t values (null),(0),(1),(2),('abc'),('def'),('ghi')") 1195: @s.prepare("select i from t") 1196: @s.execute 1197: assert_equal([nil], @s.fetch) 1198: assert_equal([""], @s.fetch) 1199: row = @s.fetch 1200: assert_equal(Encoding.default_external, row[0].encoding) if RUBY_VERSION =~ /1.9/ 1201: assert_equal(["abc"], row) 1202: assert_equal(["def"], @s.fetch) 1203: assert_equal(["abc"], @s.fetch) 1204: assert_equal(["def"], @s.fetch) 1205: assert_equal([""], @s.fetch) 1206: end 1207: end
# File test.rb, line 904 904: def test_fetch_float() 905: if @m.server_version >= 40100 then 906: @m.query("create temporary table t (i float)") 907: @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)") 908: @s.prepare("select i from t") 909: @s.execute 910: assert_equal([0], @s.fetch) 911: assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38) 912: assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38) 913: assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38) 914: assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38) 915: end 916: end
# File test.rb, line 918 918: def test_fetch_float_unsigned() 919: if @m.server_version >= 40100 then 920: @m.query("create temporary table t (i float unsigned)") 921: @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)") 922: @s.prepare("select i from t") 923: @s.execute 924: assert_equal([0], @s.fetch) 925: assert_equal([0], @s.fetch) 926: assert_equal([0], @s.fetch) 927: assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38) 928: assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38) 929: end 930: end
# File test.rb, line 829 829: def test_fetch_int() 830: if @m.server_version >= 40100 then 831: @m.query("create temporary table t (i int)") 832: @m.query("insert into t values (0),(-1),(2147483647),(-2147483648),(4294967295),(-4294967295),(4294967296)") 833: @s.prepare("select i from t") 834: @s.execute 835: assert_equal([0], @s.fetch) 836: assert_equal([1], @s.fetch) 837: assert_equal([2147483647], @s.fetch) 838: assert_equal([2147483648], @s.fetch) 839: assert_equal([2147483647], @s.fetch) 840: assert_equal([2147483648], @s.fetch) 841: end 842: end
# File test.rb, line 844 844: def test_fetch_int_unsigned() 845: if @m.server_version >= 40100 then 846: @m.query("create temporary table t (i int unsigned)") 847: @m.query("insert into t values (0),(-1),(2147483647),(-2147483648),(4294967295),(-4294967295),(4294967296)") 848: @s.prepare("select i from t") 849: @s.execute 850: assert_equal([0], @s.fetch) 851: assert_equal([0], @s.fetch) 852: assert_equal([2147483647], @s.fetch) 853: assert_equal([0], @s.fetch) 854: assert_equal([4294967295], @s.fetch) 855: assert_equal([0], @s.fetch) 856: assert_equal([4294967295], @s.fetch) 857: end 858: end
# File test.rb, line 1169 1169: def test_fetch_longblob() 1170: if @m.server_version >= 40100 then 1171: @m.query("create temporary table t (i longblob)") 1172: @m.query("insert into t values (null),('abc')") 1173: @s.prepare("select i from t") 1174: @s.execute 1175: assert_equal([nil], @s.fetch) 1176: assert_equal(["abc"], @s.fetch) 1177: end 1178: end
# File test.rb, line 1180 1180: def test_fetch_longtext() 1181: if @m.server_version >= 40100 then 1182: @m.query("create temporary table t (i longtext)") 1183: @m.query("insert into t values (null),('abc')") 1184: @s.prepare("select i from t") 1185: @s.execute 1186: assert_equal([nil], @s.fetch) 1187: assert_equal(["abc"], @s.fetch) 1188: end 1189: end
# File test.rb, line 1147 1147: def test_fetch_mediumblob() 1148: if @m.server_version >= 40100 then 1149: @m.query("create temporary table t (i mediumblob)") 1150: @m.query("insert into t values (null),('abc')") 1151: @s.prepare("select i from t") 1152: @s.execute 1153: assert_equal([nil], @s.fetch) 1154: assert_equal(["abc"], @s.fetch) 1155: end 1156: end
# File test.rb, line 798 798: def test_fetch_mediumint() 799: if @m.server_version >= 40100 then 800: @m.query("create temporary table t (i mediumint)") 801: @m.query("insert into t values (0),(-1),(8388607),(-8388608),(16777215),(-16777215),(16777216)") 802: @s.prepare("select i from t") 803: @s.execute 804: assert_equal([0], @s.fetch) 805: assert_equal([1], @s.fetch) 806: assert_equal([8388607], @s.fetch) 807: assert_equal([8388608], @s.fetch) 808: assert_equal([8388607], @s.fetch) 809: assert_equal([8388608], @s.fetch) 810: end 811: end
# File test.rb, line 813 813: def test_fetch_mediumint_unsigned() 814: if @m.server_version >= 40100 then 815: @m.query("create temporary table t (i mediumint unsigned)") 816: @m.query("insert into t values (0),(-1),(8388607),(-8388608),(16777215),(-16777215),(16777216)") 817: @s.prepare("select i from t") 818: @s.execute 819: assert_equal([0], @s.fetch) 820: assert_equal([0], @s.fetch) 821: assert_equal([8388607], @s.fetch) 822: assert_equal([0], @s.fetch) 823: assert_equal([16777215], @s.fetch) 824: assert_equal([0], @s.fetch) 825: assert_equal([16777215], @s.fetch) 826: end 827: end
# File test.rb, line 1158 1158: def test_fetch_mediumtext() 1159: if @m.server_version >= 40100 then 1160: @m.query("create temporary table t (i mediumtext)") 1161: @m.query("insert into t values (null),('abc')") 1162: @s.prepare("select i from t") 1163: @s.execute 1164: assert_equal([nil], @s.fetch) 1165: assert_equal(["abc"], @s.fetch) 1166: end 1167: end
# File test.rb, line 1209 1209: def test_fetch_set() 1210: if @m.server_version >= 40100 then 1211: @m.query("create temporary table t (i set('abc','def'))") 1212: @m.query("insert into t values (null),(0),(1),(2),(3),('abc'),('def'),('abc,def'),('ghi')") 1213: @s.prepare("select i from t") 1214: @s.execute 1215: assert_equal([nil], @s.fetch) 1216: assert_equal([""], @s.fetch) 1217: assert_equal(["abc"], @s.fetch) 1218: assert_equal(["def"], @s.fetch) 1219: assert_equal(["abc,def"], @s.fetch) 1220: assert_equal(["abc"], @s.fetch) 1221: assert_equal(["def"], @s.fetch) 1222: assert_equal(["abc,def"], @s.fetch) 1223: assert_equal([""], @s.fetch) 1224: end 1225: end
# File test.rb, line 767 767: def test_fetch_smallint() 768: if @m.server_version >= 40100 then 769: @m.query("create temporary table t (i smallint)") 770: @m.query("insert into t values (0),(-1),(32767),(-32768),(65535),(-65535),(65536)") 771: @s.prepare("select i from t") 772: @s.execute 773: assert_equal([0], @s.fetch) 774: assert_equal([1], @s.fetch) 775: assert_equal([32767], @s.fetch) 776: assert_equal([32768], @s.fetch) 777: assert_equal([32767], @s.fetch) 778: assert_equal([32768], @s.fetch) 779: end 780: end
# File test.rb, line 782 782: def test_fetch_smallint_unsigned() 783: if @m.server_version >= 40100 then 784: @m.query("create temporary table t (i smallint unsigned)") 785: @m.query("insert into t values (0),(-1),(32767),(-32768),(65535),(-65535),(65536)") 786: @s.prepare("select i from t") 787: @s.execute 788: assert_equal([0], @s.fetch) 789: assert_equal([0], @s.fetch) 790: assert_equal([32767], @s.fetch) 791: assert_equal([0], @s.fetch) 792: assert_equal([65535], @s.fetch) 793: assert_equal([0], @s.fetch) 794: assert_equal([65535], @s.fetch) 795: end 796: end
# File test.rb, line 1136 1136: def test_fetch_text() 1137: if @m.server_version >= 40100 then 1138: @m.query("create temporary table t (i text)") 1139: @m.query("insert into t values (null),('abc')") 1140: @s.prepare("select i from t") 1141: @s.execute 1142: assert_equal([nil], @s.fetch) 1143: assert_equal(["abc"], @s.fetch) 1144: end 1145: end
# File test.rb, line 1029 1029: def test_fetch_time() 1030: if @m.server_version >= 40100 then 1031: @m.query("create temporary table t (i time)") 1032: @m.query("insert into t values ('-838:59:59'),(0),('838:59:59')") 1033: @s.prepare("select i from t") 1034: @s.execute 1035: assert_equal([Mysql::Time.new(0,0,0,838,59,59,true)], @s.fetch) 1036: assert_equal([Mysql::Time.new(0,0,0,0,0,0,false)], @s.fetch) 1037: assert_equal([Mysql::Time.new(0,0,0,838,59,59,false)], @s.fetch) 1038: end 1039: end
# File test.rb, line 1018 1018: def test_fetch_timestamp() 1019: if @m.server_version >= 40100 then 1020: @m.query("create temporary table t (i timestamp)") 1021: @m.query("insert into t values ('1970-01-02 00:00:00'),('2037-12-30 23:59:59')") 1022: @s.prepare("select i from t") 1023: @s.execute 1024: assert_equal([Mysql::Time.new(1970,1,2,0,0,0)], @s.fetch) 1025: assert_equal([Mysql::Time.new(2037,12,30,23,59,59)], @s.fetch) 1026: end 1027: end
# File test.rb, line 1103 1103: def test_fetch_tinyblob() 1104: if @m.server_version >= 40100 then 1105: @m.query("create temporary table t (i tinyblob)") 1106: @m.query("insert into t values (null),('abc')") 1107: @s.prepare("select i from t") 1108: @s.execute 1109: assert_equal([nil], @s.fetch) 1110: assert_equal(["abc"], @s.fetch) 1111: end 1112: end
# File test.rb, line 736 736: def test_fetch_tinyint() 737: if @m.server_version >= 40100 then 738: @m.query("create temporary table t (i tinyint)") 739: @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255)") 740: @s.prepare("select i from t") 741: @s.execute 742: assert_equal([0], @s.fetch) 743: assert_equal([1], @s.fetch) 744: assert_equal([127], @s.fetch) 745: assert_equal([128], @s.fetch) 746: assert_equal([127], @s.fetch) 747: assert_equal([128], @s.fetch) 748: end 749: end
# File test.rb, line 751 751: def test_fetch_tinyint_unsigned() 752: if @m.server_version >= 40100 then 753: @m.query("create temporary table t (i tinyint unsigned)") 754: @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255),(256)") 755: @s.prepare("select i from t") 756: @s.execute 757: assert_equal([0], @s.fetch) 758: assert_equal([0], @s.fetch) 759: assert_equal([127], @s.fetch) 760: assert_equal([0], @s.fetch) 761: assert_equal([255], @s.fetch) 762: assert_equal([0], @s.fetch) 763: assert_equal([255], @s.fetch) 764: end 765: end
# File test.rb, line 1114 1114: def test_fetch_tinytext() 1115: if @m.server_version >= 40100 then 1116: @m.query("create temporary table t (i tinytext)") 1117: @m.query("insert into t values (null),('abc')") 1118: @s.prepare("select i from t") 1119: @s.execute 1120: assert_equal([nil], @s.fetch) 1121: assert_equal(["abc"], @s.fetch) 1122: end 1123: end
# File test.rb, line 1092 1092: def test_fetch_varbinary() 1093: if @m.server_version >= 40100 then 1094: @m.query("create temporary table t (i varbinary(10))") 1095: @m.query("insert into t values (null),('abc')") 1096: @s.prepare("select i from t") 1097: @s.execute 1098: assert_equal([nil], @s.fetch) 1099: assert_equal(["abc"], @s.fetch) 1100: end 1101: end
# File test.rb, line 1066 1066: def test_fetch_varchar() 1067: if @m.server_version >= 40100 then 1068: @m.query("create temporary table t (i varchar(10))") 1069: @m.query("insert into t values (null),('abc')") 1070: @s.prepare("select i from t") 1071: @s.execute 1072: assert_equal([nil], @s.fetch) 1073: assert_equal(["abc"], @s.fetch) 1074: end 1075: end
# File test.rb, line 1041 1041: def test_fetch_year() 1042: if @m.server_version >= 40100 then 1043: @m.query("create temporary table t (i year)") 1044: @m.query("insert into t values (0),(70),(69),(1901),(2155)") 1045: @s.prepare("select i from t") 1046: @s.execute 1047: assert_equal([0], @s.fetch) 1048: assert_equal([1970], @s.fetch) 1049: assert_equal([2069], @s.fetch) 1050: assert_equal([1901], @s.fetch) 1051: assert_equal([2155], @s.fetch) 1052: end 1053: end
# File test.rb, line 1251 1251: def test_field_count() 1252: if @m.server_version >= 40100 then 1253: @s.prepare("select 1,2,3") 1254: @s.execute() 1255: assert_equal(3, @s.field_count()) 1256: @s.prepare("set @a=1") 1257: @s.execute() 1258: assert_equal(0, @s.field_count()) 1259: end 1260: end
# File test.rb, line 1262 1262: def test_free_result() 1263: if @m.server_version >= 40100 then 1264: @s.free_result() 1265: @s.prepare("select 1,2,3") 1266: @s.execute() 1267: @s.free_result() 1268: end 1269: end
# File test.rb, line 1271 1271: def test_insert_id() 1272: if @m.server_version >= 40100 then 1273: @m.query("create temporary table t (i bigint auto_increment, unique(i))") 1274: @s.prepare("insert into t values (?)") 1275: @s.execute(0) 1276: assert_equal(1, @s.insert_id()) 1277: @s.execute(0) 1278: assert_equal(2, @s.insert_id()) 1279: @s.execute(2**32) 1280: assert_equal(2**32, @s.insert_id()) 1281: @s.execute(0) 1282: assert_equal(2**32+1, @s.insert_id()) 1283: end 1284: end
# File test.rb, line 1286 1286: def test_num_rows() 1287: if @m.server_version >= 40100 then 1288: @m.query("create temporary table t (i int)") 1289: @m.query("insert into t values (1),(2),(3),(4)") 1290: @s.prepare("select * from t") 1291: @s.execute 1292: assert_equal(4, @s.num_rows()) 1293: end 1294: end
# File test.rb, line 1296 1296: def test_param_count() 1297: if @m.server_version >= 40100 then 1298: @m.query("create temporary table t (a int, b int, c int)") 1299: @s.prepare("select * from t") 1300: assert_equal(0, @s.param_count()) 1301: @s.prepare("insert into t values (?,?,?)") 1302: assert_equal(3, @s.param_count()) 1303: end 1304: end
# File test.rb, line 1312 1312: def test_prepare() 1313: if @m.server_version >= 40100 then 1314: @s.prepare("select 1") 1315: assert_raises(Mysql::Error){@s.prepare("invalid syntax")} 1316: end 1317: end
# File test.rb, line 1325 1325: def test_result_metadata() 1326: if @m.server_version >= 40100 then 1327: @s.prepare("select 1 foo, 2 bar") 1328: res = @s.result_metadata() 1329: f = res.fetch_fields 1330: assert_equal("foo", f[0].name) 1331: assert_equal("bar", f[1].name) 1332: end 1333: end
# File test.rb, line 1335 1335: def test_result_metadata_nodata() 1336: if @m.server_version >= 40100 then 1337: @m.query("create temporary table t (i int)") 1338: @s.prepare("insert into t values (1)") 1339: assert_equal(nil, @s.result_metadata()) 1340: end 1341: end
# File test.rb, line 1343 1343: def test_row_seek_tell() 1344: if @m.server_version >= 40100 then 1345: @m.query("create temporary table t (i int)") 1346: @m.query("insert into t values (0),(1),(2),(3),(4)") 1347: @s.prepare("select * from t") 1348: @s.execute 1349: row0 = @s.row_tell 1350: assert_equal([0], @s.fetch) 1351: assert_equal([1], @s.fetch) 1352: row2 = @s.row_seek(row0) 1353: assert_equal([0], @s.fetch) 1354: @s.row_seek(row2) 1355: assert_equal([2], @s.fetch) 1356: end 1357: end
# File test.rb, line 1371 1371: def test_sqlstate() 1372: if @m.server_version >= 40100 then 1373: @s.prepare("select 1") 1374: if @m.client_version >= 50000 then 1375: assert_equal("00000", @s.sqlstate) 1376: else 1377: assert_equal("", @s.sqlstate) 1378: end 1379: assert_raises(Mysql::Error){@s.prepare("hogehoge")} 1380: assert_equal("42000", @s.sqlstate) 1381: end 1382: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.