pingcap / pingcap/tidb

Support restoring sql with comments

Open
#35,962 1 comment 2 reactions 0 assignees View on GitHub
type/feature-request
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

```go
func RestoreCTX() (*format.RestoreCtx, *strings.Builder) {
var s strings.Builder
return format.NewRestoreCtx(format.RestoreStringSingleQuotes|
format.RestoreKeyWordLowercase|
format.RestoreNameBackQuotes|
format.RestoreTiDBSpecialComment, &s), &s
}

func TestComment(t *testing.T) {
tcs := []string{
`SELECT /* this is an in-line comment */ 1 + 1`,
}
for _, tc := range tcs {
node, err := Parse(tc, "", "")
if err != nil {
t.Log(err)
return
}
ctx, s := RestoreCTX()
if err := node.Restore(ctx); err != nil {
t.Log(err)
return
}
t.Log(s.String())
}
}
```

I expect to print `select /* this is an in-line comment */ 1 + 1`, but it prints `select 1+1`。

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.