fix(kingbase): quote MySQL-compatible identifiers
This commit is contained in:
39 files changed
+373
-23
No files matched your search
+14
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { qualifiedTableName, quoteTableIdentifier } from "@/lib/table/tableSelectSql";
|
||||
import { qualifiedTableName, quoteTableDataIdentifier, quoteTableIdentifier } from "@/lib/table/tableSelectSql";
|
||||
|
||||
describe("qualifiedTableName — Doris/StarRocks multi-catalog", () => {
|
||||
it("prefixes external catalog for Doris (no schema)", () => {
|
||||
@@ -36,4 +36,17 @@ describe("quoteTableIdentifier", () => {
|
||||
it("bracket-quotes sqlserver identifiers", () => {
|
||||
expect(quoteTableIdentifier("sqlserver", "orders")).toBe("[orders]");
|
||||
});
|
||||
|
||||
it("uses the connection-reported quote for Kingbase table-data identifiers", () => {
|
||||
expect(quoteTableDataIdentifier("kingbase", "order", "`")).toBe("`order`");
|
||||
expect(quoteTableDataIdentifier("kingbase", "MixedCase", '"')).toBe('"MixedCase"');
|
||||
expect(quoteTableDataIdentifier("kingbase", "order detail", "`")).toBe("`order detail`");
|
||||
});
|
||||
|
||||
it("escapes Kingbase identifiers without maintaining a reserved-word list", () => {
|
||||
expect(quoteTableDataIdentifier("kingbase", "ANALYZE", "`")).toBe("`ANALYZE`");
|
||||
expect(quoteTableDataIdentifier("kingbase", "AUTHORIZATION", '"')).toBe('"AUTHORIZATION"');
|
||||
expect(quoteTableDataIdentifier("kingbase", "COLLATE", "`")).toBe("`COLLATE`");
|
||||
expect(quoteTableDataIdentifier("kingbase", "a`b", "`")).toBe("`a``b`");
|
||||
});
|
||||
});
|
||||
@@ -55,6 +55,7 @@ export const connectDb = forward("connectDb");
|
||||
export const connectionFinalProxyPort = forward("connectionFinalProxyPort");
|
||||
export const disconnectDb = forward("disconnectDb");
|
||||
export const checkConnectionHealth = forward("checkConnectionHealth");
|
||||
export const connectionIdentifierQuote = forward("connectionIdentifierQuote");
|
||||
export const closeDatabaseConnection = forward("closeDatabaseConnection");
|
||||
export const refreshConnections = forward("refreshConnections");
|
||||
export const saveConnections = forward("saveConnections");
|
||||
|
||||
@@ -225,6 +225,11 @@ export async function checkConnectionHealth(connectionId: string): Promise<void>
|
||||
return post("/api/connection/check-health", { connectionId });
|
||||
}
|
||||
|
||||
export async function connectionIdentifierQuote(connectionId: string, database?: string): Promise<string | undefined> {
|
||||
const quote = await post<string | null>("/api/connection/identifier-quote", { connectionId, database });
|
||||
return quote ?? undefined;
|
||||
}
|
||||
|
||||
export async function closeDatabaseConnection(connectionId: string, database: string): Promise<boolean> {
|
||||
return post("/api/connection/close-database", { connectionId, database });
|
||||
}
|
||||
|
||||
@@ -652,6 +652,11 @@ export async function checkConnectionHealth(connectionId: string): Promise<void>
|
||||
return invoke("check_connection_health", { connectionId });
|
||||
}
|
||||
|
||||
export async function connectionIdentifierQuote(connectionId: string, database?: string): Promise<string | undefined> {
|
||||
const quote = await invoke<string | null>("connection_identifier_quote", { connectionId, database });
|
||||
return quote ?? undefined;
|
||||
}
|
||||
|
||||
export async function closeDatabaseConnection(connectionId: string, database: string): Promise<boolean> {
|
||||
return invoke("close_database_connection", { connectionId, database });
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ export interface DataGridColumnDistinctValuesSqlOptions {
|
||||
|
||||
export interface DataGridCountSqlOptions {
|
||||
databaseType?: DatabaseType;
|
||||
identifierQuote?: string;
|
||||
catalog?: string;
|
||||
schema?: string;
|
||||
tableName: string;
|
||||
|
||||
@@ -46,6 +46,7 @@ export interface BuildExportInsertStatementsOptions {
|
||||
|
||||
export interface BuildExportPageSqlOptions {
|
||||
databaseType?: DatabaseType;
|
||||
identifierQuote?: string;
|
||||
schema?: string;
|
||||
tableName: string;
|
||||
limit?: number;
|
||||
@@ -72,6 +73,7 @@ export function buildInsertStatements(options: BuildExportInsertStatementsOption
|
||||
export async function buildExportPageSql(options: BuildExportPageSqlOptions): Promise<string> {
|
||||
return buildTableSelectSql({
|
||||
databaseType: options.databaseType,
|
||||
identifierQuote: options.identifierQuote,
|
||||
schema: options.schema,
|
||||
tableName: options.tableName,
|
||||
limit: options.limit ?? DATABASE_EXPORT_PAGE_SIZE,
|
||||
|
||||
@@ -5,6 +5,7 @@ export const TABLE_DATA_EXPORT_PAGE_SIZE = 10_000;
|
||||
|
||||
export interface FetchTableDataForExportOptions {
|
||||
databaseType?: DatabaseType;
|
||||
identifierQuote?: string;
|
||||
schema?: string;
|
||||
tableName: string;
|
||||
tableType?: string;
|
||||
@@ -24,6 +25,7 @@ export async function fetchTableDataForExport(options: FetchTableDataForExportOp
|
||||
while (true) {
|
||||
const sql = await (options.buildPageSql ?? buildTableSelectSql)({
|
||||
databaseType: options.databaseType,
|
||||
identifierQuote: options.identifierQuote,
|
||||
schema: options.schema,
|
||||
tableName: options.tableName,
|
||||
tableType: options.tableType,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { parseSqlServerLinkedSchema, sqlServerLinkedTableName } from "@/lib/data
|
||||
|
||||
export interface BuildTableSelectSqlOptions {
|
||||
databaseType?: DatabaseType;
|
||||
identifierQuote?: string;
|
||||
schema?: string;
|
||||
tableName: string;
|
||||
tableType?: string;
|
||||
@@ -32,6 +33,14 @@ export function quoteTableIdentifier(databaseType: DatabaseType | undefined, nam
|
||||
return `"${name.replace(/"/g, '""')}"`;
|
||||
}
|
||||
|
||||
export function quoteTableDataIdentifier(databaseType: DatabaseType | undefined, name: string, identifierQuote?: string): string {
|
||||
if (databaseType === "kingbase" && identifierQuote != null) {
|
||||
if (!identifierQuote) return name;
|
||||
return `${identifierQuote}${name.replaceAll(identifierQuote, identifierQuote + identifierQuote)}${identifierQuote}`;
|
||||
}
|
||||
return quoteTableIdentifier(databaseType, name);
|
||||
}
|
||||
|
||||
function quoteCypherIdentifier(name: string): string {
|
||||
return `\`${name.replace(/`/g, "``")}\``;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user