rust-mysql-simple icon indicating copy to clipboard operation
rust-mysql-simple copied to clipboard

for row in result_set - break not working

Open zirill opened this issue 4 years ago • 4 comments

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 -
}

zirill avatar Dec 19 '20 04:12 zirill

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 💔)

blackbeam avatar Dec 19 '20 11:12 blackbeam

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

zirill avatar Dec 19 '20 12:12 zirill

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.

blackbeam avatar Dec 19 '20 16:12 blackbeam

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.

zirill avatar Dec 19 '20 17:12 zirill