fix(query): skip comment-only SQL execution
This commit is contained in:
parent
7bb869d398
commit
a32ead56b9
|
|
@ -968,6 +968,15 @@ pub async fn execute_sql_statement_with_options(
|
|||
return Err("Use MongoDB-specific commands".to_string());
|
||||
}
|
||||
|
||||
let db_type = connection_database_type(state, connection_id).await;
|
||||
let has_executable_sql = db_type.map_or_else(
|
||||
|| crate::sql::has_executable_sql(sql),
|
||||
|db_type| crate::sql::has_executable_sql_for_database(sql, db_type),
|
||||
);
|
||||
if !has_executable_sql {
|
||||
return Ok(empty_query_result(0));
|
||||
}
|
||||
|
||||
// When a query tab has a client session, keep even database-less execution
|
||||
// on that tab-scoped pool so connection-level state (for example MySQL @vars)
|
||||
// survives across runs.
|
||||
|
|
@ -1094,6 +1103,9 @@ pub async fn execute_multi_core_with_options(
|
|||
|| split_sql_statements(sql),
|
||||
|db_type| crate::sql::split_sql_statements_for_database(sql, db_type),
|
||||
);
|
||||
if statements.is_empty() {
|
||||
return Ok(vec![empty_query_result(0)]);
|
||||
}
|
||||
|
||||
let mysql_pool = {
|
||||
let connections = state.connections.read().await;
|
||||
|
|
@ -1204,6 +1216,20 @@ fn error_query_result(message: String) -> db::QueryResult {
|
|||
}
|
||||
}
|
||||
|
||||
fn empty_query_result(execution_time_ms: u128) -> db::QueryResult {
|
||||
db::QueryResult {
|
||||
columns: vec![],
|
||||
column_types: Vec::new(),
|
||||
column_sortables: vec![],
|
||||
rows: vec![],
|
||||
affected_rows: 0,
|
||||
execution_time_ms,
|
||||
truncated: false,
|
||||
session_id: None,
|
||||
has_more: false,
|
||||
}
|
||||
}
|
||||
|
||||
async fn execute_multi_sqlserver(
|
||||
state: &AppState,
|
||||
pool_key: &str,
|
||||
|
|
|
|||
|
|
@ -1585,10 +1585,14 @@ fn dollar_quote_tag_at(chars: &[char], start: usize) -> Option<String> {
|
|||
None
|
||||
}
|
||||
|
||||
fn has_executable_sql(statement: &str) -> bool {
|
||||
pub fn has_executable_sql(statement: &str) -> bool {
|
||||
has_executable_sql_with_options(statement, SqlParsingOptions::default())
|
||||
}
|
||||
|
||||
pub fn has_executable_sql_for_database(statement: &str, db_type: DatabaseType) -> bool {
|
||||
has_executable_sql_with_options(statement, SqlParsingOptions::for_database_type(db_type))
|
||||
}
|
||||
|
||||
fn executable_sql_bounds(statement: &str, options: SqlParsingOptions) -> Option<(usize, usize)> {
|
||||
let trimmed_end = statement.trim_end().len();
|
||||
let trimmed = &statement[..trimmed_end];
|
||||
|
|
@ -1771,6 +1775,15 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skips_comment_only_statement_with_semicolon() {
|
||||
assert_eq!(
|
||||
split_sql_script("-- insert sqluser.tb_a values (6,'006','测试6','无');").unwrap(),
|
||||
Vec::<String>::new()
|
||||
);
|
||||
assert!(!super::has_executable_sql("-- insert sqluser.tb_a values (6,'006','测试6','无');"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_postgres_dollar_quoted_function_body_together() {
|
||||
let sql = "\
|
||||
|
|
|
|||
Loading…
Reference in New Issue