rust-mysql-simple
rust-mysql-simple copied to clipboard
for row in result_set - break not working
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 -
}
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:
- Explicitly limit the result set (for example using
LIMIT 10
in your query). (would recommend ❤️) - Kill the corresponding process using another connection (see SHOW PROCESSLIST and KILL mysql statements). (would not recommend 💔)
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
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.
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.