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

Do not rewrite last_insert_id function calls with arguments. #12997

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions go/vt/sqlparser/ast_rewriting.go
Expand Up @@ -571,10 +571,17 @@ func (er *astRewriter) funcRewrite(cursor *Cursor, node *FuncExpr) {
if !found || (bindVar == DBVarName && !er.shouldRewriteDatabaseFunc) {
return
}

// Don't rewrite `last_insert_id` function call if an argument is given
if len(node.Exprs) > 0 && node.Name.Lowered() == "last_insert_id" {
return
}

if len(node.Exprs) > 0 {
er.err = vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "Argument to %s() not supported", node.Name.Lowered())
return
}

cursor.Replace(bindVarExpression(bindVar))
er.bindVars.AddFuncResult(bindVar)
}
Expand Down
3 changes: 3 additions & 0 deletions go/vt/sqlparser/ast_rewriting_test.go
Expand Up @@ -67,6 +67,9 @@ func TestRewrites(in *testing.T) {
in: "SELECT @@enable_system_settings",
expected: "SELECT :__vtenable_system_settings as `@@enable_system_settings`",
sessionEnableSystemSettings: true,
}, {
in: "SELECT last_insert_id(10)",
expected: "SELECT last_insert_id(10)",
}, {
in: "SELECT last_insert_id()",
expected: "SELECT :__lastInsertId as `last_insert_id()`",
Expand Down