fix(cache): avoid quoted identifiers and alias lists for cache sql

Closes #8340
This commit is contained in:
t8y2 committed 2026-09-08 01:53:50 +08:00
1 parent 4f2c67e34e
commit abc32f1c71
5 files changed
+124 -6

No files matched your search

@@ -555,7 +555,17 @@ pub fn build_table_select_sql(options: TableSelectSqlOptions<'_>) -> String {
options
.order_columns
.iter()
.map(|column| format!("{} ASC", quote_table_identifier(database_type, column)))
.map(|column| {
let quoted = if database_type == Some(DatabaseType::Iris) {
// Caché/IRIS may run with delimited identifiers disabled,
// where a quoted ORDER BY name becomes a string literal and
// silently degrades to a constant sort.
quote_iris_identifier(column, None)
} else {
quote_table_identifier(database_type, column)
};
format!("{quoted} ASC")
})
.collect::<Vec<_>>()
.join(", ")
)
@@ -605,7 +615,20 @@ fn quoted_table_columns_or_star(database_type: Option<DatabaseType>, columns: &[
if columns.is_empty() {
return "*".to_string();
}
columns.iter().map(|column| quote_table_identifier(database_type, column)).collect::<Vec<_>>().join(", ")
columns
.iter()
.map(|column| {
if database_type == Some(DatabaseType::Iris) {
// With delimited identifiers disabled, the Caché/IRIS JDBC
// preparser turns a quoted column name into a `:%qpar` host
// variable, so ordinary names must stay unquoted.
quote_iris_identifier(column, None)
} else {
quote_table_identifier(database_type, column)
}
})
.collect::<Vec<_>>()
.join(", ")
}
fn build_rownum_table_select_sql(
+27
View File
@@ -339,6 +339,33 @@ fn builds_select_sql_with_limit_syntax_for_database_type() {
}),
"SELECT TOP 100 * FROM Ens.AlarmResponse"
);
// Caché 2016 often runs with delimited identifiers disabled: the JDBC
// preparser turns a quoted column into a `:%qpar` host variable and a
// quoted ORDER BY name into a string literal (constant sort), so ordinary
// column names must stay unquoted (#8340).
assert_eq!(
build_table_select_sql(TableSelectSqlOptions {
database_type: Some(DatabaseType::Iris),
schema: Some("SQLUser"),
table_name: "CT_Country",
columns: &columns,
order_columns: &keys,
limit: 200,
}),
"SELECT TOP 200 id, name FROM SQLUser.CT_Country ORDER BY id ASC"
);
// Non-Iris dialects keep their own quoting for the same input.
assert_eq!(
build_table_select_sql(TableSelectSqlOptions {
database_type: Some(DatabaseType::Mysql),
schema: None,
table_name: "users",
columns: &columns,
order_columns: &keys,
limit: 100,
}),
"SELECT `id`, `name` FROM `users` ORDER BY `id` ASC LIMIT 100;"
);
assert_eq!(
build_table_select_sql(TableSelectSqlOptions {
database_type: Some(DatabaseType::Iotdb),