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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(opengauss): derive identifier quotes from the compatibility mode (#13803)
ordinary being2e6375377ad7
diff --git a/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.ts b/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.tsindex 47ae700495..1352249685 100644--- a/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.ts+++ b/apps/desktop/src/lib/__tests__/database/jdbcDialect.spec.ts@@ -291,6 +291,9 @@ describe("jdbc dialect inference", () => {expect(connectionShouldLoadIdentifierQuote({ db_type: "kingbase" })).toBe(true);expect(connectionShouldLoadIdentifierQuote({ db_type: "kyuubi" })).toBe(true);expect(connectionShouldLoadIdentifierQuote({ db_type: "gaussdb" })).toBe(true);+ // openGauss databases switch between backticks (B/MySQL mode) and double+ // quotes (A/PG modes), so the quote has to come from the backend probe.+ expect(connectionShouldLoadIdentifierQuote({ db_type: "opengauss" })).toBe(true);expect(connectionShouldLoadIdentifierQuote({ db_type: "gbase8s", driver_profile: "gbase8s" })).toBe(true);expect(connectionShouldLoadIdentifierQuote({ db_type: "gbase", driver_profile: "gbase8a" })).toBe(false);// Cloud Spanner reports a backtick for GoogleSQL and a double quote for thediff --git a/apps/desktop/src/lib/database/jdbcDialect.ts b/apps/desktop/src/lib/database/jdbcDialect.tsindex 484176948f..8f6793e3c4 100644--- a/apps/desktop/src/lib/database/jdbcDialect.ts+++ b/apps/desktop/src/lib/database/jdbcDialect.ts@@ -154,6 +154,11 @@ export function connectionShouldLoadIdentifierQuote(connection: JdbcDialectConneif (connection.db_type === "spanner") return true;if (gaussdbIdentifierQuoteStyle(connection) !== "auto") return false;if (connection.db_type === "gaussdb") return true;+ // openGauss inherits the database compatibility mode for identifier quoting:+ // MySQL-compatible (B) databases only accept backticks, while A/PG modes use+ // double quotes. The backend probes `pg_database.datcompatibility`, so fetch+ // the reported quote instead of assuming the PostgreSQL default.+ if (connection.db_type === "opengauss") return true;if (connection.db_type !== "jdbc") return false;const dialect = inferJdbcDialect(connection);return dialect === "jdbc" || ["gaussdb", "opengauss", "postgres"].includes(dialect ?? "");diff --git a/apps/desktop/src/stores/__tests__/connectionStore.opengaussIdentifierQuote.spec.ts b/apps/desktop/src/stores/__tests__/connectionStore.opengaussIdentifierQuote.spec.tsnew file mode 100644index 0000000000..1aff4d0eb6--- /dev/null+++ b/apps/desktop/src/stores/__tests__/connectionStore.opengaussIdentifierQuote.spec.ts@@ -0,0 +1,54 @@+import { createPinia, setActivePinia } from "pinia";+import { beforeEach, describe, expect, it, vi } from "vitest";+import type { ConnectionConfig } from "@/types/database";++function installLocalStorage() {+ const data = new Map<string, string>();+ vi.stubGlobal("localStorage", {+ getItem: vi.fn((key: string) => data.get(key) ?? null),+ setItem: vi.fn((key: string, value: string) => data.set(key, value)),+ removeItem: vi.fn((key: string) => data.delete(key)),+ });+}++const opengaussConnection: ConnectionConfig = {+ id: "opengauss-mysql",+ name: "openGauss",+ db_type: "opengauss",+ host: "127.0.0.1",+ port: 5432,+ username: "gaussdb",+ password: "",+ database: "postgres",+};++describe("connectionStore openGauss identifier quote", () => {+ beforeEach(() => {+ vi.resetModules();+ vi.unstubAllGlobals();+ installLocalStorage();+ setActivePinia(createPinia());+ });++ it("loads the compatibility-mode quote reported for native openGauss connections", async () => {+ const connectionIdentifierQuote = vi.fn().mockResolvedValue("`");++ vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));+ vi.doMock("@/lib/backend/api", () => ({+ connectDb: vi.fn().mockResolvedValue(opengaussConnection.id),+ connectionDatabaseInfo: vi.fn().mockRejectedValue(new Error("metadata unavailable")),+ connectionIdentifierQuote,+ saveConnections: vi.fn().mockResolvedValue(undefined),+ saveSidebarLayout: vi.fn().mockResolvedValue(undefined),+ }));++ const { useConnectionStore } = await import("@/stores/connectionStore");+ const store = useConnectionStore();+ await store.addConnection(opengaussConnection);+ await store.connect(opengaussConnection);++ expect(connectionIdentifierQuote).toHaveBeenCalledOnce();+ expect(connectionIdentifierQuote).toHaveBeenCalledWith(opengaussConnection.id);+ expect(store.connectionIdentifierQuote(opengaussConnection.id)).toBe("`");+ }, 30_000);+});diff --git a/crates/dbx-core/src/connection/mod.rs b/crates/dbx-core/src/connection/mod.rsindex abc11e22ff..ad42795b51 100644--- a/crates/dbx-core/src/connection/mod.rs+++ b/crates/dbx-core/src/connection/mod.rs@@ -6515,14 +6515,23 @@ impl AppState {let pool_key = self.get_or_create_pool(connection_id, database).await?;enum IdentifierQuoteSource {NativeGaussdb(deadpool_postgres::Pool),+ NativeOpenGauss(deadpool_postgres::Pool),Agent(Arc<db::agent_driver::PooledAgentClient>),ExternalDriver { config: Arc<ConnectionConfig>, session: Arc<PluginDriverSession> },}let source = {match self.pool_handle(&pool_key).await.as_ref() {+ // GaussDB and openGauss take their identifier quote from the+ // database compatibility mode (`pg_database.datcompatibility`):+ // MySQL-compatible databases use backticks, while Oracle and+ // PostgreSQL modes use double quotes. Both share the native+ // PostgreSQL pool.Some(PoolKind::Postgres(pool)) if config.db_type == DatabaseType::Gaussdb => {Some(IdentifierQuoteSource::NativeGaussdb(pool.clone()))}+ Some(PoolKind::Postgres(pool)) if config.db_type == DatabaseType::OpenGauss => {+ Some(IdentifierQuoteSource::NativeOpenGauss(pool.clone()))+ }Some(PoolKind::Agent(client)) if database_capabilities::is_agent_type(&config.db_type) => {Some(IdentifierQuoteSource::Agent(client.clone()))}@@ -6534,6 +6543,9 @@ impl AppState {};match source {Some(IdentifierQuoteSource::NativeGaussdb(pool)) => Ok(db::postgres::gaussdb_identifier_quote(&pool).await),+ Some(IdentifierQuoteSource::NativeOpenGauss(pool)) => {+ Ok(db::postgres::opengauss_identifier_quote(&pool).await)+ }Some(IdentifierQuoteSource::Agent(client)) => {let mut agent = client.lock().await;let info = agent.connection_info(Some(db::connection_timeout())).await?;@@ -15437,6 +15449,43 @@ for line in sys.stdin:.await;}+ #[tokio::test]+ #[ignore = "requires a reachable openGauss instance via environment variables"]+ async fn live_opengauss_identifier_quote_matches_compatibility_mode() {+ let host = std::env::var("DBX_TEST_OPENGAUSS_HOST").expect("DBX_TEST_OPENGAUSS_HOST not set");+ let port = std::env::var("DBX_TEST_OPENGAUSS_PORT")+ .expect("DBX_TEST_OPENGAUSS_PORT not set")+ .parse::<u16>()+ .expect("DBX_TEST_OPENGAUSS_PORT should be a u16");+ let username = std::env::var("DBX_TEST_OPENGAUSS_USER").expect("DBX_TEST_OPENGAUSS_USER not set");+ let password = std::env::var("DBX_TEST_OPENGAUSS_PASSWORD").expect("DBX_TEST_OPENGAUSS_PASSWORD not set");+ let database = std::env::var("DBX_TEST_OPENGAUSS_DATABASE").unwrap_or_else(|_| "postgres".to_string());++ let mut config = live_postgres_like_config(DatabaseType::OpenGauss, &host, port, &username, &password, None);+ config.id = "opengauss-quote-live".to_string();+ config.database = Some(database.clone());++ let (state, dir) = test_app_state().await;+ state.configs.write().await.insert(config.id.clone(), config);+ let pool_key = state.get_or_create_pool("opengauss-quote-live", Some(&database)).await.unwrap();+ let pool = match state.pool_handle(&pool_key).await.expect("openGauss pool should be created") {+ PoolKind::Postgres(pool) => pool,+ _ => panic!("openGauss should use the PostgreSQL pool path"),+ };++ let mode = db::postgres::opengauss_compatibility_mode(&pool).await.unwrap();+ let quote = state.connection_identifier_quote("opengauss-quote-live", Some(&database)).await.unwrap();+ println!("[live] database = {database}, compatibility mode = {mode:?}, identifier quote = {quote:?}");+ assert_eq!(+ quote.as_deref(),+ mode.as_deref().and_then(db::postgres::gaussdb_identifier_quote_for_compatibility_mode),+ "identifier quote should follow the database compatibility mode"+ );++ pool.close();+ let _ = std::fs::remove_dir_all(dir);+ }+#[tokio::test]#[ignore = "requires a reachable openGauss instance via environment variables"]async fn live_opengauss_native_connection_succeeds() {diff --git a/crates/dbx-driver-postgres/src/postgres.rs b/crates/dbx-driver-postgres/src/postgres.rsindex efeae06b57..647f17b8e9 100644--- a/crates/dbx-driver-postgres/src/postgres.rs+++ b/crates/dbx-driver-postgres/src/postgres.rs@@ -48,6 +48,9 @@ use crate::types::{pub const GAUSSDB_COMPATIBILITY_SQL: &str ="SELECT datcompatibility FROM pg_catalog.pg_database WHERE datname = current_database()";+/// Identifier quote implied by the GaussDB database compatibility mode+/// (`pg_database.datcompatibility`): MySQL-style modes need backticks while+/// Oracle and PostgreSQL modes need double quotes.pub async fn gaussdb_identifier_quote(pool: &Pool) -> Option<String> {let timeout = super::connection_timeout();let client = checkout_postgres_client(pool, None, timeout).await.ok()?;@@ -57,6 +60,17 @@ pub async fn gaussdb_identifier_quote(pool: &Pool) -> Option<String> {gaussdb_identifier_quote_for_compatibility_mode(&compatibility_mode).map(str::to_string)}+/// Identifier quote for an openGauss database, derived from the same+/// `datcompatibility` catalog value. openGauss exposes A/B/PG modes, so the+/// MySQL-compatible (B) databases need backticks while A/PG need double quotes.+pub async fn opengauss_identifier_quote(pool: &Pool) -> Option<String> {+ opengauss_compatibility_mode(pool)+ .await+ .ok()+ .flatten()+ .and_then(|mode| gaussdb_identifier_quote_for_compatibility_mode(&mode).map(str::to_string))+}+pub fn gaussdb_identifier_quote_for_compatibility_mode(compatibility_mode: &str) -> Option<&'static str> {match compatibility_mode.trim().to_ascii_uppercase().as_str() {"M" | "B" | "MYSQL" => Some("`"),diff --git a/crates/dbx-sql-dialect/src/sql_dialect/tests.rs b/crates/dbx-sql-dialect/src/sql_dialect/tests.rsindex b744381ca4..f9c45cf111 100644--- a/crates/dbx-sql-dialect/src/sql_dialect/tests.rs+++ b/crates/dbx-sql-dialect/src/sql_dialect/tests.rs@@ -612,6 +612,32 @@ fn jdbc_table_data_qualifies_schema_without_forcing_identifier_quotes() {);}+#[test]+fn opengauss_table_data_uses_compatibility_identifier_quote() {+ // openGauss keeps the PostgreSQL catalog but switches identifier quoting with+ // the database compatibility mode: B/MySQL databases reject the double quotes+ // that A/PG databases require (#13596).+ let base = TableDataSelectSqlOptions {+ database_type: Some(DatabaseType::OpenGauss),+ schema: Some("dbx-demo".to_string()),+ table_name: "order".to_string(),+ limit: Some(25),+ ..Default::default()+ };++ assert_eq!(+ build_table_data_select_sql(TableDataSelectSqlOptions {+ identifier_quote: Some("`".to_string()),+ ..base.clone()+ }),+ "SELECT * FROM `dbx-demo`.`order` LIMIT 25;"+ );+ assert_eq!(+ build_table_data_select_sql(TableDataSelectSqlOptions { identifier_quote: Some("\"".to_string()), ..base }),+ "SELECT * FROM \"dbx-demo\".\"order\" LIMIT 25;"+ );+}+#[test]fn builds_table_data_where_and_schema_queries() {assert_eq!(