Skip to content

Commit

Permalink
patch from ptzn with offset and limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Lapshin committed Jun 16, 2008
1 parent 7a2ebd5 commit e3f1bf4
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ext/query.c
Expand Up @@ -253,24 +253,33 @@ VALUE intersys_query_fetch(VALUE self) {

VALUE intersys_query_each(VALUE self) {
struct rbQuery* query;
int i;
Data_Get_Struct(self, struct rbQuery, query);

int i;
// skip offset records
if(query->offset > 0) {
RUN(cbind_query_skip(query->query, query->offset));
for(i = 0; i < query->offset; i++) {
if(intersys_query_fetch(self) == Qnil) {
break;
}
}
}
for(i = query->offset; i < query->offset + query->limit; i++) {

int row_count = 0;
int limit = query->limit > 0 ? query->limit : -1;
while(1) {
VALUE row = intersys_query_fetch(self);
if(row == Qnil || RARRAY(row)->len == 0) {
if(row == Qnil || RARRAY(row)->len == 0 || row_count == limit) {
break;
}
rb_yield(row);
row_count++;
}

query_close(query);
return self;
}



VALUE intersys_query_close(VALUE self) {
struct rbQuery* query;
Data_Get_Struct(self, struct rbQuery, query);
Expand Down

0 comments on commit e3f1bf4

Please sign in to comment.