Hi, Christophe, Won't wrapping the first `for` loop into curly braces help? I suspect this happens because of `for` loop desugaring, which kind of "leaves" the iterator created by `execute_query()` "in scope" (not really, but only for borrow checker).
2014-05-29 19:38 GMT+04:00 Christophe Pedretti <christophe.pedre...@gmail.com>: > Hello all, > > i know that this issue is already covered by issues #9113 #6393 and #9113 > but actually i have no solution. My code is a library for accessing > databases. In my example, the database represented by db containes a table t > with columns i:integer, f:float, t:text, b:blob. > > Everything works fine except the following code used to test my library > > match db.prepare_statement("SELECT i,f,t,b FROM t where t like ?;") { > > Ok(mut st) => { > > st.set_string(1, "%o%"); > > for i in st.execute_query() { > > match i { > > Ok(s) => println!("{}:{}:{}:{}", s.get_long(0), s.get_double(1), > s.get_string(2), s.get_blob(3) ), > > Err(e) => match e.detail { > > Some(s) => println!("{}", s), > > None => () > > } > > } > > } > > st.set_string(1, "%e%"); <- PROBLEM HERE > for i in st.execute_query() { <- PROBLEM HERE > > ... > } > > }, > Err(e) => match e.detail { > > None => (), > > Some(s) => println!("{}", s) > > } > > } > > The compilation error says > > test-db.rs:71:8: 71:10 error: cannot borrow `st` as mutable more than once > at a time > test-db.rs:71 > st.set_string(1, "%e%"); > ^~ > test-db.rs:61:17: 61:19 note: previous borrow of `st` occurs here; the > mutable borrow prevents subse > quent moves, borrows, or modification of `st` until the borrow ends > test-db.rs:61 for i in > st.execute_query() { > ^~ > test-db.rs:88:7: 88:7 note: previous borrow ends here > test-db.rs:58 match > db.prepare_statement("SELECT i,f,t,b FROM t wh > ere t like ?;") { > ... > test-db.rs:88 } > ^ > error: aborting due to previous error > > do we have a solution for #6393 ? > > Thanks > > -- > Christophe > http://chris-pe.github.io/Rustic/ > > > _______________________________________________ > Rust-dev mailing list > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev > _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev