Class: TC_MysqlRes
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TC_MysqlRes
- Defined in:
- ext/test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_data_seek ⇒ Object
- #test_each ⇒ Object
- #test_each_hash ⇒ Object
- #test_fetch_field ⇒ Object
- #test_fetch_field_direct ⇒ Object
- #test_fetch_fields ⇒ Object
- #test_fetch_hash ⇒ Object
- #test_fetch_hash2 ⇒ Object
- #test_fetch_lengths ⇒ Object
- #test_fetch_row ⇒ Object
- #test_field_hash ⇒ Object
- #test_field_inspect ⇒ Object
- #test_field_seek ⇒ Object
- #test_is_not_null ⇒ Object
- #test_is_num ⇒ Object
- #test_is_pri_key ⇒ Object
- #test_num_fields ⇒ Object
- #test_num_rows ⇒ Object
- #test_row_seek ⇒ Object
Instance Method Details
#setup ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 |
# File 'ext/test.rb', line 178 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) @m.query("create temporary table t (id int, str char(10), primary key (id))") @m.query("insert into t values (1, 'abc'), (2, 'defg'), (3, 'hi'), (4, null)") @res = @m.query("select * from t") end |
#teardown ⇒ Object
189 190 191 192 |
# File 'ext/test.rb', line 189 def teardown() @res.free @m.close end |
#test_data_seek ⇒ Object
240 241 242 243 244 245 246 |
# File 'ext/test.rb', line 240 def test_data_seek() assert_equal(["1","abc"], @res.fetch_row) assert_equal(["2","defg"], @res.fetch_row) assert_equal(["3","hi"], @res.fetch_row) @res.data_seek(1) assert_equal(["2","defg"], @res.fetch_row) end |
#test_each ⇒ Object
226 227 228 229 230 231 |
# File 'ext/test.rb', line 226 def test_each() ary = [["1","abc"], ["2","defg"], ["3","hi"], ["4",nil]] @res.each do |a| assert_equal(ary.shift, a) end end |
#test_each_hash ⇒ Object
233 234 235 236 237 238 |
# File 'ext/test.rb', line 233 def test_each_hash() hash = [{"id"=>"1","str"=>"abc"}, {"id"=>"2","str"=>"defg"}, {"id"=>"3","str"=>"hi"}, {"id"=>"4","str"=>nil}] @res.each_hash do |h| assert_equal(hash.shift, h) end end |
#test_fetch_field ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'ext/test.rb', line 267 def test_fetch_field() f = @res.fetch_field assert_equal("id", f.name) assert_equal("t", f.table) assert_equal(nil, f.def) assert_equal(Mysql::Field::TYPE_LONG, f.type) assert_equal(11, f.length) assert_equal(1, f.max_length) assert_equal(Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG, f.flags) assert_equal(0, f.decimals) f = @res.fetch_field assert_equal("str", f.name) assert_equal("t", f.table) assert_equal(nil, f.def) assert_equal(Mysql::Field::TYPE_STRING, f.type) assert_equal(10, f.length) assert_equal(4, f.max_length) assert_equal(0, f.flags) assert_equal(0, f.decimals) f = @res.fetch_field assert_equal(nil, f) end |
#test_fetch_field_direct ⇒ Object
297 298 299 300 301 302 303 304 |
# File 'ext/test.rb', line 297 def test_fetch_field_direct() f = @res.fetch_field_direct(0) assert_equal("id", f.name) f = @res.fetch_field_direct(1) assert_equal("str", f.name) assert_raises(Mysql::Error){@res.fetch_field_direct(-1)} assert_raises(Mysql::Error){@res.fetch_field_direct(2)} end |
#test_fetch_fields ⇒ Object
290 291 292 293 294 295 |
# File 'ext/test.rb', line 290 def test_fetch_fields() a = @res.fetch_fields assert_equal(2, a.size) assert_equal("id", a[0].name) assert_equal("str", a[1].name) end |
#test_fetch_hash ⇒ Object
210 211 212 213 214 215 216 |
# File 'ext/test.rb', line 210 def test_fetch_hash() assert_equal({"id"=>"1", "str"=>"abc"}, @res.fetch_hash) assert_equal({"id"=>"2", "str"=>"defg"}, @res.fetch_hash) assert_equal({"id"=>"3", "str"=>"hi"}, @res.fetch_hash) assert_equal({"id"=>"4", "str"=>nil}, @res.fetch_hash) assert_equal(nil, @res.fetch_hash) end |
#test_fetch_hash2 ⇒ Object
218 219 220 221 222 223 224 |
# File 'ext/test.rb', line 218 def test_fetch_hash2() assert_equal({"t.id"=>"1", "t.str"=>"abc"}, @res.fetch_hash(true)) assert_equal({"t.id"=>"2", "t.str"=>"defg"}, @res.fetch_hash(true)) assert_equal({"t.id"=>"3", "t.str"=>"hi"}, @res.fetch_hash(true)) assert_equal({"t.id"=>"4", "t.str"=>nil}, @res.fetch_hash(true)) assert_equal(nil, @res.fetch_hash) end |
#test_fetch_lengths ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'ext/test.rb', line 306 def test_fetch_lengths() assert_equal(nil, @res.fetch_lengths()) @res.fetch_row assert_equal([1, 3], @res.fetch_lengths()) @res.fetch_row assert_equal([1, 4], @res.fetch_lengths()) @res.fetch_row assert_equal([1, 2], @res.fetch_lengths()) @res.fetch_row assert_equal([1, 0], @res.fetch_lengths()) @res.fetch_row assert_equal(nil, @res.fetch_lengths()) end |
#test_fetch_row ⇒ Object
202 203 204 205 206 207 208 |
# File 'ext/test.rb', line 202 def test_fetch_row() assert_equal(["1","abc"], @res.fetch_row) assert_equal(["2","defg"], @res.fetch_row) assert_equal(["3","hi"], @res.fetch_row) assert_equal(["4",nil], @res.fetch_row) assert_equal(nil, @res.fetch_row) end |
#test_field_hash ⇒ Object
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'ext/test.rb', line 320 def test_field_hash() f = @res.fetch_field h = { "name" => "id", "table" => "t", "def" => nil, "type" => Mysql::Field::TYPE_LONG, "length" => 11, "max_length" => 1, "flags" => Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG, "decimals" => 0, } assert_equal(h, f.hash) f = @res.fetch_field h = { "name" => "str", "table" => "t", "def" => nil, "type" => Mysql::Field::TYPE_STRING, "length" => 10, "max_length" => 4, "flags" => 0, "decimals" => 0, } assert_equal(h, f.hash) end |
#test_field_inspect ⇒ Object
347 348 349 350 351 352 |
# File 'ext/test.rb', line 347 def test_field_inspect() f = @res.fetch_field assert_equal("#<Mysql::Field:id>", f.inspect) f = @res.fetch_field assert_equal("#<Mysql::Field:str>", f.inspect) end |
#test_field_seek ⇒ Object
257 258 259 260 261 262 263 264 265 |
# File 'ext/test.rb', line 257 def test_field_seek() assert_equal(0, @res.field_tell) @res.fetch_field assert_equal(1, @res.field_tell) @res.fetch_field assert_equal(2, @res.field_tell) @res.field_seek(1) assert_equal(1, @res.field_tell) end |
#test_is_not_null ⇒ Object
361 362 363 364 365 366 |
# File 'ext/test.rb', line 361 def test_is_not_null() f = @res.fetch_field assert_equal(true, f.is_not_null?) f = @res.fetch_field assert_equal(false, f.is_not_null?) end |
#test_is_num ⇒ Object
354 355 356 357 358 359 |
# File 'ext/test.rb', line 354 def test_is_num() f = @res.fetch_field assert_equal(true, f.is_num?) f = @res.fetch_field assert_equal(false, f.is_num?) end |
#test_is_pri_key ⇒ Object
368 369 370 371 372 373 |
# File 'ext/test.rb', line 368 def test_is_pri_key() f = @res.fetch_field assert_equal(true, f.is_pri_key?) f = @res.fetch_field assert_equal(false, f.is_pri_key?) end |
#test_num_fields ⇒ Object
194 195 196 |
# File 'ext/test.rb', line 194 def test_num_fields() assert_equal(2, @res.num_fields) end |
#test_num_rows ⇒ Object
198 199 200 |
# File 'ext/test.rb', line 198 def test_num_rows() assert_equal(4, @res.num_rows) end |
#test_row_seek ⇒ Object
248 249 250 251 252 253 254 255 |
# File 'ext/test.rb', line 248 def test_row_seek() assert_equal(["1","abc"], @res.fetch_row) pos = @res.row_tell assert_equal(["2","defg"], @res.fetch_row) assert_equal(["3","hi"], @res.fetch_row) @res.row_seek(pos) assert_equal(["2","defg"], @res.fetch_row) end |