Skip to content

Commit

Permalink
fix(cubesql): Allow quoted variables with SHOW <variable> syntax (#4313)
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou committed Apr 4, 2022
1 parent 61475ab commit 3eece0e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 13 additions & 2 deletions rust/cubesql/cubesql/src/compile/mod.rs
Expand Up @@ -1634,7 +1634,7 @@ impl QueryPlanner {
}

fn show_variable_to_plan(&self, variable: &Vec<Ident>) -> CompilationResult<QueryPlan> {
let name = ObjectName(variable.to_vec()).to_string();
let name = variable.to_vec()[0].value.clone();
if self.state.protocol == DatabaseProtocol::PostgreSQL {
let stmt = if name.eq_ignore_ascii_case("all") {
parse_sql_to_statement(
Expand All @@ -1644,9 +1644,10 @@ impl QueryPlanner {
)?
} else {
parse_sql_to_statement(
// TODO: column name might be expected to match variable name
&format!(
"SELECT setting FROM pg_catalog.pg_settings where name = '{}'",
name.to_lowercase()
escape_single_quote_string(&name.to_lowercase()),
),
self.state.protocol.clone(),
)?
Expand Down Expand Up @@ -4564,6 +4565,16 @@ mod tests {
execute_query("show variables;".to_string(), DatabaseProtocol::MySQL).await?
);

// Postgres escaped with quotes
insta::assert_snapshot!(
"show_variable_quoted",
execute_query(
"show \"max_allowed_packet\";".to_string(),
DatabaseProtocol::PostgreSQL
)
.await?
);

Ok(())
}

Expand Down
@@ -0,0 +1,9 @@
---
source: cubesql/src/compile/mod.rs
expression: "execute_query(\"show \\\"max_allowed_packet\\\";\".to_string(),\n DatabaseProtocol::PostgreSQL).await?"
---
+----------+
| setting |
+----------+
| 67108864 |
+----------+

0 comments on commit 3eece0e

Please sign in to comment.