fix(sql): honor include-database-name setting for schema-aware engines
This commit is contained in:
4 files changed
+131
-20
No files matched your search
+58
-9
@@ -13,11 +13,7 @@ function col(overrides: Partial<ColumnInfo> & { name: string; data_type: string
|
||||
};
|
||||
}
|
||||
|
||||
const columns: ColumnInfo[] = [
|
||||
col({ name: "id", data_type: "integer", is_primary_key: true, extra: "auto_increment" }),
|
||||
col({ name: "name", data_type: "varchar" }),
|
||||
col({ name: "created_at", data_type: "timestamp" }),
|
||||
];
|
||||
const columns: ColumnInfo[] = [col({ name: "id", data_type: "integer", is_primary_key: true, extra: "auto_increment" }), col({ name: "name", data_type: "varchar" }), col({ name: "created_at", data_type: "timestamp" })];
|
||||
|
||||
test("builds SELECT template with explicit table columns", () => {
|
||||
assert.equal(
|
||||
@@ -87,10 +83,7 @@ test("builds GaussDB M templates with the detected backtick identifier mode", ()
|
||||
identifierQuote: "`",
|
||||
schema: "app_schema",
|
||||
tableName: "order",
|
||||
columns: [
|
||||
col({ name: "id", data_type: "integer", is_primary_key: true }),
|
||||
col({ name: "DisplayName", data_type: "varchar" }),
|
||||
],
|
||||
columns: [col({ name: "id", data_type: "integer", is_primary_key: true }), col({ name: "DisplayName", data_type: "varchar" })],
|
||||
};
|
||||
|
||||
assert.equal(buildTableSelectTemplate(options), "SELECT id, `DisplayName`\nFROM app_schema.`order`;");
|
||||
@@ -114,3 +107,59 @@ test("preserves the Phoenix schema in all SQL templates", () => {
|
||||
assert.equal(buildTableUpdateTemplate(options), `UPDATE "APP"."USERS"\nSET "NAME" = 'NAME_value'\nWHERE "ID" = 0;`);
|
||||
assert.equal(buildTableDeleteTemplate(options), `DELETE FROM "APP"."USERS"\nWHERE "ID" = 0;`);
|
||||
});
|
||||
|
||||
test("respects includeDatabaseName=false for schema-aware engines (#9110)", () => {
|
||||
// Oracle's schema qualifier is the "database name" on schema-aware engines;
|
||||
// turning the setting off must drop it, not just on MySQL-style engines.
|
||||
const sql = buildTableSelectTemplate({
|
||||
databaseType: "oracle",
|
||||
identifierQuote: `"`,
|
||||
schema: "SYSTEM",
|
||||
includeDatabaseName: false,
|
||||
quoteIdentifiers: false,
|
||||
tableName: "AQ$_INTERNET_AGENTS",
|
||||
columns: [{ name: "ID" }],
|
||||
} as Parameters<typeof buildTableSelectTemplate>[0]);
|
||||
assert.equal(sql, "SELECT ID\nFROM AQ$_INTERNET_AGENTS;");
|
||||
});
|
||||
|
||||
test("respects includeDatabaseName=false on quoted-identifier connections (#9110)", () => {
|
||||
// The identifierQuote early-return paths (JDBC/agent connections) must
|
||||
// honor the toggle too, not just the native schema-aware branch.
|
||||
const base = {
|
||||
databaseType: "postgres" as const,
|
||||
identifierQuote: '"',
|
||||
schema: "public",
|
||||
tableName: "Users",
|
||||
columns,
|
||||
};
|
||||
assert.equal(buildTableSelectTemplate(base), 'SELECT id, name, created_at\nFROM public."Users";');
|
||||
assert.equal(buildTableSelectTemplate({ ...base, includeDatabaseName: false }), 'SELECT id, name, created_at\nFROM "Users";');
|
||||
});
|
||||
|
||||
test("keeps the schema qualifier for databases that require it and the default (both settings on)", () => {
|
||||
// Default settings: schema stays.
|
||||
const defaultSql = buildTableSelectTemplate({
|
||||
databaseType: "oracle",
|
||||
identifierQuote: `"`,
|
||||
schema: "SYSTEM",
|
||||
includeDatabaseName: true,
|
||||
quoteIdentifiers: true,
|
||||
tableName: "T1",
|
||||
columns: [{ name: "ID" }],
|
||||
} as Parameters<typeof buildTableSelectTemplate>[0]);
|
||||
assert.equal(defaultSql, 'SELECT "ID"\nFROM "SYSTEM"."T1";');
|
||||
});
|
||||
|
||||
test("quoteIdentifiers=false emits bare column names in SELECT templates", () => {
|
||||
const sql = buildTableSelectTemplate({
|
||||
databaseType: "mysql",
|
||||
schema: undefined,
|
||||
database: "shopdb",
|
||||
includeDatabaseName: true,
|
||||
quoteIdentifiers: false,
|
||||
tableName: "orders",
|
||||
columns: [{ name: "id" }, { name: "amount" }],
|
||||
} as Parameters<typeof buildTableSelectTemplate>[0]);
|
||||
assert.equal(sql, "SELECT id, amount\nFROM shopdb.orders;");
|
||||
});
|
||||
Reference in new issue
Block a user