Skip to content

Commit d40bc00

Browse files
committed
Moved/tidied tests. Bug fix in client.c
The bug fix in client.c is less than ideal but there isn't really another option without some rearchitecting. Basically, wrapper->active should not be set to 0 when mysql_use_result is being used until we have iterated through the full result set (as the wrpaper is infact still active). Unfortunately, we would need to change this within Mysql2::Result, which isn't possible at the moment unless we pass the client to the result object (which seems overkill). So, for now, the query will fail with a "commands out of sync" error. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: ext/mysql2/client.c # modified: spec/mysql2/client_spec.rb # modified: spec/mysql2/result_spec.rb # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # Gemfile.lock
1 parent 07261d9 commit d40bc00

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

ext/mysql2/client.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,13 @@ static VALUE nogvl_do_result(void *ptr, char use_result) {
281281
wrapper = (mysql_client_wrapper *)ptr;
282282
if(use_result) {
283283
result = mysql_use_result(wrapper->client);
284-
// new commands can't be issued until this cursor is read all the way through
285284
} else {
286285
result = mysql_store_result(wrapper->client);
287-
288-
// once our result is stored off, this connection is
289-
// ready for another command to be issued
290-
wrapper->active = 0;
291286
}
292287

288+
// once our result is stored off, this connection is
289+
// ready for another command to be issued
290+
wrapper->active = 0;
293291
return (VALUE)result;
294292
}
295293

spec/mysql2/client_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ def connect *args
9292
end
9393

9494
context "#query" do
95+
it "should let you query again if iterating is finished when streaming" do
96+
@client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false).each {}
97+
98+
expect {
99+
@client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false)
100+
}.to_not raise_exception(Mysql2::Error)
101+
end
102+
103+
it "should not let you query again if iterating is not finished when streaming" do
104+
@client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false).first
105+
106+
expect {
107+
@client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false)
108+
}.to raise_exception(Mysql2::Error)
109+
end
110+
95111
it "should only accept strings as the query parameter" do
96112
lambda {
97113
@client.query ["SELECT 'not right'"]

spec/mysql2/result_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,11 @@
8686

8787
it "should throw an exception if we try to iterate twice when streaming is enabled" do
8888
result = @client.query "SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false
89-
expect do
89+
90+
expect {
9091
result.each {}
9192
result.each {}
92-
end.to raise_exception(Mysql2::Error)
93-
end
94-
95-
it "should let you query again after iterating completely when streaming" do
96-
@client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false).each {}
97-
@client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false).should_not raise_exception(Mysql2::Error)
93+
}.to raise_exception(Mysql2::Error)
9894
end
9995
end
10096

0 commit comments

Comments
 (0)