Skip to content

Commit

Permalink
fix(mysql-driver): Special characters in database name for readOnly d…
Browse files Browse the repository at this point in the history
…atabase 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
  • Loading branch information
paveltiunov committed Apr 7, 2020
1 parent 862a5e9 commit 1464326
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/cubejs-mysql-driver/driver/MySqlDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ class MySqlDriver extends BaseDriver {
const tableName = crypto.randomBytes(10).toString('hex');
const columns = await this.withConnection(async db => {
await this.setTimeZone(db);
await db.execute(`CREATE TEMPORARY TABLE ${this.config.database}.t_${tableName} AS ${query} LIMIT 0`, values);
const result = await db.execute(`DESCRIBE ${this.config.database}.t_${tableName}`);
await db.execute(`DROP TEMPORARY TABLE ${this.config.database}.t_${tableName}`);
await db.execute(`CREATE TEMPORARY TABLE \`${this.config.database}\`.t_${tableName} AS ${query} LIMIT 0`, values);
const result = await db.execute(`DESCRIBE \`${this.config.database}\`.t_${tableName}`);
await db.execute(`DROP TEMPORARY TABLE \`${this.config.database}\`.t_${tableName}`);
return result;
});

Expand Down
5 changes: 4 additions & 1 deletion packages/cubejs-mysql-driver/test/MySqlDriver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ describe('MySqlDriver', () => {
host: 'localhost',
user: 'root',
password: process.env.TEST_DB_PASSWORD || "Test1test",
port: container && container.getMappedPort(3306) || 3306
port: container && container.getMappedPort(3306) || 3306,
database: 'mysql'
});
await mySqlDriver.createSchemaIfNotExists('test');
await mySqlDriver.query('DROP SCHEMA test');
Expand All @@ -40,6 +41,8 @@ describe('MySqlDriver', () => {
});
expect(JSON.parse(JSON.stringify(await mySqlDriver.query('select * from test.wrong_value'))))
.toStrictEqual([{ value: "Tekirdağ" }]);
expect(JSON.parse(JSON.stringify((await mySqlDriver.downloadQueryResults('select * from test.wrong_value')).rows)))
.toStrictEqual([{ value: "Tekirdağ" }]);
});

test('boolean field', async () => {
Expand Down

0 comments on commit 1464326

Please sign in to comment.