Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(query): support Caché total-row counts

t8y29f2af0983af3
diff --git a/crates/dbx-core/src/query_result_sql.rs b/crates/dbx-core/src/query_result_sql.rs
index 064c9e79d1..f115722087 100644
--- a/crates/dbx-core/src/query_result_sql.rs
+++ b/crates/dbx-core/src/query_result_sql.rs
@@ -292,7 +292,13 @@ pub fn build_count_query_sql(options: CountQuerySqlOptions) -> QuerySqlBuildResu
.unwrap_or_else(|| err("unsupported"));
}
- let alias = quote_table_identifier(options.database_type, "dbx_count");
+ let alias = if options.database_type == Some(DatabaseType::Iris) {
+ // With delimited identifiers disabled, Caché 2016 can parameterize a
+ // double-quoted alias as a string literal, leaving a trailing :%qpar.
+ "dbx_count".to_string()
+ } else {
+ quote_table_identifier(options.database_type, "dbx_count")
+ };
let wrapped_sql = match options.database_type {
Some(DatabaseType::Iris) => iris_statement_for_derived_table(&statement),
_ => statement,
@@ -3321,7 +3327,7 @@ WHERE u.id = picked.id;
assert_eq!(
result.sql.unwrap(),
- "SELECT COUNT(*) AS dbx_total_rows FROM (SELECT id, appointment_time FROM patients WHERE status = ?) \"dbx_count\";"
+ "SELECT COUNT(*) AS dbx_total_rows FROM (SELECT id, appointment_time FROM patients WHERE status = ?) dbx_count;"
);
}
@@ -3335,7 +3341,7 @@ WHERE u.id = picked.id;
assert_eq!(
result.sql.unwrap(),
- "SELECT COUNT(*) AS dbx_total_rows FROM (SELECT * FROM (SELECT TOP ? id FROM visits WHERE status = ? ORDER BY created_at DESC) recent WHERE id > ?) \"dbx_count\";"
+ "SELECT COUNT(*) AS dbx_total_rows FROM (SELECT * FROM (SELECT TOP ? id FROM visits WHERE status = ? ORDER BY created_at DESC) recent WHERE id > ?) dbx_count;"
);
}
@@ -3348,7 +3354,20 @@ WHERE u.id = picked.id;
assert_eq!(
result.sql.unwrap(),
- "SELECT COUNT(*) AS dbx_total_rows FROM (SELECT id FROM visits WHERE status = ?) \"dbx_count\";"
+ "SELECT COUNT(*) AS dbx_total_rows FROM (SELECT id FROM visits WHERE status = ?) dbx_count;"
+ );
+ }
+
+ #[test]
+ fn iris_count_query_uses_unquoted_alias_for_legacy_cache() {
+ let result = build_count_query_sql(CountQuerySqlOptions {
+ original_sql: "SELECT * FROM TATFY WHERE UpdateDate = '2026-07-30' AND UpdateTime > '08:00:00'".to_string(),
+ database_type: Some(DatabaseType::Iris),
+ });
+
+ assert_eq!(
+ result.sql.unwrap(),
+ "SELECT COUNT(*) AS dbx_total_rows FROM (SELECT * FROM TATFY WHERE UpdateDate = '2026-07-30' AND UpdateTime > '08:00:00') dbx_count;"
);
}