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

Methods

Public Instance methods

[Source]

     # File test.rb, line 170
170:   def setup()
171:     @host, @user, @pass, db, port, sock, flag = ARGV
172:     @db = db || "test"
173:     @port = port.to_i
174:     @sock = sock.nil? || sock.empty? ? nil : sock
175:     @flag = flag.to_i
176:     @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)
177:     @m.query("create temporary table t (id int, str char(10), primary key (id))")
178:     @m.query("insert into t values (1, 'abc'), (2, 'defg'), (3, 'hi'), (4, null)")
179:     @res = @m.query("select * from t")
180:   end

[Source]

     # File test.rb, line 181
181:   def teardown()
182:     @res.free
183:     @m.close
184:   end

[Source]

     # File test.rb, line 232
232:   def test_data_seek()
233:     assert_equal(["1","abc"], @res.fetch_row)
234:     assert_equal(["2","defg"], @res.fetch_row)
235:     assert_equal(["3","hi"], @res.fetch_row)
236:     @res.data_seek(1)
237:     assert_equal(["2","defg"], @res.fetch_row)
238:   end

[Source]

     # File test.rb, line 218
218:   def test_each()
219:     ary = [["1","abc"], ["2","defg"], ["3","hi"], ["4",nil]]
220:     @res.each do |a|
221:       assert_equal(ary.shift, a)
222:     end
223:   end

[Source]

     # File test.rb, line 225
225:   def test_each_hash()
226:     hash = [{"id"=>"1","str"=>"abc"}, {"id"=>"2","str"=>"defg"}, {"id"=>"3","str"=>"hi"}, {"id"=>"4","str"=>nil}]
227:     @res.each_hash do |h|
228:       assert_equal(hash.shift, h)
229:     end
230:   end

[Source]

     # File test.rb, line 259
259:   def test_fetch_field()
260:     f = @res.fetch_field
261:     assert_equal("id", f.name)
262:     assert_equal("t", f.table)
263:     assert_equal(nil, f.def)
264:     assert_equal(Mysql::Field::TYPE_LONG, f.type)
265:     assert_equal(11, f.length)
266:     assert_equal(1, f.max_length)
267:     assert_equal(Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG, f.flags)
268:     assert_equal(0, f.decimals)
269:     f = @res.fetch_field
270:     assert_equal("str", f.name)
271:     assert_equal("t", f.table)
272:     assert_equal(nil, f.def)
273:     assert_equal(Mysql::Field::TYPE_STRING, f.type)
274:     assert_equal(10, f.length)
275:     assert_equal(4, f.max_length)
276:     assert_equal(0, f.flags)
277:     assert_equal(0, f.decimals)
278:     f = @res.fetch_field
279:     assert_equal(nil, f)
280:   end

[Source]

     # File test.rb, line 289
289:   def test_fetch_field_direct()
290:     f = @res.fetch_field_direct(0)
291:     assert_equal("id", f.name)
292:     f = @res.fetch_field_direct(1)
293:     assert_equal("str", f.name)
294:     assert_raises(Mysql::Error){@res.fetch_field_direct(-1)}
295:     assert_raises(Mysql::Error){@res.fetch_field_direct(2)}
296:   end

[Source]

     # File test.rb, line 282
282:   def test_fetch_fields()
283:     a = @res.fetch_fields
284:     assert_equal(2, a.size)
285:     assert_equal("id", a[0].name)
286:     assert_equal("str", a[1].name)
287:   end

[Source]

     # File test.rb, line 202
202:   def test_fetch_hash()
203:     assert_equal({"id"=>"1", "str"=>"abc"}, @res.fetch_hash)
204:     assert_equal({"id"=>"2", "str"=>"defg"}, @res.fetch_hash)
205:     assert_equal({"id"=>"3", "str"=>"hi"}, @res.fetch_hash)
206:     assert_equal({"id"=>"4", "str"=>nil}, @res.fetch_hash)
207:     assert_equal(nil, @res.fetch_hash)
208:   end

[Source]

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

[Source]

     # File test.rb, line 298
298:   def test_fetch_lengths()
299:     assert_equal(nil,  @res.fetch_lengths())
300:     @res.fetch_row
301:     assert_equal([1, 3],  @res.fetch_lengths())
302:     @res.fetch_row
303:     assert_equal([1, 4],  @res.fetch_lengths())
304:     @res.fetch_row
305:     assert_equal([1, 2],  @res.fetch_lengths())
306:     @res.fetch_row
307:     assert_equal([1, 0],  @res.fetch_lengths())
308:     @res.fetch_row
309:     assert_equal(nil,  @res.fetch_lengths())
310:   end

[Source]

     # File test.rb, line 194
194:   def test_fetch_row()
195:     assert_equal(["1","abc"], @res.fetch_row)
196:     assert_equal(["2","defg"], @res.fetch_row)
197:     assert_equal(["3","hi"], @res.fetch_row)
198:     assert_equal(["4",nil], @res.fetch_row)
199:     assert_equal(nil, @res.fetch_row)
200:   end

[Source]

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

[Source]

     # File test.rb, line 339
339:   def test_field_inspect()
340:     f = @res.fetch_field
341:     assert_equal("#<Mysql::Field:id>", f.inspect)
342:     f = @res.fetch_field
343:     assert_equal("#<Mysql::Field:str>", f.inspect)
344:   end

[Source]

     # File test.rb, line 249
249:   def test_field_seek()
250:     assert_equal(0, @res.field_tell)
251:     @res.fetch_field
252:     assert_equal(1, @res.field_tell)
253:     @res.fetch_field
254:     assert_equal(2, @res.field_tell)
255:     @res.field_seek(1)
256:     assert_equal(1, @res.field_tell)
257:   end

[Source]

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

[Source]

     # File test.rb, line 346
346:   def test_is_num()
347:     f = @res.fetch_field
348:     assert_equal(true, f.is_num?)
349:     f = @res.fetch_field
350:     assert_equal(false, f.is_num?)
351:   end

[Source]

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

[Source]

     # File test.rb, line 186
186:   def test_num_fields()
187:     assert_equal(2, @res.num_fields)
188:   end

[Source]

     # File test.rb, line 190
190:   def test_num_rows()
191:     assert_equal(4, @res.num_rows)
192:   end

[Source]

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

[Validate]