Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: don't include quotes in parsed strings #17799

Merged
merged 1 commit into from
Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/ccl/acceptanceccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func BenchmarkRestoreBig(b *testing.B) {
b.Fatal(err)
}

dbName := fmt.Sprintf("bank%d", b.N)
dbName := fmt.Sprintf("bank %d", b.N)
r.Exec(fmt.Sprintf("CREATE DATABASE %s", dbName))

b.ResetTimer()
Expand Down
10 changes: 5 additions & 5 deletions pkg/ccl/sqlccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ func TestBackupRestoreIncremental(t *testing.T) {
// the greatest key in the diff is less than the previous backups.
sqlDB.Exec(`INSERT INTO data.bank VALUES (0, -1, 'final')`)
checksums = append(checksums, checksumBankPayload(t, sqlDB))
finalBackupDir := filepath.Join(dir, "final")
finalBackupDir := filepath.Join(dir, "final layer")
sqlDB.Exec(fmt.Sprintf(`BACKUP TABLE data.bank TO '%s' %s`,
finalBackupDir, fmt.Sprintf(` INCREMENTAL FROM %s`, strings.Join(backupDirs, `,`)),
))
Expand Down Expand Up @@ -1837,18 +1837,18 @@ func TestRestoreInto(t *testing.T) {

sqlDB.Exec(`BACKUP DATABASE data TO $1`, dir)

restoreStmt := fmt.Sprintf(`RESTORE data.bank FROM '%s' WITH OPTIONS ('into_db'='data2')`, dir)
restoreStmt := fmt.Sprintf(`RESTORE data.bank FROM '%s' WITH into_db = 'data 2'`, dir)

_, err := sqlDB.DB.Exec(restoreStmt)
if !testutils.IsError(err, "a database named \"data2\" needs to exist") {
if !testutils.IsError(err, "a database named \"data 2\" needs to exist") {
t.Fatal(err)
}

sqlDB.Exec(`CREATE DATABASE data2`)
sqlDB.Exec(`CREATE DATABASE "data 2"`)
sqlDB.Exec(restoreStmt)

expected := sqlDB.QueryStr(`SELECT * FROM data.bank`)
sqlDB.CheckQueryResults(`SELECT * FROM data2.bank`, expected)
sqlDB.CheckQueryResults(`SELECT * FROM "data 2".bank`, expected)
}

func TestBackupRestorePermissions(t *testing.T) {
Expand Down
19 changes: 16 additions & 3 deletions pkg/sql/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/envutil"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/pkg/errors"
"golang.org/x/net/context"
)

Expand Down Expand Up @@ -342,7 +343,11 @@ func (p *planner) TypeAsString(e parser.Expr, op string) (func() (string, error)
if err != nil {
return "", err
}
return parser.AsStringWithFlags(d, parser.FmtBareStrings), nil
str, ok := d.(*parser.DString)
if !ok {
return "", errors.Errorf("failed to cast %T to string", d)
}
return string(*str), nil
}
return fn, nil
}
Expand Down Expand Up @@ -377,7 +382,11 @@ func (p *planner) TypeAsStringOpts(
if err != nil {
return nil, err
}
res[name] = parser.AsStringWithFlags(d, parser.FmtBareStrings)
str, ok := d.(*parser.DString)
if !ok {
return res, errors.Errorf("failed to cast %T to string", d)
}
res[name] = string(*str)
}
return res, nil
}
Expand Down Expand Up @@ -405,7 +414,11 @@ func (p *planner) TypeAsStringArray(
if err != nil {
return nil, err
}
strs[i] = parser.AsStringWithFlags(d, parser.FmtBareStrings)
str, ok := d.(*parser.DString)
if !ok {
return strs, errors.Errorf("failed to cast %T to string", d)
}
strs[i] = string(*str)
}
return strs, nil
}
Expand Down