fix: support prepared query option SHOW without changing compatibility

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
discord9
2026-10-09 17:54:55 +08:00
parent dad64729c5
commit 8a7fc2707a
3 changed files with 26 additions and 5 deletions
+7 -4
View File
@@ -281,10 +281,10 @@ fn check_show_variables(query: &str) -> Option<Output> {
} else if SHOW_LOWER_CASE_PATTERN.is_match(query) {
Some(show_variables("lower_case_table_names", "0"))
} else if let Some(matched) = SHOW_VARIABLES_LIKE_PATTERN.find(query) {
let remainder = &query[matched.end()..];
let remainder = strip_leading_comments(remainder).trim_start();
let remainder = remainder.strip_prefix(';').unwrap_or(remainder);
let remainder = strip_leading_comments(remainder);
let mut remainder = strip_leading_comments(&query[matched.end()..]);
while let Some(rest) = remainder.strip_prefix(';') {
remainder = strip_leading_comments(rest);
}
if remainder.is_empty() {
Some(show_variables("", ""))
} else {
@@ -668,6 +668,7 @@ mod test {
"SHOW VARIABLES query.parallelism;",
"SHOW VARIABLES /* comment */ query.parallelism",
"SHOW VARIABLES; SELECT 1",
"SHOW VARIABLES; /* comment */; SELECT 1",
] {
assert!(
check(query, QueryContext::arc(), session.clone()).is_none(),
@@ -678,6 +679,8 @@ mod test {
for query in [
"SHOW VARIABLES",
"SHOW VARIABLES;",
"SHOW VARIABLES;;",
"SHOW VARIABLES; /* comment */;",
"SHOW VARIABLES /* comment */",
"SHOW VARIABLES /* comment */;",
"SHOW VARIABLES # comment",
+1 -1
View File
@@ -355,7 +355,7 @@ impl QueryParser for DefaultQueryParser {
let (sql, copy_to_stdout_format) = if let Ok(mut statements) = parsed_statements {
let first_stmt = statements.remove(0);
let format = check_copy_to_stdout(&first_stmt);
(first_stmt.to_string(), format)
(statement_to_query(&first_stmt), format)
} else {
// bypass the error: it can run into error because of different
// versions of sqlparser
+18
View File
@@ -551,6 +551,24 @@ async fn test_extended_query_regproc_response() -> Result<()> {
Ok(())
}
#[tokio::test]
async fn test_extended_query_show_query_option() -> Result<()> {
let server_port = start_test_server(TlsOption::default()).await?;
let client = create_connection_with_given_db(server_port, DEFAULT_SCHEMA_NAME)
.await
.unwrap();
client
.batch_execute("SET query.parallelism = 2")
.await
.unwrap();
let statement = client.prepare("SHOW query.parallelism").await.unwrap();
let rows = client.query(&statement, &[]).await.unwrap();
assert_eq!(rows.len(), 1);
assert_eq!(rows[0].get::<usize, String>(0), "2");
Ok(())
}
#[tokio::test]
async fn test_extended_query() -> Result<()> {
let server_port = start_test_server(TlsOption::default()).await?;