Michael Granger avatar 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.

Comments (0)

Files changed (1)

 	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;
 }
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.