@@ -62,6 +62,8 @@ type PrepareExec struct {
6262 // If it's generated from executing "prepare stmt from '...'", the process is parse -> plan -> executor
6363 // If it's generated from the prepare protocol, the process is session.PrepareStmt -> NewPrepareExec
6464 // They both generate a PrepareExec struct, but the second case needs to reset the statement context while the first already do that.
65+ // Also, the second case need charset_client param since SQL is directly passed from clients.
66+ // While the text-prepare already transformed charset by parser.
6567 needReset bool
6668}
6769
@@ -87,23 +89,28 @@ func (e *PrepareExec) Next(ctx context.Context, _ *chunk.Chunk) error {
8789 return nil
8890 }
8991 }
90- charset , collation := vars .GetCharsetInfo ()
9192 var (
9293 stmts []ast.StmtNode
9394 err error
9495 )
96+ var params []parser.ParseParam
97+ if e .needReset {
98+ params = vars .GetParseParams ()
99+ } else {
100+ var paramsArr [2 ]parser.ParseParam
101+ charset , collation := vars .GetCharsetInfo ()
102+ paramsArr [0 ] = parser .CharsetConnection (charset )
103+ paramsArr [1 ] = parser .CollationConnection (collation )
104+ params = paramsArr [:]
105+ }
95106 if sqlParser , ok := e .Ctx ().(sqlexec.SQLParser ); ok {
96107 // FIXME: ok... yet another parse API, may need some api interface clean.
97- stmts , _ , err = sqlParser .ParseSQL (ctx , e .sqlText ,
98- parser .CharsetConnection (charset ),
99- parser .CollationConnection (collation ))
108+ stmts , _ , err = sqlParser .ParseSQL (ctx , e .sqlText , params ... )
100109 } else {
101110 p := parser .New ()
102111 p .SetParserConfig (vars .BuildParserConfig ())
103112 var warns []error
104- stmts , warns , err = p .ParseSQL (e .sqlText ,
105- parser .CharsetConnection (charset ),
106- parser .CollationConnection (collation ))
113+ stmts , warns , err = p .ParseSQL (e .sqlText , params ... )
107114 for _ , warn := range warns {
108115 e .Ctx ().GetSessionVars ().StmtCtx .AppendWarning (util .SyntaxWarn (warn ))
109116 }
0 commit comments