From 49eef8529efdce144a66af0ea8ebc71e7ffc5af9 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Tue, 13 Jun 2023 14:49:58 +0530 Subject: [PATCH 1/2] feat: refactor and add a comment Signed-off-by: Manan Gupta --- go/vt/sidecardb/sidecardb.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/go/vt/sidecardb/sidecardb.go b/go/vt/sidecardb/sidecardb.go index e03dd76fe0b..78f4bae2fa2 100644 --- a/go/vt/sidecardb/sidecardb.go +++ b/go/vt/sidecardb/sidecardb.go @@ -368,7 +368,11 @@ func (si *schemaInit) setCurrentDatabase(dbName string) error { func (si *schemaInit) getCurrentSchema(tableName string) (string, error) { var currentTableSchema string - rs, err := si.exec(si.ctx, sqlparser.BuildParsedQuery(showCreateTableQuery, GetIdentifier(), sqlparser.String(sqlparser.NewIdentifierCS(tableName))).Query, 1, false) + // We escape the tableName because it can be a keyword. + // Converting the tableName to a case-sensitive identifier and printing it out using the + // sqlparser package, ensures that the table name is escaped with backticks if required. + escapedTableName := sqlparser.String(sqlparser.NewIdentifierCS(tableName)) + rs, err := si.exec(si.ctx, sqlparser.BuildParsedQuery(showCreateTableQuery, GetIdentifier(), escapedTableName).Query, 1, false) if err != nil { if sqlErr, ok := err.(*mysql.SQLError); ok && sqlErr.Number() == mysql.ERNoSuchTable { // table does not exist in the sidecar database From 25101bb54bd509d760b8c537bcaa417496f773f9 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Wed, 14 Jun 2023 11:00:31 +0530 Subject: [PATCH 2/2] feat: address review comments Signed-off-by: Manan Gupta --- go/vt/sidecardb/sidecardb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/sidecardb/sidecardb.go b/go/vt/sidecardb/sidecardb.go index 78f4bae2fa2..df87dab2288 100644 --- a/go/vt/sidecardb/sidecardb.go +++ b/go/vt/sidecardb/sidecardb.go @@ -369,7 +369,7 @@ func (si *schemaInit) getCurrentSchema(tableName string) (string, error) { var currentTableSchema string // We escape the tableName because it can be a keyword. - // Converting the tableName to a case-sensitive identifier and printing it out using the + // Converting the tableName to a case-sensitive identifier and converting back to a string using the // sqlparser package, ensures that the table name is escaped with backticks if required. escapedTableName := sqlparser.String(sqlparser.NewIdentifierCS(tableName)) rs, err := si.exec(si.ctx, sqlparser.BuildParsedQuery(showCreateTableQuery, GetIdentifier(), escapedTableName).Query, 1, false)