Skip to content

Commit

Permalink
mysql: fix CI
Browse files Browse the repository at this point in the history
Task #3446
  • Loading branch information
QianKaiLin committed Oct 26, 2024
1 parent d9d6032 commit d766e56
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 39 deletions.
113 changes: 80 additions & 33 deletions rust/src/mysql/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ impl MysqlState {
self.tx_id += 1;
tx.tx_id = self.tx_id;
tx.tls = self.tls;
if tx.tls {
tx.complete = true;
}
tx.command = Some(command);
SCLogDebug!("Creating new transaction.tx_id: {}", tx.tx_id);
if self.transactions.len() > unsafe { MYSQL_MAX_TX } + self.tx_index_completed {
Expand All @@ -326,9 +329,6 @@ impl MysqlState {
}
self.tx_index_completed = index;
}
if tx.tls {
tx.complete = true;
}
tx
}

Expand Down Expand Up @@ -612,14 +612,22 @@ impl MysqlState {
Some(MysqlStateProgress::LocalFileRequestReceived)
}
MysqlResponsePacket::FieldsList { columns: _ } => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.complete = true;
}
Some(MysqlStateProgress::FieldListResponseReceived)
}
MysqlResponsePacket::Statistics => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.complete = true;
}
Expand All @@ -630,22 +638,34 @@ impl MysqlState {
MysqlResponsePacket::Err { .. } => match self.state_progress {
MysqlStateProgress::CommandReceived
| MysqlStateProgress::TextResulsetContinue => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.complete = true;
}
Some(MysqlStateProgress::CommandResponseReceived)
}
MysqlStateProgress::FieldListReceived => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.complete = true;
}
Some(MysqlStateProgress::FieldListResponseReceived)
}
MysqlStateProgress::StmtExecReceived
| MysqlStateProgress::StmtExecResponseContinue => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.complete = true;
}
Expand All @@ -655,15 +675,23 @@ impl MysqlState {
Some(MysqlStateProgress::StmtResetResponseReceived)
}
MysqlStateProgress::ChangeUserReceived => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.complete = true;
}
Some(MysqlStateProgress::Finished)
}
MysqlStateProgress::StmtFetchReceived
| MysqlStateProgress::StmtFetchResponseContinue => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.complete = true;
}
Expand All @@ -678,16 +706,23 @@ impl MysqlState {
} => match self.state_progress {
MysqlStateProgress::Auth => Some(MysqlStateProgress::AuthFinished),
MysqlStateProgress::CommandReceived => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.affected_rows = Some(rows);
tx.complete = true;
}

Some(MysqlStateProgress::CommandResponseReceived)
}
MysqlStateProgress::StmtExecReceived => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.affected_rows = Some(rows);
tx.complete = true;
Expand All @@ -701,34 +736,38 @@ impl MysqlState {
Some(MysqlStateProgress::StmtResetResponseReceived)
}
MysqlStateProgress::TextResulsetContinue => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.complete = true;
}

Some(MysqlStateProgress::CommandResponseReceived)
}
MysqlStateProgress::StmtExecResponseContinue => {
let prepare_stmt = self.prepare_stmt.take();
let tx = self.get_tx_mut(self.tx_id - 1);
if let Some(tx) = tx {
if let Some(mut prepare_stmt) = prepare_stmt {
let rows = prepare_stmt.rows.take();
if let Some(rows) = rows {
tx.rows = Some(
rows.into_iter()
.map(|row| match row {
MysqlResultBinarySetRow::Err => String::new(),
MysqlResultBinarySetRow::Text(text) => text,
})
.collect::<Vec<String>>(),
);
if self.tx_id > 0 {
let tx = self.get_tx_mut(self.tx_id - 1);
if let Some(tx) = tx {
if let Some(mut prepare_stmt) = prepare_stmt {
let rows = prepare_stmt.rows.take();
if let Some(rows) = rows {
tx.rows = Some(
rows.into_iter()
.map(|row| match row {
MysqlResultBinarySetRow::Err => String::new(),
MysqlResultBinarySetRow::Text(text) => text,
})
.collect::<Vec<String>>(),
);
}

tx.complete = true;
}

tx.complete = true;
}
}

Some(MysqlStateProgress::StmtExecResponseReceived)
}
MysqlStateProgress::StmtFetchResponseContinue => {
Expand All @@ -742,7 +781,11 @@ impl MysqlState {
eof,
rows,
} => {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if !rows.is_empty() {
let mut rows = rows.into_iter().map(|row| row.texts.join(",")).collect();
if let Some(tx) = tx {
Expand Down Expand Up @@ -798,7 +841,11 @@ impl MysqlState {

if !rows.is_empty() {
if eof.status_flags != 0x0A {
let tx = self.get_tx_mut(self.tx_id - 1);
let tx = if self.tx_id > 0 {
self.get_tx_mut(self.tx_id - 1)
} else {
None
};
if let Some(tx) = tx {
tx.rows = Some(
rows.into_iter()
Expand Down
12 changes: 6 additions & 6 deletions rust/src/mysql/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ pub enum MysqlCommand {
},
}

impl MysqlCommand {
pub fn to_string(self) -> String {
impl std::fmt::Display for MysqlCommand {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
MysqlCommand::Quit => "quit".to_string(),
MysqlCommand::Query { query } => query,
MysqlCommand::Ping => "ping".to_string(),
_ => String::new(),
MysqlCommand::Quit => write!(f, "quit"),
MysqlCommand::Query { query } => write!(f, "{}", query),
MysqlCommand::Ping => write!(f, "ping"),
_ => write!(f, ""),
}
}
}
Expand Down

0 comments on commit d766e56

Please sign in to comment.