Test::Unit::TestCase
# File test.rb, line 213 213: def setup() 214: @host, @user, @pass, db, port, sock, flag = ARGV 215: @db = db || "test" 216: @port = port.to_i 217: @sock = sock.nil? || sock.empty? ? nil : sock 218: @flag = flag.to_i 219: @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag) 220: @m.query("create temporary table t (id int, str char(10), primary key (id))") 221: @m.query("insert into t values (1, 'abc'), (2, 'defg'), (3, 'hi'), (4, null)") 222: @res = @m.query("select * from t") 223: end
# File test.rb, line 224 224: def teardown() 225: @res.free 226: @m.close 227: end
# File test.rb, line 275 275: def test_data_seek() 276: assert_equal(["1","abc"], @res.fetch_row) 277: assert_equal(["2","defg"], @res.fetch_row) 278: assert_equal(["3","hi"], @res.fetch_row) 279: @res.data_seek(1) 280: assert_equal(["2","defg"], @res.fetch_row) 281: end
# File test.rb, line 261 261: def test_each() 262: ary = [["1","abc"], ["2","defg"], ["3","hi"], ["4",nil]] 263: @res.each do |a| 264: assert_equal(ary.shift, a) 265: end 266: end
# File test.rb, line 268 268: def test_each_hash() 269: hash = [{"id"=>"1","str"=>"abc"}, {"id"=>"2","str"=>"defg"}, {"id"=>"3","str"=>"hi"}, {"id"=>"4","str"=>nil}] 270: @res.each_hash do |h| 271: assert_equal(hash.shift, h) 272: end 273: end
# File test.rb, line 302 302: def test_fetch_field() 303: f = @res.fetch_field 304: assert_equal("id", f.name) 305: assert_equal("t", f.table) 306: assert_equal(nil, f.def) 307: assert_equal(Mysql::Field::TYPE_LONG, f.type) 308: assert_equal(11, f.length) 309: assert_equal(1, f.max_length) 310: assert_equal(Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG, f.flags) 311: assert_equal(0, f.decimals) 312: f = @res.fetch_field 313: assert_equal("str", f.name) 314: assert_equal("t", f.table) 315: assert_equal(nil, f.def) 316: assert_equal(Mysql::Field::TYPE_STRING, f.type) 317: assert_equal(10, f.length) 318: assert_equal(4, f.max_length) 319: assert_equal(0, f.flags) 320: assert_equal(0, f.decimals) 321: f = @res.fetch_field 322: assert_equal(nil, f) 323: end
# File test.rb, line 332 332: def test_fetch_field_direct() 333: f = @res.fetch_field_direct(0) 334: assert_equal("id", f.name) 335: f = @res.fetch_field_direct(1) 336: assert_equal("str", f.name) 337: assert_raises(Mysql::Error){@res.fetch_field_direct(1)} 338: assert_raises(Mysql::Error){@res.fetch_field_direct(2)} 339: end
# File test.rb, line 325 325: def test_fetch_fields() 326: a = @res.fetch_fields 327: assert_equal(2, a.size) 328: assert_equal("id", a[0].name) 329: assert_equal("str", a[1].name) 330: end
# File test.rb, line 245 245: def test_fetch_hash() 246: assert_equal({"id"=>"1", "str"=>"abc"}, @res.fetch_hash) 247: assert_equal({"id"=>"2", "str"=>"defg"}, @res.fetch_hash) 248: assert_equal({"id"=>"3", "str"=>"hi"}, @res.fetch_hash) 249: assert_equal({"id"=>"4", "str"=>nil}, @res.fetch_hash) 250: assert_equal(nil, @res.fetch_hash) 251: end
# File test.rb, line 253 253: def test_fetch_hash2() 254: assert_equal({"t.id"=>"1", "t.str"=>"abc"}, @res.fetch_hash(true)) 255: assert_equal({"t.id"=>"2", "t.str"=>"defg"}, @res.fetch_hash(true)) 256: assert_equal({"t.id"=>"3", "t.str"=>"hi"}, @res.fetch_hash(true)) 257: assert_equal({"t.id"=>"4", "t.str"=>nil}, @res.fetch_hash(true)) 258: assert_equal(nil, @res.fetch_hash) 259: end
# File test.rb, line 341 341: def test_fetch_lengths() 342: assert_equal(nil, @res.fetch_lengths()) 343: @res.fetch_row 344: assert_equal([1, 3], @res.fetch_lengths()) 345: @res.fetch_row 346: assert_equal([1, 4], @res.fetch_lengths()) 347: @res.fetch_row 348: assert_equal([1, 2], @res.fetch_lengths()) 349: @res.fetch_row 350: assert_equal([1, 0], @res.fetch_lengths()) 351: @res.fetch_row 352: assert_equal(nil, @res.fetch_lengths()) 353: end
# File test.rb, line 237 237: def test_fetch_row() 238: assert_equal(["1","abc"], @res.fetch_row) 239: assert_equal(["2","defg"], @res.fetch_row) 240: assert_equal(["3","hi"], @res.fetch_row) 241: assert_equal(["4",nil], @res.fetch_row) 242: assert_equal(nil, @res.fetch_row) 243: end
# File test.rb, line 355 355: def test_field_hash() 356: f = @res.fetch_field 357: h = { 358: "name" => "id", 359: "table" => "t", 360: "def" => nil, 361: "type" => Mysql::Field::TYPE_LONG, 362: "length" => 11, 363: "max_length" => 1, 364: "flags" => Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG, 365: "decimals" => 0, 366: } 367: assert_equal(h, f.hash) 368: f = @res.fetch_field 369: h = { 370: "name" => "str", 371: "table" => "t", 372: "def" => nil, 373: "type" => Mysql::Field::TYPE_STRING, 374: "length" => 10, 375: "max_length" => 4, 376: "flags" => 0, 377: "decimals" => 0, 378: } 379: assert_equal(h, f.hash) 380: end
# File test.rb, line 382 382: def test_field_inspect() 383: f = @res.fetch_field 384: assert_equal("#<Mysql::Field:id>", f.inspect) 385: f = @res.fetch_field 386: assert_equal("#<Mysql::Field:str>", f.inspect) 387: end
# File test.rb, line 292 292: def test_field_seek() 293: assert_equal(0, @res.field_tell) 294: @res.fetch_field 295: assert_equal(1, @res.field_tell) 296: @res.fetch_field 297: assert_equal(2, @res.field_tell) 298: @res.field_seek(1) 299: assert_equal(1, @res.field_tell) 300: end
# File test.rb, line 396 396: def test_is_not_null() 397: f = @res.fetch_field 398: assert_equal(true, f.is_not_null?) 399: f = @res.fetch_field 400: assert_equal(false, f.is_not_null?) 401: end
# File test.rb, line 389 389: def test_is_num() 390: f = @res.fetch_field 391: assert_equal(true, f.is_num?) 392: f = @res.fetch_field 393: assert_equal(false, f.is_num?) 394: end
# File test.rb, line 403 403: def test_is_pri_key() 404: f = @res.fetch_field 405: assert_equal(true, f.is_pri_key?) 406: f = @res.fetch_field 407: assert_equal(false, f.is_pri_key?) 408: end
# File test.rb, line 229 229: def test_num_fields() 230: assert_equal(2, @res.num_fields) 231: end
# File test.rb, line 233 233: def test_num_rows() 234: assert_equal(4, @res.num_rows) 235: end
# File test.rb, line 283 283: def test_row_seek() 284: assert_equal(["1","abc"], @res.fetch_row) 285: pos = @res.row_tell 286: assert_equal(["2","defg"], @res.fetch_row) 287: assert_equal(["3","hi"], @res.fetch_row) 288: @res.row_seek(pos) 289: assert_equal(["2","defg"], @res.fetch_row) 290: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.