Skip to content

Commit 2a7d09d

Browse files
committed
Tests for streaming and stored procedures with multiple result sets
1 parent 41ab20a commit 2a7d09d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

spec/mysql2/client_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,21 @@ def connect *args
614614

615615
@multi_client.more_results?.should be_false
616616
end
617+
618+
it "#more_results? should work with stored procedures" do
619+
@multi_client.query("DROP PROCEDURE IF EXISTS test_proc")
620+
@multi_client.query("CREATE PROCEDURE test_proc() BEGIN SELECT 1 AS 'set_1'; SELECT 2 AS 'set_2'; END")
621+
@multi_client.query("CALL test_proc()").first.should eql({ 'set_1' => 1 })
622+
@multi_client.more_results?.should be_true
623+
624+
@multi_client.next_result
625+
@multi_client.store_result.first.should eql({ 'set_2' => 2 })
626+
627+
@multi_client.next_result
628+
@multi_client.store_result.should be_nil # this is the result from CALL itself
629+
630+
@multi_client.more_results?.should be_false
631+
end
617632
end
618633
end
619634

spec/mysql2/result_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,19 @@
107107

108108
context "streaming" do
109109
it "should maintain a count while streaming" do
110-
result = @client.query('SELECT 1')
111-
112-
result.count.should eql(1)
110+
result = @client.query('SELECT 1', :stream => true, :cache_rows => false)
111+
result.count.should eql(0)
113112
result.each.to_a
114113
result.count.should eql(1)
115114
end
116115

117-
it "should set the actual count of rows after streaming" do
118-
result = @client.query("SELECT * FROM mysql2_test", :stream => true, :cache_rows => false)
116+
it "should retain the count when mixing first and each" do
117+
result = @client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false)
119118
result.count.should eql(0)
120-
result.each {|r| }
119+
result.first
121120
result.count.should eql(1)
121+
result.each.to_a
122+
result.count.should eql(2)
122123
end
123124

124125
it "should not yield nil at the end of streaming" do

0 commit comments

Comments
 (0)