Class: Mysql::Result
- Inherits:
-
Object
- Object
- Mysql::Result
- Defined in:
- ext/mysql.c
Instance Method Summary collapse
-
#all_hashes(*args) ⇒ Object
all_hashes(with_table=false) – returns an array of hashes, one hash per row.
-
#data_seek(offset) ⇒ Object
data_seek(offset).
-
#each ⇒ Object
each ….
-
#each_hash(*args) ⇒ Object
each_hash(with_table=false) ….
-
#fetch_field ⇒ Object
fetch_field().
-
#fetch_field_direct(nr) ⇒ Object
fetch_field_direct(nr).
-
#fetch_fields ⇒ Object
fetch_fields().
-
#fetch_hash(*args) ⇒ Object
fetch_hash(with_table=false).
-
#fetch_lengths ⇒ Object
fetch_lengths().
-
#fetch_row ⇒ Object
fetch_row().
-
#field_seek(offset) ⇒ Object
field_seek(offset).
-
#field_tell ⇒ Object
field_tell().
-
#free ⇒ Object
free().
-
#num_fields ⇒ Object
num_fields().
-
#num_rows ⇒ Object
num_rows().
-
#row_seek(offset) ⇒ Object
row_seek(offset).
-
#row_tell ⇒ Object
row_tell().
Instance Method Details
#all_hashes(*args) ⇒ Object
all_hashes(with_table=false) – returns an array of hashes, one hash per row
1674 1675 1676 1677 1678 1679 1680 1681 1682 |
# File 'ext/mysql.c', line 1674 static VALUE all_hashes(int argc, VALUE* argv, VALUE obj) { VALUE with_table; check_free(obj); rb_scan_args(argc, argv, "01", &with_table); if (with_table == Qnil) with_table = Qfalse; return process_all_hashes(obj, with_table, 1, 0); } |
#data_seek(offset) ⇒ Object
data_seek(offset)
1364 1365 1366 1367 1368 1369 |
# File 'ext/mysql.c', line 1364 static VALUE data_seek(VALUE obj, VALUE offset) { check_free(obj); mysql_data_seek(GetMysqlRes(obj), NUM2INT(offset)); return obj; } |
#each ⇒ Object
each …
1652 1653 1654 1655 1656 1657 1658 1659 |
# File 'ext/mysql.c', line 1652 static VALUE each(VALUE obj) { VALUE row; check_free(obj); while ((row = fetch_row(obj)) != Qnil) rb_yield(row); return obj; } |
#each_hash(*args) ⇒ Object
each_hash(with_table=false) …
1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 |
# File 'ext/mysql.c', line 1662 static VALUE each_hash(int argc, VALUE* argv, VALUE obj) { VALUE with_table; check_free(obj); rb_scan_args(argc, argv, "01", &with_table); if (with_table == Qnil) with_table = Qfalse; process_all_hashes(obj, with_table, 0, 1); return obj; } |
#fetch_field ⇒ Object
fetch_field()
1372 1373 1374 1375 1376 |
# File 'ext/mysql.c', line 1372 static VALUE fetch_field(VALUE obj) { check_free(obj); return make_field_obj(mysql_fetch_field(GetMysqlRes(obj))); } |
#fetch_field_direct(nr) ⇒ Object
fetch_field_direct(nr)
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 |
# File 'ext/mysql.c', line 1397 static VALUE fetch_field_direct(VALUE obj, VALUE nr) { MYSQL_RES* res; unsigned int max; unsigned int n; check_free(obj); res = GetMysqlRes(obj); max = mysql_num_fields(res); n = NUM2INT(nr); if (n >= max) rb_raise(eMysql, "%d: out of range (max: %d)", n, max-1); #if MYSQL_VERSION_ID >= 32226 return make_field_obj(mysql_fetch_field_direct(res, n)); #else return make_field_obj(&mysql_fetch_field_direct(res, n)); #endif } |
#fetch_fields ⇒ Object
fetch_fields()
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 |
# File 'ext/mysql.c', line 1379 static VALUE fetch_fields(VALUE obj) { MYSQL_RES* res; MYSQL_FIELD* f; unsigned int n; VALUE ret; unsigned int i; check_free(obj); res = GetMysqlRes(obj); f = mysql_fetch_fields(res); n = mysql_num_fields(res); ret = rb_ary_new2(n); for (i=0; i<n; i++) rb_ary_store(ret, i, make_field_obj(&f[i])); return ret; } |
#fetch_hash(*args) ⇒ Object
fetch_hash(with_table=false)
1582 1583 1584 1585 1586 1587 1588 1589 1590 |
# File 'ext/mysql.c', line 1582 static VALUE fetch_hash(int argc, VALUE* argv, VALUE obj) { VALUE with_table; check_free(obj); rb_scan_args(argc, argv, "01", &with_table); if (with_table == Qnil) with_table = Qfalse; return fetch_hash2(obj, with_table); } |
#fetch_lengths ⇒ Object
fetch_lengths()
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 |
# File 'ext/mysql.c', line 1416 static VALUE fetch_lengths(VALUE obj) { MYSQL_RES* res; unsigned int n; unsigned long* lengths; VALUE ary; unsigned int i; check_free(obj); res = GetMysqlRes(obj); n = mysql_num_fields(res); lengths = mysql_fetch_lengths(res); if (lengths == NULL) return Qnil; ary = rb_ary_new2(n); for (i=0; i<n; i++) rb_ary_store(ary, i, INT2NUM(lengths[i])); return ary; } |
#fetch_row ⇒ Object
fetch_row()
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 |
# File 'ext/mysql.c', line 1436 static VALUE fetch_row(VALUE obj) { MYSQL_RES* res; unsigned int n; MYSQL_ROW row; unsigned long* lengths; VALUE ary; unsigned int i; check_free(obj); res = GetMysqlRes(obj); n = mysql_num_fields(res); row = mysql_fetch_row(res); lengths = mysql_fetch_lengths(res); if (row == NULL) return Qnil; ary = rb_ary_new2(n); for (i=0; i<n; i++) rb_ary_store(ary, i, row[i]? rb_tainted_str_new(row[i], lengths[i]): Qnil); return ary; } |
#field_seek(offset) ⇒ Object
field_seek(offset)
1593 1594 1595 1596 1597 |
# File 'ext/mysql.c', line 1593 static VALUE field_seek(VALUE obj, VALUE offset) { check_free(obj); return INT2NUM(mysql_field_seek(GetMysqlRes(obj), NUM2INT(offset))); } |
#field_tell ⇒ Object
field_tell()
1600 1601 1602 1603 1604 |
# File 'ext/mysql.c', line 1600 static VALUE field_tell(VALUE obj) { check_free(obj); return INT2NUM(mysql_field_tell(GetMysqlRes(obj))); } |
#free ⇒ Object
free()
1607 1608 1609 1610 1611 1612 1613 1614 1615 |
# File 'ext/mysql.c', line 1607 static VALUE res_free(VALUE obj) { struct mysql_res* resp = DATA_PTR(obj); check_free(obj); mysql_free_result(resp->res); resp->freed = Qtrue; store_result_count--; return Qnil; } |
#num_fields ⇒ Object
num_fields()
1618 1619 1620 1621 1622 |
# File 'ext/mysql.c', line 1618 static VALUE num_fields(VALUE obj) { check_free(obj); return INT2NUM(mysql_num_fields(GetMysqlRes(obj))); } |
#num_rows ⇒ Object
num_rows()
1625 1626 1627 1628 1629 |
# File 'ext/mysql.c', line 1625 static VALUE num_rows(VALUE obj) { check_free(obj); return INT2NUM(mysql_num_rows(GetMysqlRes(obj))); } |
#row_seek(offset) ⇒ Object
row_seek(offset)
1632 1633 1634 1635 1636 1637 1638 1639 1640 |
# File 'ext/mysql.c', line 1632 static VALUE row_seek(VALUE obj, VALUE offset) { MYSQL_ROW_OFFSET prev_offset; if (CLASS_OF(offset) != cMysqlRowOffset) rb_raise(rb_eTypeError, "wrong argument type %s (expected Mysql::RowOffset)", rb_obj_classname(offset)); check_free(obj); prev_offset = mysql_row_seek(GetMysqlRes(obj), DATA_PTR(offset)); return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, prev_offset); } |
#row_tell ⇒ Object
row_tell()
1643 1644 1645 1646 1647 1648 1649 |
# File 'ext/mysql.c', line 1643 static VALUE row_tell(VALUE obj) { MYSQL_ROW_OFFSET offset; check_free(obj); offset = mysql_row_tell(GetMysqlRes(obj)); return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, offset); } |