Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for row in result_set - break not working #259

Open
zirill opened this issue Dec 19, 2020 · 4 comments
Open

for row in result_set - break not working #259

zirill opened this issue Dec 19, 2020 · 4 comments

Comments

@zirill
Copy link

zirill commented Dec 19, 2020

Hello,

result_set very big
break - stops the execution of the block,
but does not continue the code further.
(until the cycle is complete)

while let Some(result_set) = result.next_set() {
    let result_set = result_set?
    let mut count = 0;
    for row in result_set {
       count = count + 1
       if count > 10 {
           break
       }
    }
   // - not next -
}
@blackbeam
Copy link
Owner

Hi. The break statement means that the result_set will go out of scope and hence dropped. As you can see here the Drop impl for query result is actually the same loop, but with noop on each iteration. You have the following options:

  1. Explicitly limit the result set (for example using LIMIT 10 in your query). (would recommend ❤️)
  2. Kill the corresponding process using another connection (see SHOW PROCESSLIST and KILL mysql statements). (would not recommend 💔)

@zirill
Copy link
Author

zirill commented Dec 19, 2020

Thanks for the options.
The first one does not suit me, I do not interfere with the "SQL Query".
Ideally change:

  fn drop(&mut self) {
        while self.next().is_some() {}
    }

so you can stop the loop

@blackbeam
Copy link
Owner

Ideally change so you can stop the loop.

Oh. Then i suggest you the second option because this loop can't be stopped without breaking the connection.
I'll think about adding a function that aborts the connection unconditionally, but it's an unusual behavior of a client, so the server will complain.

@zirill
Copy link
Author

zirill commented Dec 19, 2020

I'll think about adding a function that aborts the connection unconditionally,

I look forward to, still add "timeout".
Thank you very much for your great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants