This commit is contained in:
Umed Khudoiberdiev 2017-07-01 10:43:23 +05:00
parent 4b933867c4
commit 2a64aaf8b6
5 changed files with 78 additions and 2 deletions

View File

@ -615,7 +615,7 @@ export class MysqlQueryRunner implements QueryRunner {
await this.startTransaction();
try {
const disableForeignKeysCheckQuery = `SET FOREIGN_KEY_CHECKS = 0;`;
const dropTablesQuery = `SELECT concat('DROP TABLE IF EXISTS ', table_name, ';') AS query FROM information_schema.tables WHERE table_schema = '${this.dbName}'`;
const dropTablesQuery = `SELECT concat('DROP TABLE IF EXISTS \`', table_name, '\`;') AS query FROM information_schema.tables WHERE table_schema = '${this.dbName}'`;
const enableForeignKeysCheckQuery = `SET FOREIGN_KEY_CHECKS = 1;`;
await this.query(disableForeignKeysCheckQuery);

View File

@ -628,7 +628,7 @@ AND cons.constraint_name = cols.constraint_name AND cons.owner = cols.owner ORDE
await this.startTransaction();
try {
const disableForeignKeysCheckQuery = `SET FOREIGN_KEY_CHECKS = 0;`;
const dropTablesQuery = `SELECT concat('DROP TABLE IF EXISTS ', table_name, ';') AS query FROM information_schema.tables WHERE table_schema = '${this.dbName}'`;
const dropTablesQuery = `SELECT concat('DROP TABLE IF EXISTS "', table_name, '";') AS query FROM information_schema.tables WHERE table_schema = '${this.dbName}'`;
const enableForeignKeysCheckQuery = `SET FOREIGN_KEY_CHECKS = 1;`;
await this.query(disableForeignKeysCheckQuery);

View File

@ -0,0 +1,14 @@
import {Entity} from "../../../../src/decorator/entity/Entity";
import {Column} from "../../../../src/decorator/columns/Column";
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn";
@Entity()
export class Group {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
}

View File

@ -0,0 +1,16 @@
import {Entity} from "../../../../src/decorator/entity/Entity";
import {Column} from "../../../../src/decorator/columns/Column";
import {PrimaryColumn} from "../../../../src/decorator/columns/PrimaryColumn";
import {ManyToOne} from "../../../../src/decorator/relations/ManyToOne";
import {Group} from "./Group";
@Entity()
export class Player {
@PrimaryColumn()
email: string;
@ManyToOne(type => Group)
group: Group;
}

View File

@ -0,0 +1,46 @@
import "reflect-metadata";
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {expect} from "chai";
import {Player} from "./entity/Player";
import {Group} from "./entity/Group";
describe.only("github issues > #401 special keywords should be escaped in join queries", () => {
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 'group' keyword properly", () => Promise.all(connections.map(async connection => {
const group = new Group();
group.name = "about players";
await connection.manager.save(group);
const player = new Player();
player.email = "player@gmail.com";
player.group = group;
await connection.manager.save(player);
const loadedPlayer = await connection
.getRepository(Player)
.createQueryBuilder("player")
.leftJoinAndSelect("player.group", "group")
.where("player.email = :email", { email: "player@gmail.com" })
.getOne();
expect(loadedPlayer).to.be.eql({
email: "player@gmail.com",
group: {
id: 1,
name: "about players"
}
});
})));
});