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

Support uppercase user defined variables #6225

Merged
merged 2 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions go/test/endtoend/vtgate/setstatement/udv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ func TestSetUDV(t *testing.T) {
query: "set @foo = 'abc', @bar = 42, @baz = 30.5, @tablet = concat('foo','bar')",
expectedRows: "", rowsAffected: 0,
}, {
query: "select @foo, @bar, @baz, @tablet",
expectedRows: `[[VARBINARY("abc") INT64(42) FLOAT64(30.5) VARBINARY("foobar")]]`, rowsAffected: 1,
query: "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */",
expectedRows: "", rowsAffected: 0,
}, {
query: "select @foo, @bar, @baz, @tablet, @OLD_SQL_MODE",
expectedRows: `[[VARBINARY("abc") INT64(42) FLOAT64(30.5) VARBINARY("foobar") VARBINARY("ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION")]]`, rowsAffected: 1,
}, {
query: "insert into test(id, val1, val2, val3) values(1, @foo, null, null), (2, null, @bar, null), (3, null, null, @baz)",
expectedRows: ``, rowsAffected: 3,
Expand Down
4 changes: 3 additions & 1 deletion go/vt/sqlparser/expression_rewriting.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package sqlparser

import (
"strings"

"vitess.io/vitess/go/vt/log"
querypb "vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/proto/vtrpc"
Expand Down Expand Up @@ -155,7 +157,7 @@ func (er *expressionRewriter) goingDown(cursor *Cursor) bool {
er.funcRewrite(cursor, node)
case *ColName:
if node.Name.at == SingleAt {
cursor.Replace(bindVarExpression(UserDefinedVariableName + node.Name.CompliantName()))
cursor.Replace(bindVarExpression(UserDefinedVariableName + strings.ToLower(node.Name.CompliantName())))
er.needBindVarFor(UserDefinedVariableName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/plan_executor_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestPlanExecutorSetUDV(t *testing.T) {
out *vtgatepb.Session
err string
}{{
in: "set @foo = 'bar'",
in: "set @FOO = 'bar'",
out: &vtgatepb.Session{UserDefinedVariables: createMap([]string{"foo"}, []interface{}{"bar"}), Autocommit: true},
}, {
in: "set @foo = 2",
Expand Down