mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
Merge pull request #519 from bartlomiej-korpus/issue-512-fix
fix issue 512
This commit is contained in:
commit
3fdd296a87
@ -1409,7 +1409,7 @@ export class QueryBuilder<Entity> {
|
||||
return object;
|
||||
}, {} as ObjectLiteral);
|
||||
this.setParameters(params);
|
||||
return "UPDATE " + tableName + " " + (aliasName ? ea(aliasName) : "") + " SET " + updateSet;
|
||||
return "UPDATE " + this.escapeTable(tableName) + " " + (aliasName ? ea(aliasName) : "") + " SET " + updateSet;
|
||||
}
|
||||
|
||||
throw new Error("No query builder type is specified.");
|
||||
|
||||
17
test/github-issues/512/entity/Post.ts
Normal file
17
test/github-issues/512/entity/Post.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import {Entity} from "../../../../src/decorator/entity/Entity";
|
||||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn";
|
||||
import {Column} from "../../../../src/decorator/columns/Column";
|
||||
|
||||
@Entity("Posts")
|
||||
export class Post {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
title: string;
|
||||
|
||||
@Column("date")
|
||||
date: string;
|
||||
|
||||
}
|
||||
30
test/github-issues/512/issue-512.ts
Normal file
30
test/github-issues/512/issue-512.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import "reflect-metadata";
|
||||
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
|
||||
import {Connection} from "../../../src/connection/Connection";
|
||||
import {Post} from "./entity/Post";
|
||||
import {expect} from "chai";
|
||||
|
||||
describe("github issues > #512 Table name escaping in UPDATE in QueryBuilder", () => {
|
||||
|
||||
let connections: Connection[];
|
||||
before(async () => connections = await createTestingConnections({
|
||||
entities: [__dirname + "/entity/*{.js,.ts}"],
|
||||
schemaCreate: true,
|
||||
dropSchemaOnConnection: true,
|
||||
}));
|
||||
beforeEach(() => reloadTestingDatabases(connections));
|
||||
after(() => closeTestingConnections(connections));
|
||||
|
||||
it("should escape table name using driver's escape function in UPDATE", () => Promise.all(connections.map(async connection => {
|
||||
const driver = connection.driver;
|
||||
const queryBuilder = connection.entityManager.createQueryBuilder(Post, "post");
|
||||
const query = queryBuilder
|
||||
.update({
|
||||
title: "Some Title",
|
||||
})
|
||||
.getSql();
|
||||
|
||||
return query.should.contain(driver.escapeTableName("Posts"));
|
||||
})));
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user