Class Mysql::Result
In: mysql.c
Parent: Object

Methods

Public Instance methods

data_seek(offset)

[Source]

/*      data_seek(offset)    */
static VALUE data_seek(VALUE obj, VALUE offset)
{
    check_free(obj);
    mysql_data_seek(GetMysqlRes(obj), NUM2INT(offset));
    return obj;
}

each {…}

[Source]

/*      each {...}   */
static VALUE each(VALUE obj)
{
    VALUE row;
    check_free(obj);
    while ((row = fetch_row(obj)) != Qnil)
        rb_yield(row);
    return obj;
}

each_hash(with_table=false) {…}

[Source]

/*      each_hash(with_table=false) {...}    */
static VALUE each_hash(int argc, VALUE* argv, VALUE obj)
{
    VALUE with_table;
    VALUE hash;
    check_free(obj);
    rb_scan_args(argc, argv, "01", &with_table);
    if (with_table == Qnil)
        with_table = Qfalse;
    while ((hash = fetch_hash2(obj, with_table)) != Qnil)
        rb_yield(hash);
    return obj;
}

fetch_field()

[Source]

/*      fetch_field()        */
static VALUE fetch_field(VALUE obj)
{
    check_free(obj);
    return make_field_obj(mysql_fetch_field(GetMysqlRes(obj)));
}

fetch_field_direct(nr)

[Source]

/*      fetch_field_direct(nr)       */
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)
#if RUBY_VERSION_CODE < 160
        Raise(eMysql, "%d: out of range (max: %d)", n, max-1);
#else
        rb_raise(eMysql, "%d: out of range (max: %d)", n, max-1);
#endif
#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()

[Source]

/*      fetch_fields()       */
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(with_table=false)

[Source]

/*      fetch_hash(with_table=false) */
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()

[Source]

/*      fetch_lengths()              */
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()

[Source]

/*      fetch_row()  */
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)

[Source]

/*      field_seek(offset)   */
static VALUE field_seek(VALUE obj, VALUE offset)
{
    check_free(obj);
    return INT2NUM(mysql_field_seek(GetMysqlRes(obj), NUM2INT(offset)));
}

field_tell()

[Source]

/*      field_tell()         */
static VALUE field_tell(VALUE obj)
{
    check_free(obj);
    return INT2NUM(mysql_field_tell(GetMysqlRes(obj)));
}

free()

[Source]

/*      free()                       */
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()

[Source]

/*      num_fields()         */
static VALUE num_fields(VALUE obj)
{
    check_free(obj);
    return INT2NUM(mysql_num_fields(GetMysqlRes(obj)));
}

num_rows()

[Source]

/*      num_rows()   */
static VALUE num_rows(VALUE obj)
{
    check_free(obj);
    return INT2NUM(mysql_num_rows(GetMysqlRes(obj)));
}

row_seek(offset)

[Source]

/*      row_seek(offset)     */
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()

[Source]

/*      row_tell()   */
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);
}

[Validate]