Class TC_MysqlRes
In: test.rb
Parent: Test::Unit::TestCase

Methods

Public Instance methods

[Source]

     # File test.rb, line 178
178:   def setup()
179:     @host, @user, @pass, db, port, sock, flag = ARGV
180:     @db = db || "test"
181:     @port = port.to_i
182:     @sock = sock.nil? || sock.empty? ? nil : sock
183:     @flag = flag.to_i
184:     @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
185:     @m.query("create temporary table t (id int, str char(10), primary key (id))")
186:     @m.query("insert into t values (1, 'abc'), (2, 'defg'), (3, 'hi'), (4, null)")
187:     @res = @m.query("select * from t")
188:   end

[Source]

     # File test.rb, line 189
189:   def teardown()
190:     @res.free
191:     @m.close
192:   end

[Source]

     # File test.rb, line 240
240:   def test_data_seek()
241:     assert_equal(["1","abc"], @res.fetch_row)
242:     assert_equal(["2","defg"], @res.fetch_row)
243:     assert_equal(["3","hi"], @res.fetch_row)
244:     @res.data_seek(1)
245:     assert_equal(["2","defg"], @res.fetch_row)
246:   end

[Source]

     # File test.rb, line 226
226:   def test_each()
227:     ary = [["1","abc"], ["2","defg"], ["3","hi"], ["4",nil]]
228:     @res.each do |a|
229:       assert_equal(ary.shift, a)
230:     end
231:   end

[Source]

     # File test.rb, line 233
233:   def test_each_hash()
234:     hash = [{"id"=>"1","str"=>"abc"}, {"id"=>"2","str"=>"defg"}, {"id"=>"3","str"=>"hi"}, {"id"=>"4","str"=>nil}]
235:     @res.each_hash do |h|
236:       assert_equal(hash.shift, h)
237:     end
238:   end

[Source]

     # File test.rb, line 267
267:   def test_fetch_field()
268:     f = @res.fetch_field
269:     assert_equal("id", f.name)
270:     assert_equal("t", f.table)
271:     assert_equal(nil, f.def)
272:     assert_equal(Mysql::Field::TYPE_LONG, f.type)
273:     assert_equal(11, f.length)
274:     assert_equal(1, f.max_length)
275:     assert_equal(Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG, f.flags)
276:     assert_equal(0, f.decimals)
277:     f = @res.fetch_field
278:     assert_equal("str", f.name)
279:     assert_equal("t", f.table)
280:     assert_equal(nil, f.def)
281:     assert_equal(Mysql::Field::TYPE_STRING, f.type)
282:     assert_equal(10, f.length)
283:     assert_equal(4, f.max_length)
284:     assert_equal(0, f.flags)
285:     assert_equal(0, f.decimals)
286:     f = @res.fetch_field
287:     assert_equal(nil, f)
288:   end

[Source]

     # File test.rb, line 297
297:   def test_fetch_field_direct()
298:     f = @res.fetch_field_direct(0)
299:     assert_equal("id", f.name)
300:     f = @res.fetch_field_direct(1)
301:     assert_equal("str", f.name)
302:     assert_raises(Mysql::Error){@res.fetch_field_direct(-1)}
303:     assert_raises(Mysql::Error){@res.fetch_field_direct(2)}
304:   end

[Source]

     # File test.rb, line 290
290:   def test_fetch_fields()
291:     a = @res.fetch_fields
292:     assert_equal(2, a.size)
293:     assert_equal("id", a[0].name)
294:     assert_equal("str", a[1].name)
295:   end

[Source]

     # File test.rb, line 210
210:   def test_fetch_hash()
211:     assert_equal({"id"=>"1", "str"=>"abc"}, @res.fetch_hash)
212:     assert_equal({"id"=>"2", "str"=>"defg"}, @res.fetch_hash)
213:     assert_equal({"id"=>"3", "str"=>"hi"}, @res.fetch_hash)
214:     assert_equal({"id"=>"4", "str"=>nil}, @res.fetch_hash)
215:     assert_equal(nil, @res.fetch_hash)
216:   end

[Source]

     # File test.rb, line 218
