@@ -62,6 +62,8 @@ type PrepareExec struct {
62
62
// If it's generated from executing "prepare stmt from '...'", the process is parse -> plan -> executor
63
63
// If it's generated from the prepare protocol, the process is session.PrepareStmt -> NewPrepareExec
64
64
// 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.
65
67
needReset bool
66
68
}
67
69
@@ -87,23 +89,28 @@ func (e *PrepareExec) Next(ctx context.Context, _ *chunk.Chunk) error {
87
89
return nil
88
90
}
89
91
}
90
- charset , collation := vars .GetCharsetInfo ()
91
92
var (
92
93
stmts []ast.StmtNode
93
94
err error
94
95
)
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
+ }
95
106
if sqlParser , ok := e .Ctx ().(sqlexec.SQLParser ); ok {
96
107
// 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 ... )
100
109
} else {
101
110
p := parser .New ()
102
111
p .SetParserConfig (vars .BuildParserConfig ())
103
112
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 ... )
107
114
for _ , warn := range warns {
108
115
e .Ctx ().GetSessionVars ().StmtCtx .AppendWarning (util .SyntaxWarn (warn ))
109
116
}
0 commit comments