diff --git a/src/conn/mod.rs b/src/conn/mod.rs index ed33e40..dfc5157 100644 --- a/src/conn/mod.rs +++ b/src/conn/mod.rs @@ -466,6 +466,7 @@ impl Conn { } fn handle_err(&mut self) { + self.0.status_flags = StatusFlags::empty(); self.0.has_results = false; self.0.ok_packet = None; } @@ -1146,9 +1147,16 @@ impl Drop for Conn { #[allow(non_snake_case)] mod test { mod my_conn { - use std::{collections::HashMap, io::Write, iter, process}; + use std::{ + collections::HashMap, io::Write, iter, process, sync::mpsc::sync_channel, + time::Duration, + }; - use mysql_common::{binlog::events::EventData, packets::binlog_request::BinlogRequest}; + use mysql_common::{ + binlog::events::EventData, packets::binlog_request::BinlogRequest, + value::json::Serialized, + }; + use serde_json::json; use crate::{ from_row, from_value, params, @@ -1754,6 +1762,35 @@ mod test { .unwrap(); } + #[test] + fn issue_285() { + let (tx, rx) = sync_channel::<()>(0); + + let handle = std::thread::spawn(move || { + let mut conn = Conn::new(get_opts()).unwrap(); + const INVALID_SQL: &str = r#" + CREATE TEMPORARY TABLE IF NOT EXISTS `user_details` ( + `user_id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(255) DEFAULT NULL, + `first_name` varchar(50) DEFAULT NULL, + `last_name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`user_id`) + ); + + INSERT INTO `user_details` (`user_id`, `username`, `first_name`, `last_name`) + VALUES (1, 'rogers63', 'david') + "#; + + conn.query_iter(INVALID_SQL).unwrap(); + tx.send(()).unwrap(); + }); + + match rx.recv_timeout(Duration::from_secs(100_000)) { + Ok(_) => handle.join().unwrap(), + Err(_) => panic!("test failed"), + } + } + #[test] fn should_work_with_named_params() { let mut conn = Conn::new(get_opts()).unwrap(); diff --git a/src/conn/query_result.rs b/src/conn/query_result.rs index 4e38e54..9bd35ac 100644 --- a/src/conn/query_result.rs +++ b/src/conn/query_result.rs @@ -136,12 +136,10 @@ impl<'c, 't, 'tc, T: crate::prelude::Protocol> QueryResult<'c, 't, 'tc, T> { /// /// **Requires:** `self.state == OnBoundary` fn handle_next(&mut self) { - if cfg!(debug_assertions) { - if let SetIteratorState::OnBoundary = self.state { - } else { - panic!("self.state == OnBoundary"); - } - } + debug_assert!( + matches!(self.state, SetIteratorState::OnBoundary), + "self.state != OnBoundary" + ); if self.conn.more_results_exists() { match self.conn.handle_result_set() { diff --git a/src/lib.rs b/src/lib.rs index f30cec1..e460c0a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -756,7 +756,7 @@ #![crate_name = "mysql"] #![crate_type = "rlib"] #![crate_type = "dylib"] -#![cfg_attr(feature = "nightly", feature(test, const_fn))] +#![cfg_attr(feature = "nightly", feature(test))] #[cfg(feature = "nightly")] extern crate test;