8000 Additional fixes for PG::Result#values and #column_values. · danielcode/ruby-pg@490bbb5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 490bbb5

Browse files
committed
Additional fixes for PG::Result#values and #column_values.
- Revert the row-building loop of Result#values to use the heap, too. - Use the heap for building #column_values, too. Props to Lars Kanis for figuring out the problem. Refs #135, #136, #138.
1 parent eabb146 commit 490bbb5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ext/pg_result.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -729,12 +729,12 @@ pgresult_values(VALUE self)
729729
VALUE ary = rb_ary_new2(num_rows);
730730

731731
for ( row = 0; row < num_rows; row++ ) {
732-
VALUE new_row[ num_fields ];
732+
VALUE new_row = rb_ary_new2(num_fields);
733733

734734
/* populate the row */
735735
for ( field = 0; field < num_fields; field++ ) {
736736
if ( PQgetisnull(result, row, field) ) {
737-
new_row[ field ] = Qnil;
737+
rb_ary_store( new_row, field, Qnil );
738738
}
739739
else {
740740
VALUE val = rb_tainted_str_new( PQgetvalue(result, row, field),
@@ -748,11 +748,11 @@ pgresult_values(VALUE self)
748748
rb_enc_associate( val, rb_ascii8bit_encoding() );
749749
}
750750
#endif
751-
new_row[ field ] = val;
751+
rb_ary_store( new_row, fi 8000 eld, val );
752752
}
753753
}
754754

755-
rb_ary_store( ary, row, rb_ary_new4(num_fields, new_row) );
755+
rb_ary_store( ary, row, new_row );
756756
}
757757

758758
return ary;
@@ -770,7 +770,7 @@ make_column_result_array( VALUE self, int col )
770770
int rows = PQntuples( result );
771771
int i;
772772
VALUE val = Qnil;
773-
VALUE results[ rows ];
773+
VALUE results = rb_ary_new2( rows );
774774

775775
if ( col >= PQnfields(result) )
776776
rb_raise( rb_eIndexError, "no column %d in result", col );
@@ -788,10 +788,10 @@ make_column_result_array( VALUE self, int col )
788788
}
789789
#endif
790790

791-
results[ i ] = val;
791+
rb_ary_store( results, i, val );
792792
}
793793

794-
return rb_ary_new4( rows, results );
794+
return results;
795795
}
796796

797797

0 commit comments

Comments
 (0)
0