fix(gaussdb): support M mode SQL generation and DDL
This commit is contained in:
12 files changed
+296
-37
No files matched your search
@@ -5223,6 +5223,7 @@ const {
|
||||
copyInsertTargetLabel: computed(() => props.tableMeta?.tableName ?? props.customSaveHandler?.targetLabel),
|
||||
mongoUpdateTarget: computed(() => props.mongoUpdateTarget),
|
||||
databaseType: computed(() => props.databaseType),
|
||||
identifierQuote: computed(() => connectionStore.connectionIdentifierQuote(props.connectionId)),
|
||||
connectionId: computed(() => props.connectionId),
|
||||
database: computed(() => props.executionDatabase ?? props.database),
|
||||
context: computed(() => props.context),
|
||||
|
||||
@@ -1876,6 +1876,7 @@ async function exportTableData(row: ObjectBrowserRow, format: "csv" | "xlsx", co
|
||||
connectionId: props.connection.id,
|
||||
database: props.database,
|
||||
schema,
|
||||
identifierQuote: connectionStore.connectionIdentifierQuote(props.connection.id),
|
||||
tableName: row.name,
|
||||
filePath,
|
||||
format,
|
||||
|
||||
@@ -1248,7 +1248,8 @@ async function loadTemplateContext(allowView = false) {
|
||||
}
|
||||
}
|
||||
|
||||
return { node, dbType, tableSchema, columns, tableType };
|
||||
const identifierQuote = connectionStore.connectionIdentifierQuote(node.connectionId);
|
||||
return { node, dbType, identifierQuote, tableSchema, columns, tableType };
|
||||
}
|
||||
|
||||
function openSqlTemplateTab(connectionId: string, database: string, schema: string | undefined, catalog: string | undefined, sql: string, title?: string) {
|
||||
@@ -1262,6 +1263,7 @@ async function newSelectTemplate() {
|
||||
if (!context) return;
|
||||
const sql = buildTableSelectTemplate({
|
||||
databaseType: context.dbType,
|
||||
identifierQuote: context.identifierQuote,
|
||||
catalog: context.node.catalog,
|
||||
database: context.node.database,
|
||||
schema: context.tableSchema,
|
||||
@@ -1280,6 +1282,7 @@ async function newInsertTemplate() {
|
||||
if (!context) return;
|
||||
const sql = buildTableInsertTemplate({
|
||||
databaseType: context.dbType,
|
||||
identifierQuote: context.identifierQuote,
|
||||
catalog: context.node.catalog,
|
||||
database: context.node.database,
|
||||
schema: context.tableSchema,
|
||||
@@ -1299,6 +1302,7 @@ async function newUpdateTemplate() {
|
||||
if (!context) return;
|
||||
const sql = buildTableUpdateTemplate({
|
||||
databaseType: context.dbType,
|
||||
identifierQuote: context.identifierQuote,
|
||||
catalog: context.node.catalog,
|
||||
database: context.node.database,
|
||||
schema: context.tableSchema,
|
||||
@@ -1317,6 +1321,7 @@ async function newDeleteTemplate() {
|
||||
if (!context) return;
|
||||
const sql = buildTableDeleteTemplate({
|
||||
databaseType: context.dbType,
|
||||
identifierQuote: context.identifierQuote,
|
||||
catalog: context.node.catalog,
|
||||
database: context.node.database,
|
||||
schema: context.tableSchema,
|
||||
|
||||
@@ -76,6 +76,7 @@ export interface UseDataGridExportOptions {
|
||||
copyInsertTargetLabel?: ComputedRef<string | undefined>;
|
||||
mongoUpdateTarget?: ComputedRef<MongoCopyUpdateTarget | undefined>;
|
||||
databaseType: ComputedRef<DatabaseType | undefined>;
|
||||
identifierQuote?: ComputedRef<string | undefined>;
|
||||
connectionId: ComputedRef<string | undefined>;
|
||||
database: ComputedRef<string | undefined>;
|
||||
context: ComputedRef<"results" | "table-data" | undefined>;
|
||||
@@ -1002,6 +1003,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
connectionId: connectionId.value,
|
||||
database: database.value,
|
||||
schema: meta.schema,
|
||||
identifierQuote: options.identifierQuote?.value,
|
||||
tableName: meta.tableName,
|
||||
filePath: outputPath,
|
||||
format,
|
||||
|
||||
@@ -284,6 +284,7 @@ export function useSidebarTreeExportRuntime(options: SidebarTreeExportRuntimeOpt
|
||||
connectionId,
|
||||
database,
|
||||
schema: node.schema || undefined,
|
||||
identifierQuote: connectionStore.connectionIdentifierQuote(connectionId),
|
||||
tableName: node.label,
|
||||
filePath: outputPath,
|
||||
format,
|
||||
|
||||
@@ -3538,6 +3538,7 @@ export interface TableExportRequest {
|
||||
connectionId: string;
|
||||
database: string;
|
||||
schema?: string;
|
||||
identifierQuote?: string;
|
||||
tableName: string;
|
||||
filePath: string;
|
||||
format: "csv" | "xlsx" | "json" | "markdown" | "sql" | "txt";
|
||||
|
||||
@@ -50,8 +50,8 @@ function quoteCypherIdentifier(name: string): string {
|
||||
return `\`${name.replace(/`/g, "``")}\``;
|
||||
}
|
||||
|
||||
export function qualifiedTableName(options: Pick<BuildTableSelectSqlOptions, "databaseType" | "schema" | "tableName" | "catalog" | "database">): string {
|
||||
const { databaseType, schema, tableName, catalog, database } = options;
|
||||
export function qualifiedTableName(options: Pick<BuildTableSelectSqlOptions, "databaseType" | "identifierQuote" | "schema" | "tableName" | "catalog" | "database">): string {
|
||||
const { databaseType, identifierQuote, schema, tableName, catalog, database } = options;
|
||||
// Doris / StarRocks multi-catalog: address external-catalog tables with the
|
||||
// 3-part `catalog.database.table` form, which the engines accept directly.
|
||||
if (catalog && catalog !== "internal" && (databaseType === "doris" || databaseType === "starrocks")) {
|
||||
@@ -73,6 +73,14 @@ export function qualifiedTableName(options: Pick<BuildTableSelectSqlOptions, "da
|
||||
}
|
||||
return quoteTableIdentifier(databaseType, tableName);
|
||||
}
|
||||
if ((databaseType === "gaussdb" || databaseType === "opengauss" || databaseType === "postgres" || databaseType === "kingbase") && identifierQuote != null) {
|
||||
const quotedTable = quoteTableDataIdentifier(databaseType, tableName, identifierQuote);
|
||||
const trimmedSchema = schema?.trim();
|
||||
if (trimmedSchema) {
|
||||
return `${quoteTableDataIdentifier(databaseType, trimmedSchema, identifierQuote)}.${quotedTable}`;
|
||||
}
|
||||
return quotedTable;
|
||||
}
|
||||
if ((isSchemaAware(databaseType) || databaseType === "sqlite") && !usesDatabaseObjectTreeMode(databaseType) && schema) {
|
||||
if (databaseType === "sqlserver") {
|
||||
const linked = parseSqlServerLinkedSchema(schema);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { ColumnInfo, DatabaseType } from "@/types/database";
|
||||
import { qualifiedTableName, quoteTableIdentifier } from "@/lib/table/tableSelectSql";
|
||||
import { qualifiedTableName, quoteTableDataIdentifier } from "@/lib/table/tableSelectSql";
|
||||
|
||||
export interface TableSqlTemplateOptions {
|
||||
databaseType?: DatabaseType;
|
||||
identifierQuote?: string;
|
||||
schema?: string;
|
||||
catalog?: string;
|
||||
database?: string;
|
||||
@@ -17,7 +18,7 @@ export function buildTableSelectTemplate(options: TableSqlTemplateOptions): stri
|
||||
if (!columns.length) {
|
||||
return `SELECT *\nFROM ${tableName};`;
|
||||
}
|
||||
const selectColumns = columns.map((column) => quoteTableIdentifier(options.databaseType, column.name));
|
||||
const selectColumns = columns.map((column) => templateIdentifier(options, column.name));
|
||||
return `SELECT ${selectColumns.join(", ")}\nFROM ${tableName};`;
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ function buildDefaultInsertTemplate(options: TableSqlTemplateOptions): string {
|
||||
return `INSERT INTO ${tableName}\n/* TODO: add column values */\nVALUES ();`;
|
||||
}
|
||||
|
||||
const columnNames = columns.map((column) => quoteTableIdentifier(options.databaseType, column.name));
|
||||
const columnNames = columns.map((column) => templateIdentifier(options, column.name));
|
||||
const values = columns.map((column) => columnPlaceholderValue(column, options.databaseType));
|
||||
return `INSERT INTO ${tableName} (${columnNames.join(", ")})\nVALUES (${values.join(", ")});`;
|
||||
}
|
||||
@@ -84,20 +85,21 @@ export function buildTableUpdateTemplate(options: TableSqlTemplateOptions): stri
|
||||
const primaryKeys = columns.filter((column) => column.is_primary_key);
|
||||
const primaryKeyNames = new Set(primaryKeys.map((column) => column.name));
|
||||
const updateColumns = columns.filter((column) => !primaryKeyNames.has(column.name));
|
||||
const setClause = updateColumns.length ? updateColumns.map((column) => `${quoteTableIdentifier(options.databaseType, column.name)} = ${columnPlaceholderValue(column, options.databaseType)}`).join(",\n ") : "/* TODO: set column = value */";
|
||||
const setClause = updateColumns.length ? updateColumns.map((column) => `${templateIdentifier(options, column.name)} = ${columnPlaceholderValue(column, options.databaseType)}`).join(",\n ") : "/* TODO: set column = value */";
|
||||
|
||||
return `UPDATE ${tableName}\nSET ${setClause}\n${buildWhereClause(options.databaseType, primaryKeys)};`;
|
||||
return `UPDATE ${tableName}\nSET ${setClause}\n${buildWhereClause(options, primaryKeys)};`;
|
||||
}
|
||||
|
||||
export function buildTableDeleteTemplate(options: TableSqlTemplateOptions): string {
|
||||
const tableName = templateTableName(options);
|
||||
const primaryKeys = (options.columns ?? []).filter((column) => column.is_primary_key);
|
||||
return `DELETE FROM ${tableName}\n${buildWhereClause(options.databaseType, primaryKeys)};`;
|
||||
return `DELETE FROM ${tableName}\n${buildWhereClause(options, primaryKeys)};`;
|
||||
}
|
||||
|
||||
function templateTableName(options: TableSqlTemplateOptions): string {
|
||||
return qualifiedTableName({
|
||||
databaseType: options.databaseType,
|
||||
identifierQuote: options.identifierQuote,
|
||||
catalog: options.catalog,
|
||||
database: options.database,
|
||||
schema: options.schema,
|
||||
@@ -105,9 +107,13 @@ function templateTableName(options: TableSqlTemplateOptions): string {
|
||||
});
|
||||
}
|
||||
|
||||
function buildWhereClause(databaseType: DatabaseType | undefined, primaryKeys: ColumnInfo[]): string {
|
||||
function templateIdentifier(options: TableSqlTemplateOptions, name: string): string {
|
||||
return quoteTableDataIdentifier(options.databaseType, name, options.identifierQuote);
|
||||
}
|
||||
|
||||
function buildWhereClause(options: TableSqlTemplateOptions, primaryKeys: ColumnInfo[]): string {
|
||||
if (!primaryKeys.length) return "WHERE /* TODO: add WHERE clause */";
|
||||
const conditions = primaryKeys.map((column) => `${quoteTableIdentifier(databaseType, column.name)} = ${columnPlaceholderValue(column, databaseType)}`);
|
||||
const conditions = primaryKeys.map((column) => `${templateIdentifier(options, column.name)} = ${columnPlaceholderValue(column, options.databaseType)}`);
|
||||
return `WHERE ${conditions.join(" AND ")}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user