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
1706 1707 1708 1709 1710 1711 1712 1713 1714 |
# File 'ext/mysql.c', line 1706
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)
1396 1397 1398 1399 1400 1401 |
# File 'ext/mysql.c', line 1396
static VALUE data_seek(VALUE obj, VALUE offset)
{
check_free(obj);
mysql_data_seek(GetMysqlRes(obj), NUM2INT(offset));
return obj;
}
|
#each ⇒ Object
each …
1684 1685 1686 1687 1688 1689 1690 1691 |
# File 'ext/mysql.c', line 1684
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) …
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 |
# File 'ext/mysql.c', line 1694
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()
1404 1405 1406 1407 1408 |
# File 'ext/mysql.c', line 1404
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)
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 |
# File 'ext/mysql.c', line 1429
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()
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 |
# File 'ext/mysql.c', line 1411
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)
1614 1615 1616 1617 1618 1619 1620 1621 1622 |
# File 'ext/mysql.c', line 1614
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()
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 |
# File 'ext/mysql.c', line 1448
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()
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 |
# File 'ext/mysql.c', line 1468
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_enc_tainted_str_new(row[i], lengths[i]): Qnil);
return ary;
}
|
#field_seek(offset) ⇒ Object
field_seek(offset)
1625 1626 1627 1628 1629 |
# File 'ext/mysql.c', line 1625
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()
1632 1633 1634 1635 1636 |
# File 'ext/mysql.c', line 1632
static VALUE field_tell(VALUE obj)
{
check_free(obj);
return INT2NUM(mysql_field_tell(GetMysqlRes(obj)));
}
|
#free ⇒ Object
free()
1639 1640 1641 1642 1643 1644 1645 1646 1647 |
# File 'ext/mysql.c', line 1639
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()
1650 1651 1652 1653 1654 |
# File 'ext/mysql.c', line 1650
static VALUE num_fields(VALUE obj)
{
check_free(obj);
return INT2NUM(mysql_num_fields(GetMysqlRes(obj)));
}
|
#num_rows ⇒ Object
num_rows()
1657 1658 1659 1660 1661 |
# File 'ext/mysql.c', line 1657
static VALUE num_rows(VALUE obj)
{
check_free(obj);
return INT2NUM(mysql_num_rows(GetMysqlRes(obj)));
}
|
#row_seek(offset) ⇒ Object
row_seek(offset)
1664 1665 1666 1667 1668 1669 1670 1671 1672 |
# File 'ext/mysql.c', line 1664
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()
1675 1676 1677 1678 1679 1680 1681 |
# File 'ext/mysql.c', line 1675
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);
}
|