fix(gaussdb): quote identifiers by compatibility mode

This commit is contained in:
zipg authored and GitHub committed 2026-07-29 23:34:58 +08:00
1 parent d0c3a3fd2e
commit 66f94f23f1
28 files changed
+1207 -134

No files matched your search

+109 -2
View File
@@ -770,7 +770,10 @@ pub fn build_data_grid_column_distinct_values_sql(options: DataGridColumnDistinc
}
pub fn build_data_grid_count_sql(options: DataGridCountSqlOptions) -> String {
let table = if options.database_type == Some(DatabaseType::Kingbase) {
let table = if crate::sql_dialect::uses_connection_identifier_quote(
options.database_type,
options.identifier_quote.as_deref(),
) {
crate::sql_dialect::table_data_qualified_table_name(
options.database_type,
options.schema.as_deref(),
@@ -2691,7 +2694,7 @@ fn data_grid_qualified_table_name(
table_name: &str,
identifier_quote: Option<&str>,
) -> String {
if database_type == Some(DatabaseType::Kingbase) {
if crate::sql_dialect::uses_connection_identifier_quote(database_type, identifier_quote) {
crate::sql_dialect::table_data_qualified_table_name(database_type, schema, table_name, identifier_quote)
} else {
crate::sql_dialect::qualified_table_name_with_catalog(database_type, catalog, schema, database, table_name)
@@ -3191,6 +3194,33 @@ mod tests {
#[test]
fn builds_filter_conditions() {
for (database_type, identifier_quote, column_name, expected) in [
(DatabaseType::Gaussdb, Some("\""), "column_01", "column_01 = 1"),
(DatabaseType::Gaussdb, Some("\""), "MixedCase", "\"MixedCase\" = 1"),
(DatabaseType::Gaussdb, Some("\""), "order", "\"order\" = 1"),
(DatabaseType::Gaussdb, Some("\""), "order detail", "\"order detail\" = 1"),
(DatabaseType::Gaussdb, Some("\""), "\"AlreadyQuoted\"", "\"AlreadyQuoted\" = 1"),
(DatabaseType::Gaussdb, Some("`"), "MixedCase", "`MixedCase` = 1"),
(DatabaseType::Postgres, Some("`"), "order", "`order` = 1"),
(DatabaseType::OpenGauss, Some("`"), "order detail", "`order detail` = 1"),
(DatabaseType::Gaussdb, None, "column_01", "\"column_01\" = 1"),
(DatabaseType::OpenGauss, None, "column_01", "\"column_01\" = 1"),
] {
assert_eq!(
build_data_grid_context_filter_condition(DataGridContextFilterConditionOptions {
database_type: Some(database_type),
identifier_quote: identifier_quote.map(str::to_string),
column_name: column_name.to_string(),
mode: DataGridContextFilterMode::Equals,
value: json!(1),
values: Vec::new(),
end_value: None,
column_info: Some(column(column_name, "integer", false, None)),
})
.as_deref(),
Some(expected)
);
}
assert_eq!(
build_data_grid_context_filter_condition(DataGridContextFilterConditionOptions {
database_type: Some(DatabaseType::Kingbase),
@@ -3829,6 +3859,30 @@ mod tests {
}),
"SELECT COUNT(*) AS cnt FROM `cqbq_ls`.`ANALYZE`"
);
assert_eq!(
build_data_grid_count_sql(DataGridCountSqlOptions {
database_type: Some(DatabaseType::Gaussdb),
identifier_quote: Some("\"".to_string()),
catalog: None,
database: None,
schema: Some("schema_01".to_string()),
table_name: "table_01".to_string(),
where_input: None,
}),
"SELECT COUNT(*) AS cnt FROM schema_01.table_01"
);
assert_eq!(
build_data_grid_count_sql(DataGridCountSqlOptions {
database_type: Some(DatabaseType::Postgres),
identifier_quote: Some("`".to_string()),
catalog: None,
database: None,
schema: Some("App Schema".to_string()),
table_name: "order".to_string(),
where_input: None,
}),
"SELECT COUNT(*) AS cnt FROM `App Schema`.`order`"
);
}
#[test]
@@ -4478,6 +4532,59 @@ mod tests {
.all(|statement| statement.contains("`gc`.`docfileinfo`") && !statement.contains('"')));
}
#[test]
fn gaussdb_jdbc_save_selectively_quotes_identifiers() {
let result = prepare_data_grid_save(DataGridSaveStatementOptions {
database_type: Some(DatabaseType::Gaussdb),
identifier_quote: Some("\"".to_string()),
table_meta: DataGridTableMeta {
catalog: None,
database: None,
schema: Some("schema_01".to_string()),
table_name: "table_01".to_string(),
primary_keys: vec!["id".to_string()],
columns: Some(vec![column("id", "integer", false, None), column("name", "varchar", false, None)]),
},
columns: vec!["id".to_string(), "name".to_string()],
source_columns: None,
rows: vec![vec![json!(1), json!("old")]],
dirty_rows: vec![(0, vec![(1, json!("new"))])],
deleted_rows: vec![],
new_rows: vec![],
});
assert_eq!(result.validation_error, None);
assert_eq!(result.statements, vec!["UPDATE schema_01.table_01 SET name = 'new' WHERE id = 1;"]);
}
#[test]
fn postgres_driver_to_gaussdb_m_mode_save_uses_backticks() {
let result = prepare_data_grid_save(DataGridSaveStatementOptions {
database_type: Some(DatabaseType::Postgres),
identifier_quote: Some("`".to_string()),
table_meta: DataGridTableMeta {
catalog: None,
database: None,
schema: Some("App Schema".to_string()),
table_name: "order".to_string(),
primary_keys: vec!["ID".to_string()],
columns: Some(vec![
column("ID", "integer", false, None),
column("display name", "varchar", false, None),
]),
},
columns: vec!["ID".to_string(), "display name".to_string()],
source_columns: None,
rows: vec![vec![json!(1), json!("old")]],
dirty_rows: vec![(0, vec![(1, json!("new"))])],
deleted_rows: vec![],
new_rows: vec![],
});
assert_eq!(result.validation_error, None);
assert_eq!(result.statements, vec!["UPDATE `App Schema`.`order` SET `display name` = 'new' WHERE `ID` = 1;"]);
}
#[test]
fn postgres_save_uses_exact_quoted_primary_key_for_update_delete_and_rollback() {
let result = prepare_data_grid_save(DataGridSaveStatementOptions {