rename method to each, seek dataset to beginning on each call of #each
This commit is contained in:
parent
d90e2a3187
commit
872bdb0caf
@ -208,7 +208,7 @@ static VALUE rb_mysql_result_fetch_row(int argc, VALUE * argv, VALUE self) {
|
|||||||
return rowHash;
|
return rowHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE rb_mysql_result_fetch_rows(int argc, VALUE * argv, VALUE self) {
|
static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
|
||||||
VALUE dataset, opts, block;
|
VALUE dataset, opts, block;
|
||||||
MYSQL_RES * result;
|
MYSQL_RES * result;
|
||||||
unsigned long numRows, i;
|
unsigned long numRows, i;
|
||||||
@ -217,6 +217,10 @@ static VALUE rb_mysql_result_fetch_rows(int argc, VALUE * argv, VALUE self) {
|
|||||||
|
|
||||||
rb_scan_args(argc, argv, "01&", &opts, &block);
|
rb_scan_args(argc, argv, "01&", &opts, &block);
|
||||||
|
|
||||||
|
// force-start at the beginning of the result set for proper
|
||||||
|
// behavior of #each
|
||||||
|
mysql_data_seek(result, 0);
|
||||||
|
|
||||||
numRows = mysql_num_rows(result);
|
numRows = mysql_num_rows(result);
|
||||||
if (numRows == 0) {
|
if (numRows == 0) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
@ -262,7 +266,7 @@ void Init_mysql2_ext() {
|
|||||||
cMysql2Result = rb_define_class_under(mMysql2, "Result", rb_cObject);
|
cMysql2Result = rb_define_class_under(mMysql2, "Result", rb_cObject);
|
||||||
// rb_define_method(cMysql2Result, "fetch_row", rb_mysql_result_fetch_row, -1);
|
// rb_define_method(cMysql2Result, "fetch_row", rb_mysql_result_fetch_row, -1);
|
||||||
// rb_define_method(cMysql2Result, "fetch_rows", rb_mysql_result_fetch_rows, -1);
|
// rb_define_method(cMysql2Result, "fetch_rows", rb_mysql_result_fetch_rows, -1);
|
||||||
rb_define_method(cMysql2Result, "each", rb_mysql_result_fetch_rows, -1);
|
rb_define_method(cMysql2Result, "each", rb_mysql_result_each, -1);
|
||||||
|
|
||||||
VALUE mEnumerable = rb_const_get(rb_cObject, rb_intern("Enumerable"));
|
VALUE mEnumerable = rb_const_get(rb_cObject, rb_intern("Enumerable"));
|
||||||
rb_include_module(cMysql2Result, mEnumerable);
|
rb_include_module(cMysql2Result, mEnumerable);
|
||||||
|
@ -31,5 +31,5 @@ VALUE cMysql2Result;
|
|||||||
static ID sym_symbolize_keys;
|
static ID sym_symbolize_keys;
|
||||||
static VALUE rb_mysql_result_to_obj(MYSQL_RES * res);
|
static VALUE rb_mysql_result_to_obj(MYSQL_RES * res);
|
||||||
static VALUE rb_mysql_result_fetch_row(int argc, VALUE * argv, VALUE self);
|
static VALUE rb_mysql_result_fetch_row(int argc, VALUE * argv, VALUE self);
|
||||||
static VALUE rb_mysql_result_fetch_rows(int argc, VALUE * argv, VALUE self);
|
static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self);
|
||||||
void rb_mysql_result_free(void * result);
|
void rb_mysql_result_free(void * result);
|
Loading…
Reference in New Issue
Block a user