# File test.rb, line 443 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
# File test.rb, line 452 def teardown() @s.close @m.close end
# File test.rb, line 457 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
# File test.rb, line 539 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
# File test.rb, line 567 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
# File test.rb, line 523 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
# File test.rb, line 583 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
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
# File test.rb, line 495 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
# File test.rb, line 507 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
# File test.rb, line 555 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
# File test.rb, line 599 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
# File test.rb, line 608 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
# File test.rb, line 617 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
# File test.rb, line 1227 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) assert_equal(Encoding.default_external, a[1].encoding) if RUBY_VERSION =~ /1.9/ 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
def test_errno()
@s.errno()
end
def test_error()
@s.error()
end
# File test.rb, line 643 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
# File test.rb, line 655 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
# File test.rb, line 668 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
# File test.rb, line 681 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
# File test.rb, line 692 def test_execute5() if @m.server_version >= 40100 then [30, 31, 32, 62, 63].each do |i| v, = @m.prepare("select cast(? as signed)").execute(2**i-1).fetch assert_equal(2**i-1, v) v, = @m.prepare("select cast(? as signed)").execute(-(2**i)).fetch assert_equal(-(2**i), v) end end end
# File test.rb, line 703 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
# File test.rb, line 860 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
# File test.rb, line 880 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([18446744073709551615], @s.fetch) # MySQL problem end assert_equal([9223372036854775807], @s.fetch) if @m.server_version >= 50000 then assert_equal([0], @s.fetch) else assert_equal([9223372036854775808], @s.fetch) # MySQL problem end assert_equal([18446744073709551615], @s.fetch) assert_equal([0], @s.fetch) assert_equal([18446744073709551615], @s.fetch) end end
# File test.rb, line 1077 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\00\\00\\00\\00\\00\\00\\00""], @s.fetch) else assert_equal(["abc"], @s.fetch) end end end
# File test.rb, line 711 def test_fetch_bit() if @m.client_version >= 50003 and @m.server_version >= 50003 then @m.query("create temporary table t (i bit(8))") @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255),(256)") @s.prepare("select i from t") @s.execute assert_equal(["\x00"], @s.fetch) assert_equal(["\xff"], @s.fetch) assert_equal(["\x7f"], @s.fetch) assert_equal(["\xff"], @s.fetch) assert_equal(["\xff"], @s.fetch) assert_equal(["\xff"], @s.fetch) assert_equal(["\xff"], @s.fetch) @m.query("create temporary table t2 (i bit(64))") @m.query("insert into t2 values (0),(-1),(4294967296),(18446744073709551615),(18446744073709551616)") @s.prepare("select i from t2") @s.execute assert_equal(["\x00\x00\x00\x00\x00\x00\x00\x00"], @s.fetch) assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch) assert_equal(["\x00\x00\x00\x01\x00\x00\x00\x00"], @s.fetch) assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch) assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch) end end
# File test.rb, line 1125 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
# File test.rb, line 1055 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
# File test.rb, line 994 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
# File test.rb, line 1006 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
# File test.rb, line 960 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
# File test.rb, line 978 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
# File test.rb, line 932 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
# File test.rb, line 946 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
# File test.rb, line 1191 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) row = @s.fetch assert_equal(Encoding.default_external, row[0].encoding) if RUBY_VERSION =~ /1.9/ assert_equal(["abc"], row) assert_equal(["def"], @s.fetch) assert_equal(["abc"], @s.fetch) assert_equal(["def"], @s.fetch) assert_equal([""], @s.fetch) end end
# File test.rb, line 904 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
# File test.rb, line 918 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
# File test.rb, line 829 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
# File test.rb, line 844 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
# File test.rb, line 1169 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
# File test.rb, line 1180 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
# File test.rb, line 1147 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
# File test.rb, line 798 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
# File test.rb, line 813 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
# File test.rb, line 1158 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
# File test.rb, line 1209 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
# File test.rb, line 767 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
# File test.rb, line 782 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
# File test.rb, line 1136 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
# File test.rb, line 1029 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
# File test.rb, line 1018 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
# File test.rb, line 1103 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
# File test.rb, line 736 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
# File test.rb, line 751 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
# File test.rb, line 1114 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
# File test.rb, line 1092 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
# File test.rb, line 1066 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
# File test.rb, line 1041 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
# File test.rb, line 1251 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
# File test.rb, line 1262 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
# File test.rb, line 1271 def test_insert_id() if @m.server_version >= 40100 then @m.query("create temporary table t (i bigint auto_increment, unique(i))") @s.prepare("insert into t values (?)") @s.execute(0) assert_equal(1, @s.insert_id()) @s.execute(0) assert_equal(2, @s.insert_id()) @s.execute(2**32) assert_equal(2**32, @s.insert_id()) @s.execute(0) assert_equal(2**32+1, @s.insert_id()) end end
# File test.rb, line 1286 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
# File test.rb, line 1296 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
def test_param_metadata()
@s.param_metadata()
end
# File test.rb, line 1312 def test_prepare() if @m.server_version >= 40100 then @s.prepare("select 1") assert_raises(Mysql::Error){@s.prepare("invalid syntax")} end end
def test_reset()
@s.reset()
end
# File test.rb, line 1325 def test_result_metadata() if @m.server_version >= 40100 then @s.prepare("select 1 foo, 2 bar") res = @s.result_metadata() f = res.fetch_fields assert_equal("foo", f[0].name) assert_equal("bar", f[1].name) end end
# File test.rb, line 1335 def test_result_metadata_nodata() if @m.server_version >= 40100 then @m.query("create temporary table t (i int)") @s.prepare("insert into t values (1)") assert_equal(nil, @s.result_metadata()) end end
# File test.rb, line 1343 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
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
# File test.rb, line 1371 def test_sqlstate() if @m.server_version >= 40100 then @s.prepare("select 1") if @m.client_version >= 50000 then assert_equal("00000", @s.sqlstate) else assert_equal("", @s.sqlstate) end assert_raises(Mysql::Error){@s.prepare("hogehoge")} assert_equal("42000", @s.sqlstate) end end