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

[parser] RestoreStringWithoutCharset and RestoreStringWithoutDefaultCharset flags not work #37175

Closed
chenlujjj opened this issue Aug 17, 2022 · 1 comment · Fixed by #37248
Closed
Assignees
Labels
severity/minor sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@chenlujjj
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

import (
	"fmt"
	"os"
	"strings"

	"github.com/pingcap/tidb/parser"
	"github.com/pingcap/tidb/parser/ast"
	"github.com/pingcap/tidb/parser/format"
	_ "github.com/pingcap/tidb/parser/test_driver"
)

func main() {
	rawSql := "SELECT 'a'"
	restoreCtx := format.NewRestoreCtx(format.RestoreStringSingleQuotes|format.RestoreStringWithoutCharset|format.RestoreStringWithoutDefaultCharset, os.Stdout)

	astNode, err := parse(rawSql)
	if err != nil {
		panic(err)
	}

	err = (*astNode).Restore(restoreCtx)
	if err != nil {
		panic(err)
	}
}


func parse(sql string) (*ast.StmtNode, error) {
	p := parser.New()

	stmtNodes, _, err := p.Parse(sql, "", "")
	if err != nil {
		return nil, err
	}
	return &stmtNodes[0], nil
}

2. What did you expect to see? (Required)

Output: SELECT 'a'

3. What did you see instead (Required)

SELECT _utf8mb4'a'

4. What is your TiDB version? (Required)

@Defined2014
Copy link
Contributor

Defined2014 commented Aug 19, 2022

The test_driver file only be used in UT, so change it to severity/minor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/minor sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
3 participants