all_hashes now returns an empty array on empty results

This commit is contained in:
oldmoe 2008-09-05 05:59:33 +02:00
parent 4108162bbb
commit 02e8481161

View File

@ -1069,9 +1069,17 @@ static VALUE process_all_hashes(VALUE obj, VALUE with_table, int build_array, in
{ {
MYSQL_RES* res = GetMysqlRes(obj); MYSQL_RES* res = GetMysqlRes(obj);
unsigned int n = mysql_num_fields(res); unsigned int n = mysql_num_fields(res);
VALUE ary;
if(build_array)
ary = rb_ary_new();
MYSQL_ROW row = mysql_fetch_row(res); // need one early to determine the columns MYSQL_ROW row = mysql_fetch_row(res); // need one early to determine the columns
if (row == NULL) if (row == NULL){
if(build_array){
return ary;
}else{
return Qnil; return Qnil;
}
}
unsigned long* lengths = mysql_fetch_lengths(res); unsigned long* lengths = mysql_fetch_lengths(res);
MYSQL_FIELD* fields = mysql_fetch_fields(res); MYSQL_FIELD* fields = mysql_fetch_fields(res);
unsigned int i; unsigned int i;
@ -1105,9 +1113,6 @@ static VALUE process_all_hashes(VALUE obj, VALUE with_table, int build_array, in
rb_iv_set(obj, "tblcolname", colname); rb_iv_set(obj, "tblcolname", colname);
} }
} }
VALUE ary;
if(build_array)
ary = rb_ary_new();
while(row != NULL) while(row != NULL)
{ {