fix(gbase8s): stabilize connections and table access
Co-authored-by: zipg <4047349+zipg@users.noreply.github.com>
This commit is contained in:
1 parent
7d5a9459e4
commit
7e6923d53b
26 files changed
+375
-46
No files matched your search
@@ -5,6 +5,7 @@ import {
|
||||
connectionObjectTreeNodeSchema,
|
||||
connectionObjectTreeQuerySchema,
|
||||
connectionQueryExecutionSchema,
|
||||
connectionShouldDiscoverJdbcSchemas,
|
||||
connectionShouldLoadIdentifierQuote,
|
||||
connectionUsesDatabaseObjectTreeMode,
|
||||
effectiveDatabaseTypeForConnection,
|
||||
@@ -87,6 +88,8 @@ describe("jdbc dialect inference", () => {
|
||||
expect(connectionShouldLoadIdentifierQuote({ db_type: "jdbc", jdbc_driver_class: "org.postgresql.Driver" })).toBe(true);
|
||||
expect(connectionShouldLoadIdentifierQuote({ db_type: "kingbase" })).toBe(true);
|
||||
expect(connectionShouldLoadIdentifierQuote({ db_type: "gaussdb" })).toBe(true);
|
||||
expect(connectionShouldLoadIdentifierQuote({ db_type: "gbase", driver_profile: "gbase8s" })).toBe(true);
|
||||
expect(connectionShouldLoadIdentifierQuote({ db_type: "gbase", driver_profile: "gbase8a" })).toBe(false);
|
||||
expect(
|
||||
connectionShouldLoadIdentifierQuote({
|
||||
db_type: "jdbc",
|
||||
@@ -96,6 +99,11 @@ describe("jdbc dialect inference", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("falls back to a flat table tree when GBase 8s reports no schemas", () => {
|
||||
expect(connectionShouldDiscoverJdbcSchemas({ db_type: "gbase", driver_profile: "gbase8s" })).toBe(true);
|
||||
expect(connectionShouldDiscoverJdbcSchemas({ db_type: "gbase", driver_profile: "gbase8a" })).toBe(false);
|
||||
});
|
||||
|
||||
it("recognizes GaussDB reached through PostgreSQL-compatible JDBC drivers", () => {
|
||||
const connection = {
|
||||
db_type: "jdbc" as const,
|
||||
|
||||
@@ -34,6 +34,17 @@ describe("qualifiedTableName — SQLite attached databases", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("qualifiedTableName — GBase 8s", () => {
|
||||
it("keeps the owner unquoted when the driver reports no identifier quote support", () => {
|
||||
expect(qualifiedTableName({ databaseType: "informix", identifierQuote: "", schema: "gbasedbt", tableName: "connection_smoke" })).toBe("gbasedbt.connection_smoke");
|
||||
expect(quoteTableDataIdentifier("informix", "connection_smoke", "")).toBe("connection_smoke");
|
||||
});
|
||||
|
||||
it("keeps native Informix qualification when no driver capability was loaded", () => {
|
||||
expect(qualifiedTableName({ databaseType: "informix", schema: "gbasedbt", tableName: "connection_smoke" })).toBe("gbasedbt.connection_smoke");
|
||||
});
|
||||
});
|
||||
|
||||
describe("quoteTableIdentifier", () => {
|
||||
it("backtick-quotes mysql identifiers", () => {
|
||||
expect(quoteTableIdentifier("mysql", "orders")).toBe("`orders`");
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { preventDialogDocumentSelectAll } from "../dialogTextSelection";
|
||||
|
||||
function keyboardEvent(target: EventTarget, options: { key?: string; metaKey?: boolean; ctrlKey?: boolean; altKey?: boolean } = {}) {
|
||||
return {
|
||||
key: options.key ?? "a",
|
||||
metaKey: options.metaKey ?? false,
|
||||
ctrlKey: options.ctrlKey ?? false,
|
||||
altKey: options.altKey ?? false,
|
||||
target,
|
||||
preventDefault: vi.fn(),
|
||||
} as unknown as KeyboardEvent;
|
||||
}
|
||||
|
||||
describe("preventDialogDocumentSelectAll", () => {
|
||||
it("prevents page selection from non-text dialog surfaces", () => {
|
||||
const event = keyboardEvent(document.createElement("div"), { metaKey: true });
|
||||
|
||||
expect(preventDialogDocumentSelectAll(event)).toBe(true);
|
||||
expect(event.preventDefault).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it.each([document.createElement("input"), document.createElement("textarea")])("keeps native select-all for text controls", (target) => {
|
||||
const event = keyboardEvent(target, { ctrlKey: true });
|
||||
|
||||
expect(preventDialogDocumentSelectAll(event)).toBe(false);
|
||||
expect(event.preventDefault).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps native select-all for nested textbox content", () => {
|
||||
const textbox = document.createElement("div");
|
||||
textbox.setAttribute("role", "textbox");
|
||||
const child = document.createElement("span");
|
||||
textbox.appendChild(child);
|
||||
const event = keyboardEvent(child, { metaKey: true });
|
||||
|
||||
expect(preventDialogDocumentSelectAll(event)).toBe(false);
|
||||
expect(event.preventDefault).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not intercept ordinary typing", () => {
|
||||
const event = keyboardEvent(document.createElement("div"));
|
||||
|
||||
expect(preventDialogDocumentSelectAll(event)).toBe(false);
|
||||
expect(event.preventDefault).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
function isDialogTextInputTarget(target: EventTarget | null): boolean {
|
||||
if (!(target instanceof Element)) return false;
|
||||
return target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || (target instanceof HTMLElement && target.isContentEditable) || !!target.closest("[contenteditable='true'], [role='textbox']");
|
||||
}
|
||||
|
||||
export function preventDialogDocumentSelectAll(event: KeyboardEvent): boolean {
|
||||
const isSelectAll = event.key.toLowerCase() === "a" && (event.metaKey || event.ctrlKey) && !event.altKey;
|
||||
if (!isSelectAll || isDialogTextInputTarget(event.target)) return false;
|
||||
event.preventDefault();
|
||||
return true;
|
||||
}
|
||||
@@ -69,6 +69,7 @@ export function effectiveDatabaseTypeForConnection(connection?: JdbcDialectConne
|
||||
|
||||
export function connectionShouldLoadIdentifierQuote(connection: JdbcDialectConnection | undefined): boolean {
|
||||
if (!connection) return false;
|
||||
if (connection.db_type === "gbase" && isGbase8sProfile(connection.driver_profile)) return true;
|
||||
if (connection.db_type === "kingbase") return true;
|
||||
if (gaussdbIdentifierQuoteStyle(connection) !== "auto") return false;
|
||||
if (connection.db_type === "gaussdb") return true;
|
||||
@@ -142,6 +143,9 @@ export function connectionUsesDatabaseObjectTreeMode(connection?: JdbcDialectCon
|
||||
}
|
||||
|
||||
export function connectionShouldDiscoverJdbcSchemas(connection?: JdbcDialectConnection): boolean {
|
||||
// GBase 8s exposes owner schemas only when the current database can use them
|
||||
// in DML; non-ANSI databases fall back to the flat table tree.
|
||||
if (connection?.db_type === "gbase" && isGbase8sProfile(connection.driver_profile)) return true;
|
||||
return connection?.db_type === "jdbc" && !inferJdbcDialect(connection);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ export function quoteTableIdentifier(databaseType: DatabaseType | undefined, nam
|
||||
|
||||
export function quoteTableDataIdentifier(databaseType: DatabaseType | undefined, name: string, identifierQuote?: string): string {
|
||||
if ((databaseType === "gaussdb" || databaseType === "opengauss" || databaseType === "postgres") && identifierQuote != null) return quoteGaussDbJdbcIdentifier(name, identifierQuote);
|
||||
if (databaseType === "kingbase" && identifierQuote != null) {
|
||||
if ((databaseType === "kingbase" || databaseType === "informix") && identifierQuote != null) {
|
||||
if (!identifierQuote) return name;
|
||||
return `${identifierQuote}${name.replaceAll(identifierQuote, identifierQuote + identifierQuote)}${identifierQuote}`;
|
||||
}
|
||||
@@ -81,6 +81,11 @@ export function qualifiedTableName(options: Pick<BuildTableSelectSqlOptions, "da
|
||||
}
|
||||
return quotedTable;
|
||||
}
|
||||
if (databaseType === "informix" && identifierQuote != null) {
|
||||
const quotedTable = quoteTableDataIdentifier(databaseType, tableName, identifierQuote);
|
||||
const trimmedSchema = schema?.trim();
|
||||
return trimmedSchema ? `${quoteTableDataIdentifier(databaseType, trimmedSchema, identifierQuote)}.${quotedTable}` : quotedTable;
|
||||
}
|
||||
if ((isSchemaAware(databaseType) || databaseType === "sqlite") && !usesDatabaseObjectTreeMode(databaseType) && schema) {
|
||||
if (databaseType === "sqlserver") {
|
||||
const linked = parseSqlServerLinkedSchema(schema);
|
||||
|
||||
Reference in new issue
Block a user