Commits

Michael Granger  committed 62c8ee5

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.

  • Participants
  • Parent commits 4d5e457

Comments (0)

Files changed (1)

File ext/pg_result.c

 	VALUE ary = rb_ary_new2(num_rows);
 
 	for ( row = 0; row < num_rows; row++ ) {
-		VALUE new_row[ num_fields ];
+		VALUE new_row = rb_ary_new2(num_fields);
 
 		/* populate the row */
 		for ( field = 0; field < num_fields; field++ ) {
 			if ( PQgetisnull(result, row, field) ) {
-				new_row[ field ] = Qnil;
+				rb_ary_store( new_row, field, Qnil );
 			}
 			else {
 				VALUE val = rb_tainted_str_new( PQgetvalue(result, row, field), 
 					rb_enc_associate( val, rb_ascii8bit_encoding() );
 				}
 #endif
-				new_row[ field ] = val;
+				rb_ary_store( new_row, field, val );
 			}
 		}
 
-		rb_ary_store( ary, row, rb_ary_new4(num_fields, new_row) );
+		rb_ary_store( ary, row, new_row );
 	}
 
 	return ary;
 	int rows = PQntuples( result );
 	int i;
 	VALUE val = Qnil;
-	VALUE results[ rows ];
+	VALUE results = rb_ary_new2( rows );
 
 	if ( col >= PQnfields(result) )
 		rb_raise( rb_eIndexError, "no column %d in result", col );
 		}
 #endif
 
-		results[ i ] = val;
+		rb_ary_store( results, i, val );
 	}
 
-	return rb_ary_new4( rows, results );
+	return results;
 }