fix(neo4j): pick node identity function by server version
This commit is contained in:
25 files changed
+461
-30
No files matched your search
@@ -3895,6 +3895,7 @@ async function refreshSavedRows(request: { dirtyRows: ReadonlyMap<number, Readon
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: resolvedDatabaseType.value,
|
||||
driverProfile: connectionStore.getConfig(connectionId)?.driver_profile,
|
||||
serverVersion: connectionStore.getConfig(connectionId)?.database_info?.productVersion,
|
||||
identifierQuote: connectionStore.connectionIdentifierQuote?.(connectionId),
|
||||
catalog: tableMeta.catalog,
|
||||
database: tableMeta.database,
|
||||
@@ -6547,6 +6548,7 @@ async function applyOrderBySearch() {
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: resolvedDatabaseType.value,
|
||||
driverProfile: props.connectionId ? connectionStore.getConfig(props.connectionId)?.driver_profile : undefined,
|
||||
serverVersion: props.connectionId ? connectionStore.getConfig(props.connectionId)?.database_info?.productVersion : undefined,
|
||||
identifierQuote: connectionStore.connectionIdentifierQuote?.(props.connectionId),
|
||||
catalog: tableMeta.catalog,
|
||||
database: tableMeta.database,
|
||||
@@ -6586,6 +6588,7 @@ async function applyWhereFilter() {
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: resolvedDatabaseType.value,
|
||||
driverProfile: props.connectionId ? connectionStore.getConfig(props.connectionId)?.driver_profile : undefined,
|
||||
serverVersion: props.connectionId ? connectionStore.getConfig(props.connectionId)?.database_info?.productVersion : undefined,
|
||||
identifierQuote: connectionStore.connectionIdentifierQuote?.(props.connectionId),
|
||||
catalog: tableMeta.catalog,
|
||||
database: tableMeta.database,
|
||||
@@ -7851,6 +7854,7 @@ async function syncUserFacingSql() {
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: resolvedDatabaseType.value,
|
||||
driverProfile: config?.driver_profile,
|
||||
serverVersion: config?.database_info?.productVersion,
|
||||
identifierQuote: props.connectionId ? connectionStore.connectionIdentifierQuote?.(props.connectionId) : undefined,
|
||||
catalog: props.tableMeta.catalog,
|
||||
database: props.tableMeta.database,
|
||||
@@ -11341,6 +11345,7 @@ async function loadForeignKeyDisplayLabels() {
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: resolvedDatabaseType.value,
|
||||
driverProfile: connectionStore.getConfig(props.connectionId!)?.driver_profile,
|
||||
serverVersion: connectionStore.getConfig(props.connectionId!)?.database_info?.productVersion,
|
||||
identifierQuote: connectionStore.connectionIdentifierQuote?.(props.connectionId),
|
||||
catalog: props.tableMeta?.catalog,
|
||||
database: props.database,
|
||||
|
||||
@@ -1692,6 +1692,7 @@ async function openNewQuery(row: ObjectBrowserRow) {
|
||||
await buildTableSelectSql({
|
||||
databaseType: effectiveDatabaseType.value,
|
||||
driverProfile: props.connection.driver_profile,
|
||||
serverVersion: props.connection.database_info?.productVersion,
|
||||
identifierQuote: connectionStore.connectionIdentifierQuote?.(props.connection.id),
|
||||
catalog: props.catalog,
|
||||
database: props.database,
|
||||
|
||||
+6
@@ -97,4 +97,10 @@ describe("useDataGridEditor save SQL database qualification", () => {
|
||||
await createEditor(false).saveChanges();
|
||||
expect(mocks.prepareDataGridSave.mock.calls[1]![0]).toMatchObject({ includeDatabaseName: false });
|
||||
});
|
||||
|
||||
it("forwards the connected server version so saved statements match the read SQL (#10503)", async () => {
|
||||
mocks.getConfig.mockReturnValue({ database_info: { productVersion: "Neo4j/4.4.44" } });
|
||||
await createEditor(false).saveChanges();
|
||||
expect(mocks.prepareDataGridSave.mock.calls[0]![0]).toMatchObject({ serverVersion: "Neo4j/4.4.44" });
|
||||
});
|
||||
});
|
||||
@@ -17,6 +17,7 @@ const mocks = vi.hoisted(() => ({
|
||||
setErrorResult: vi.fn(),
|
||||
setTableMeta: vi.fn(),
|
||||
updateSql: vi.fn(),
|
||||
databaseInfo: undefined as { productName?: string; productVersion?: string } | undefined,
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/backend/api", () => ({
|
||||
@@ -27,7 +28,7 @@ vi.mock("@/lib/backend/api", () => ({
|
||||
vi.mock("@/stores/connectionStore", () => ({
|
||||
useConnectionStore: () => ({
|
||||
activeConnectionId: "",
|
||||
getConfig: () => ({ id: "connection-1", db_type: mocks.databaseType }),
|
||||
getConfig: () => ({ id: "connection-1", db_type: mocks.databaseType, database_info: mocks.databaseInfo }),
|
||||
ensureConnected: mocks.ensureConnected,
|
||||
connectionIdentifierQuote: () => undefined,
|
||||
metadataGenerationFor: () => 0,
|
||||
@@ -108,6 +109,7 @@ describe("useNavigationTargets openTableTarget", () => {
|
||||
mocks.tabs.length = 0;
|
||||
mocks.databaseType = "postgres";
|
||||
mocks.tableOpenSortMode = "none";
|
||||
mocks.databaseInfo = undefined;
|
||||
mocks.ensureConnected.mockResolvedValue(undefined);
|
||||
mocks.buildTableSelectSql.mockImplementation(async ({ tableName }: { tableName: string }) => `SELECT * FROM ${tableName}`);
|
||||
mocks.executeTabSql.mockResolvedValue(undefined);
|
||||
@@ -130,6 +132,30 @@ describe("useNavigationTargets openTableTarget", () => {
|
||||
expect(mocks.tabs[0]?.orderByInput).toBeUndefined();
|
||||
});
|
||||
|
||||
it("forwards the connected server version to the table SQL builder (#10503)", async () => {
|
||||
mocks.databaseType = "neo4j";
|
||||
mocks.databaseInfo = { productName: "Neo4j", productVersion: "Neo4j/4.4.44" };
|
||||
|
||||
await useNavigationTargets(dialogs).openTableTarget({ connectionId: "connection-1", database: "neo4j", tableName: "users", tableType: "TABLE" });
|
||||
|
||||
expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(expect.objectContaining({ serverVersion: "Neo4j/4.4.44" }));
|
||||
});
|
||||
|
||||
it("reads the server version when the SQL is built, not from the config captured before connect (#10503)", async () => {
|
||||
mocks.databaseType = "neo4j";
|
||||
mocks.databaseInfo = undefined;
|
||||
// The store swaps the config object when the probe lands, so the reference captured before
|
||||
// connect never sees the version.
|
||||
mocks.getColumns.mockImplementation(async () => {
|
||||
mocks.databaseInfo = { productName: "Neo4j", productVersion: "Neo4j/4.4.44" };
|
||||
return [column("id")];
|
||||
});
|
||||
|
||||
await useNavigationTargets(dialogs).openTableTarget({ connectionId: "connection-1", database: "neo4j", tableName: "users", tableType: "TABLE" });
|
||||
|
||||
expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(expect.objectContaining({ serverVersion: "Neo4j/4.4.44" }));
|
||||
});
|
||||
|
||||
it.each(["oracle", "oceanbase-oracle"])("uses the %s physical primary index for default ordering", async (databaseType) => {
|
||||
mocks.databaseType = databaseType;
|
||||
mocks.tableOpenSortMode = "database";
|
||||
|
||||
@@ -122,6 +122,7 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)
|
||||
return buildTableSelectSql({
|
||||
databaseType: effectiveDbType,
|
||||
driverProfile: config?.driver_profile,
|
||||
serverVersion: config?.database_info?.productVersion,
|
||||
identifierQuote: connectionStore.connectionIdentifierQuote?.(tab.connectionId),
|
||||
database: tableMeta?.database,
|
||||
schema: tableMeta?.schema,
|
||||
|
||||
@@ -1592,6 +1592,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
if (!tableMeta.value) return null;
|
||||
return {
|
||||
databaseType: resolvedDatabaseType.value,
|
||||
serverVersion: connectionStore.getConfig(connectionId.value ?? "")?.database_info?.productVersion,
|
||||
identifierQuote: connectionStore.connectionIdentifierQuote?.(connectionId.value),
|
||||
tableMeta: tableMeta.value,
|
||||
columns: result.value.columns,
|
||||
|
||||
@@ -258,6 +258,7 @@ export function useDataGridLargeValues(options: UseDataGridLargeValuesOptions) {
|
||||
if (!visibleLargeValuePreviewActive || generation !== visibleLargeValuePreviewRequestedGeneration || options.result.value !== sourceResult) return;
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: options.databaseType.value,
|
||||
serverVersion: options.getConnectionConfig(options.connectionId.value!)?.database_info?.productVersion,
|
||||
identifierQuote: options.connectionIdentifierQuote(options.connectionId.value),
|
||||
database: tableMeta.database,
|
||||
schema: tableMeta.schema,
|
||||
@@ -426,6 +427,7 @@ export function useDataGridLargeValues(options: UseDataGridLargeValuesOptions) {
|
||||
const selectedColumns = [...new Set([...tableMeta.primaryKeys, sourceColumn])];
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: options.databaseType.value,
|
||||
serverVersion: options.getConnectionConfig(options.connectionId.value!)?.database_info?.productVersion,
|
||||
identifierQuote: options.connectionIdentifierQuote(options.connectionId.value),
|
||||
database: tableMeta.database,
|
||||
schema: tableMeta.schema,
|
||||
|
||||
@@ -147,6 +147,7 @@ async function openTableTarget(target: NavigationTarget, options: { tableInfoTab
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: effectiveDbType,
|
||||
driverProfile: config.driver_profile,
|
||||
serverVersion: connectionStore.getConfig(target.connectionId)?.database_info?.productVersion,
|
||||
identifierQuote,
|
||||
schema: tableSchema,
|
||||
catalog: target.catalog,
|
||||
@@ -204,6 +205,7 @@ async function openTableTarget(target: NavigationTarget, options: { tableInfoTab
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: effectiveDbType,
|
||||
driverProfile: config.driver_profile,
|
||||
serverVersion: connectionStore.getConfig(target.connectionId)?.database_info?.productVersion,
|
||||
identifierQuote,
|
||||
schema: tableSchema,
|
||||
catalog: target.catalog,
|
||||
@@ -255,6 +257,7 @@ async function openTableTarget(target: NavigationTarget, options: { tableInfoTab
|
||||
const emptySql = await buildTableSelectSql({
|
||||
databaseType: effectiveDbType,
|
||||
driverProfile: config.driver_profile,
|
||||
serverVersion: connectionStore.getConfig(target.connectionId)?.database_info?.productVersion,
|
||||
identifierQuote,
|
||||
schema: tableSchema,
|
||||
catalog: target.catalog,
|
||||
@@ -302,6 +305,7 @@ async function openTableTarget(target: NavigationTarget, options: { tableInfoTab
|
||||
const newSql = await buildTableSelectSql({
|
||||
databaseType: effectiveDbType,
|
||||
driverProfile: config.driver_profile,
|
||||
serverVersion: connectionStore.getConfig(target.connectionId)?.database_info?.productVersion,
|
||||
identifierQuote,
|
||||
schema: tableSchema,
|
||||
catalog: target.catalog,
|
||||
|
||||
@@ -375,6 +375,7 @@ export function useSidebarDataOpenRuntime() {
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: effectiveDbType,
|
||||
driverProfile: config?.driver_profile,
|
||||
serverVersion: connectionStore.getConfig(node.connectionId)?.database_info?.productVersion,
|
||||
identifierQuote: connectionStore.connectionIdentifierQuote?.(node.connectionId),
|
||||
schema: tableSchema,
|
||||
database: node.database,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { joinedRowChanges, type JoinedWriteSource } from "../../dataGrid/joinedRowChanges";
|
||||
import { joinedRowChanges, joinedSaveOptions, type JoinedWriteSource } from "../../dataGrid/joinedRowChanges";
|
||||
|
||||
const sources: JoinedWriteSource[] = [
|
||||
{ tableKey: "users", primaryKeys: ["id"], sourceColumns: ["id", "name", undefined, undefined] },
|
||||
@@ -79,3 +79,22 @@ describe("joined row updates", () => {
|
||||
).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("joined save options", () => {
|
||||
it("keeps the connected server version so saved rows are addressed like the rows that were read", () => {
|
||||
const options = joinedSaveOptions([{ tableMeta: { tableName: "events", primaryKeys: ["id"] }, sourceColumns: ["id", "name"] }], {
|
||||
databaseType: "neo4j",
|
||||
serverVersion: "Neo4j/4.4.44",
|
||||
identifierQuote: "`",
|
||||
includeDatabaseName: false,
|
||||
columns: ["id", "name"],
|
||||
rows: [[1, "user"]],
|
||||
dirtyRows: new Map([[0, new Map([[1, "renamed"]])]]),
|
||||
newRows: [],
|
||||
deletedRows: new Set(),
|
||||
});
|
||||
expect(options).toHaveLength(1);
|
||||
expect(options[0]!.serverVersion).toBe("Neo4j/4.4.44");
|
||||
expect(options[0]!.databaseType).toBe("neo4j");
|
||||
});
|
||||
});
|
||||
@@ -25,6 +25,9 @@ export interface DataGridColumnInfo {
|
||||
|
||||
export interface DataGridSaveStatementOptions {
|
||||
databaseType?: DatabaseType;
|
||||
/** Server version reported by the connection (see `BuildTableSelectSqlOptions.serverVersion`).
|
||||
* The saved statements must address rows the same way the grid read them. */
|
||||
serverVersion?: string;
|
||||
identifierQuote?: string;
|
||||
tableMeta: DataGridTableMeta;
|
||||
columns: string[];
|
||||
|
||||
@@ -9,7 +9,7 @@ export interface JoinedSaveTarget {
|
||||
/** Feed per-source changes through the existing SQL builder, including undo SQL. */
|
||||
export function joinedSaveOptions(
|
||||
targets: JoinedSaveTarget[],
|
||||
options: Pick<DataGridSaveStatementOptions, "databaseType" | "identifierQuote" | "columns" | "includeDatabaseName"> & {
|
||||
options: Pick<DataGridSaveStatementOptions, "databaseType" | "serverVersion" | "identifierQuote" | "columns" | "includeDatabaseName"> & {
|
||||
rows: CellValue[][];
|
||||
dirtyRows: Map<number, Map<number, CellValue>>;
|
||||
newRows: CellValue[][];
|
||||
@@ -24,6 +24,7 @@ export function joinedSaveOptions(
|
||||
}));
|
||||
return joinedRowChanges(sources, options.rows, options.dirtyRows).map((update) => ({
|
||||
databaseType: options.databaseType,
|
||||
serverVersion: options.serverVersion,
|
||||
identifierQuote: options.identifierQuote,
|
||||
columns: options.columns,
|
||||
tableMeta: targets[update.sourceIndex]!.tableMeta,
|
||||
|
||||
@@ -13,6 +13,10 @@ import type { SqlSemanticToken } from "@/lib/sql/semantic/types";
|
||||
export interface BuildTableSelectSqlOptions {
|
||||
databaseType?: DatabaseType;
|
||||
driverProfile?: string;
|
||||
/** Server version reported by the connection (for example `Neo4j/4.4.44`). Engines that
|
||||
* renamed a built-in function across releases (Neo4j below 5 uses `id()` where 5+ uses
|
||||
* `elementId()`) need it to generate SQL the connected server understands. */
|
||||
serverVersion?: string;
|
||||
identifierQuote?: string;
|
||||
schema?: string;
|
||||
tableName: string;
|
||||
|
||||
@@ -4842,6 +4842,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const sql = await buildTableSelectSql({
|
||||
databaseType: effectiveDbType,
|
||||
driverProfile: conn?.driver_profile,
|
||||
serverVersion: conn?.database_info?.productVersion,
|
||||
identifierQuote,
|
||||
database: tableMeta.database,
|
||||
schema: tableMeta.schema,
|
||||
@@ -8962,6 +8963,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const sql = await api.buildTableSelectSql({
|
||||
databaseType: effectiveDbType,
|
||||
driverProfile: conn?.driver_profile,
|
||||
serverVersion: conn?.database_info?.productVersion,
|
||||
identifierQuote,
|
||||
database: tableMeta.database,
|
||||
schema: tableMeta.schema,
|
||||
|
||||
Reference in new issue
Block a user