Skip to content

Commit

Permalink
Clear status_flags on server error
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbeam committed Jul 19, 2021
1 parent 29d0ee2 commit e5db79d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
41 changes: 39 additions & 2 deletions src/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 4 additions & 6 deletions src/conn/query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e5db79d

Please sign in to comment.