Escape the given tablename in the engine_table_reader (#2958)

This commit is contained in:
Vinai Rachakonda
2022-03-11 11:15:45 -08:00
committed by GitHub
parent 26dbd64c59
commit 99b0028b6d
3 changed files with 9 additions and 5 deletions
@@ -61,7 +61,7 @@ func NewSqlEngineReader(ctx context.Context, dEnv *env.DoltEnv, tableName string
return nil, err
}
sch, iter, err := se.Query(sqlCtx, fmt.Sprintf("SELECT * FROM %s", tableName))
sch, iter, err := se.Query(sqlCtx, fmt.Sprintf("SELECT * FROM `%s`", tableName))
if err != nil {
return nil, err
}
@@ -267,7 +267,7 @@ func (s *SqlEngineTableWriter) TableSchema() sql.PrimaryKeySchema {
// forceDropTableIfNeeded drop the given table in case the -f parameter is passed.
func (s *SqlEngineTableWriter) forceDropTableIfNeeded() error {
if s.force {
_, _, err := s.se.Query(s.sqlCtx, fmt.Sprintf("DROP TABLE IF EXISTS %s", s.tableName))
_, _, err := s.se.Query(s.sqlCtx, fmt.Sprintf("DROP TABLE IF EXISTS `%s`", s.tableName))
return err
}
@@ -280,7 +280,7 @@ func (s *SqlEngineTableWriter) createOrEmptyTableIfNeeded() error {
case CreateOp:
return s.createTable()
case ReplaceOp:
_, _, err := s.se.Query(s.sqlCtx, fmt.Sprintf("TRUNCATE TABLE %s", s.tableName))
_, _, err := s.se.Query(s.sqlCtx, fmt.Sprintf("TRUNCATE TABLE `%s`", s.tableName))
return err
default:
return nil
@@ -719,7 +719,7 @@ DELIM
@test "import-update-tables: import supports tables with dashes in the name" {
cat <<DELIM > file.csv
pk, c1
pk,c1
0,0
DELIM
@@ -727,7 +727,11 @@ DELIM
[ $status -eq 0 ]
[[ "$output" =~ "Import completed successfully." ]] || false
skip "This fails right now with syntax error at position 20 near 'this'"
run dolt table import -u this-is-a-table file.csv
[ $status -eq 0 ]
run dolt sql -r csv -q "SELECT * FROM \`this-is-a-table\`"
[ $status -eq 0 ]
[[ "$output" =~ "pk,c1" ]] || false
[[ "$output" =~ "0,0" ]] || false
}