218:   def test_fetch_hash2()
219:     assert_equal({"t.id"=>"1", "t.str"=>"abc"}, @res.fetch_hash(true))
220:     assert_equal({"t.id"=>"2", "t.str"=>"defg"}, @res.fetch_hash(true))
221:     assert_equal({"t.id"=>"3", "t.str"=>"hi"}, @res.fetch_hash(true))
222:     assert_equal({"t.id"=>"4", "t.str"=>nil}, @res.fetch_hash(true))
223:     assert_equal(nil, @res.fetch_hash)
224:   end

[Source]

     # File test.rb, line 306
306:   def test_fetch_lengths()
307:     assert_equal(nil,  @res.fetch_lengths())
308:     @res.fetch_row
309:     assert_equal([1, 3],  @res.fetch_lengths())
310:     @res.fetch_row
311:     assert_equal([1, 4],  @res.fetch_lengths())
312:     @res.fetch_row
313:     assert_equal([1, 2],  @res.fetch_lengths())
314:     @res.fetch_row
315:     assert_equal([1, 0],  @res.fetch_lengths())
316:     @res.fetch_row
317:     assert_equal(nil,  @res.fetch_lengths())
318:   end

[Source]

     # File test.rb, line 202
202:   def test_fetch_row()
203:     assert_equal(["1","abc"], @res.fetch_row)
204:     assert_equal(["2","defg"], @res.fetch_row)
205:     assert_equal(["3","hi"], @res.fetch_row)
206:     assert_equal(["4",nil], @res.fetch_row)
207:     assert_equal(nil, @res.fetch_row)
208:   end

[Source]

     # File test.rb, line 320
320:   def test_field_hash()
321:     f = @res.fetch_field
322:     h = {
323:       "name" => "id",
324:       "table" => "t",
325:       "def" => nil,
326:       "type" => Mysql::Field::TYPE_LONG,
327:       "length" => 11,
328:       "max_length" => 1,
329:       "flags" => Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG,
330:       "decimals" => 0,
331:     }
332:     assert_equal(h, f.hash)
333:     f = @res.fetch_field
334:     h = {
335:       "name" => "str",
336:       "table" => "t",
337:       "def" => nil,
338:       "type" => Mysql::Field::TYPE_STRING,
339:       "length" => 10,
340:       "max_length" => 4,
341:       "flags" => 0,
342:       "decimals" => 0,
343:     }
344:     assert_equal(h, f.hash)
345:   end

[Source]

     # File test.rb, line 347
347:   def test_field_inspect()
348:     f = @res.fetch_field
349:     assert_equal("#<Mysql::Field:id>", f.inspect)
350:     f = @res.fetch_field
351:     assert_equal("#<Mysql::Field:str>", f.inspect)
352:   end

[Source]

     # File test.rb, line 257
257:   def test_field_seek()
258:     assert_equal(0, @res.field_tell)
259:     @res.fetch_field
260:     assert_equal(1, @res.field_tell)
261:     @res.fetch_field
262:     assert_equal(2, @res.field_tell)
263:     @res.field_seek(1)
264:     assert_equal(1, @res.field_tell)
265:   end

[Source]

     # File test.rb, line 361
361:   def test_is_not_null()
362:     f = @res.fetch_field
363:     assert_equal(true, f.is_not_null?)
364:     f = @res.fetch_field
365:     assert_equal(false, f.is_not_null?)
366:   end

[Source]

     # File test.rb, line 354
354:   def test_is_num()
355:     f = @res.fetch_field
356:     assert_equal(true, f.is_num?)
357:     f = @res.fetch_field
358:     assert_equal(false, f.is_num?)
359:   end

[Source]

     # File test.rb, line 368
368:   def test_is_pri_key()
369:     f = @res.fetch_field
370:     assert_equal(true, f.is_pri_key?)
371:     f = @res.fetch_field
372:     assert_equal(false, f.is_pri_key?)
373:   end

[Source]

     # File test.rb, line 194
194:   def test_num_fields()
195:     assert_equal(2, @res.num_fields)
196:   end

[Source]

     # File test.rb, line 198
198:   def test_num_rows()
199:     assert_equal(4, @res.num_rows)
200:   end

[Source]

     # File test.rb, line 248
248:   def test_row_seek()
249:     assert_equal(["1","abc"], @res.fetch_row)
250:     pos = @res.row_tell
251:     assert_equal(["2","defg"], @res.fetch_row)
252:     assert_equal(["3","hi"], @res.fetch_row)
253:     @res.row_seek(pos)
254:     assert_equal(["2","defg"], @res.fetch_row)
255:   end

[Validate]