Skip to content

Commit e58d027

Browse files
committed
Merge pull request #737 from ajaska/fix-cache-rows-on-prepared-statements
Fix :cache_rows => false on prepared statements
2 parents 23e2b76 + f8b95a3 commit e58d027

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

ext/mysql2/result.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
886886

887887
if (wrapper->stmt_wrapper && !cacheRows && !wrapper->is_streaming) {
888888
rb_warn(":cache_rows is forced for prepared statements (if not streaming)");
889+
cacheRows = 1;
889890
}
890891

891892
if (wrapper->stmt_wrapper && !cast) {

spec/mysql2/statement_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@
128128
expect(test_result['decimal_test']).to eql(123.45)
129129
end
130130

131+
it "should warn but still work if cache_rows is set to false" do
132+
@client.query_options.merge!(:cache_rows => false)
133+
statement = @client.prepare 'SELECT 1'
134+
result = nil
135+
expect { result = statement.execute.to_a }.to output(/:cache_rows is forced for prepared statements/).to_stderr
136+
expect(result.length).to eq(1)
137+
end
138+
131139
context "utf8_db" do
132140
before(:each) do
133141
@client.query("DROP DATABASE IF EXISTS test_mysql2_stmt_utf8")

0 commit comments

Comments
 (0)