From 632ff18acf3aa9fc6bc7fd72c25e62ac9611b827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Qu=C3=A9r=C3=A9?= Date: Mon, 20 Nov 2023 17:56:26 +0100 Subject: [PATCH] fix(database/clickhouse): properly escape database and table name --- database/clickhouse/clickhouse.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/database/clickhouse/clickhouse.go b/database/clickhouse/clickhouse.go index ee1ac209f..8a51fc1d9 100644 --- a/database/clickhouse/clickhouse.go +++ b/database/clickhouse/clickhouse.go @@ -192,7 +192,7 @@ func (ch *ClickHouse) SetVersion(version int, dirty bool) error { return err } - query := "INSERT INTO " + ch.config.MigrationsTable + " (version, dirty, sequence) VALUES (?, ?, ?)" + query := "INSERT INTO `" + ch.config.MigrationsTable + "` (version, dirty, sequence) VALUES (?, ?, ?)" if _, err := tx.Exec(query, version, bool(dirty), time.Now().UnixNano()); err != nil { return &database.Error{OrigErr: err, Query: []byte(query)} } @@ -220,7 +220,7 @@ func (ch *ClickHouse) ensureVersionTable() (err error) { var ( table string - query = "SHOW TABLES FROM " + ch.config.DatabaseName + " LIKE '" + ch.config.MigrationsTable + "'" + query = "SHOW TABLES FROM `" + ch.config.DatabaseName + "` LIKE '" + ch.config.MigrationsTable + "'" ) // check if migration table exists if err := ch.conn.QueryRow(query).Scan(&table); err != nil { @@ -259,7 +259,7 @@ func (ch *ClickHouse) ensureVersionTable() (err error) { } func (ch *ClickHouse) Drop() (err error) { - query := "SHOW TABLES FROM " + ch.config.DatabaseName + query := "SHOW TABLES FROM `" + ch.config.DatabaseName + "`" tables, err := ch.conn.Query(query) if err != nil { @@ -277,7 +277,7 @@ func (ch *ClickHouse) Drop() (err error) { return err } - query = "DROP TABLE IF EXISTS " + ch.config.DatabaseName + "." + table + query = "DROP TABLE IF EXISTS `" + ch.config.DatabaseName + "`.`" + table + "`" if _, err := ch.conn.Exec(query); err != nil { return &database.Error{OrigErr: err, Query: []byte(query)}