Skip to content

Commit 1464326

Browse files
committed
fix(mysql-driver): Special characters in database name for readOnly database lead to Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
1 parent 862a5e9 commit 1464326

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/cubejs-mysql-driver/driver/MySqlDriver.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ class MySqlDriver extends BaseDriver {
143143
const tableName = crypto.randomBytes(10).toString('hex');
144144
const columns = await this.withConnection(async db => {
145145
await this.setTimeZone(db);
146-
await db.execute(`CREATE TEMPORARY TABLE ${this.config.database}.t_${tableName} AS ${query} LIMIT 0`, values);
147-
const result = await db.execute(`DESCRIBE ${this.config.database}.t_${tableName}`);
148-
await db.execute(`DROP TEMPORARY TABLE ${this.config.database}.t_${tableName}`);
146+
await db.execute(`CREATE TEMPORARY TABLE \`${this.config.database}\`.t_${tableName} AS ${query} LIMIT 0`, values);
147+
const result = await db.execute(`DESCRIBE \`${this.config.database}\`.t_${tableName}`);
148+
await db.execute(`DROP TEMPORARY TABLE \`${this.config.database}\`.t_${tableName}`);
149149
return result;
150150
});
151151

packages/cubejs-mysql-driver/test/MySqlDriver.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ describe('MySqlDriver', () => {
2020
host: 'localhost',
2121
user: 'root',
2222
password: process.env.TEST_DB_PASSWORD || "Test1test",
23-
port: container && container.getMappedPort(3306) || 3306
23+
port: container && container.getMappedPort(3306) || 3306,
24+
database: 'mysql'
2425
});
2526
await mySqlDriver.createSchemaIfNotExists('test');
2627
await mySqlDriver.query('DROP SCHEMA test');
@@ -40,6 +41,8 @@ describe('MySqlDriver', () => {
4041
});
4142
expect(JSON.parse(JSON.stringify(await mySqlDriver.query('select * from test.wrong_value'))))
4243
.toStrictEqual([{ value: "Tekirdağ" }]);
44+
expect(JSON.parse(JSON.stringify((await mySqlDriver.downloadQueryResults('select * from test.wrong_value')).rows)))
45+
.toStrictEqual([{ value: "Tekirdağ" }]);
4346
});
4447

4548
test('boolean field', async () => {

0 commit comments

Comments
 (0)