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

sessionctx: supports set character_set_results = null #7353

Merged
merged 3 commits into from
Aug 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func (s *testSuite) TestSetVar(c *C) {
c.Assert(charset, Equals, "utf8")
c.Assert(collation, Equals, "utf8_bin")

tk.MustExec("set @@character_set_results = NULL")
tk.MustExec("set character_set_results = NULL")
tk.MustQuery("select @@character_set_results").Check(testkit.Rows(""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In MySQL, it's very strange that will return NULL instead of "" in select @@ but return "" in show variable orz

mysql> select @@character_set_results ;
+-------------------------+
| @@character_set_results |
+-------------------------+
| utf8                    |
+-------------------------+
1 row in set (0.00 sec)

mysql> set character_set_results = NULL;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@character_set_results ;
+-------------------------+
| @@character_set_results |
+-------------------------+
| NULL                    |
+-------------------------+
1 row in set (0.00 sec)

mysql> show variables where variable_name='character_set_results';
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| character_set_results |       |
+-----------------------+-------+
1 row in set (0.01 sec)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think system variables in MySQL have their own types.


// Test set transaction isolation level, which is equivalent to setting variable "tx_isolation".
tk.MustExec("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED")
Expand Down
9 changes: 4 additions & 5 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,11 @@ func SetSessionSystemVar(vars *SessionVars, name string, value types.Datum) erro
if sysVar == nil {
return UnknownSystemVar
}
if value.IsNull() {
return vars.deleteSystemVar(name)
}
var sVal string
sVal := ""
var err error
sVal, err = value.ToString()
if !value.IsNull() {
sVal, err = value.ToString()
}
if err != nil {
return errors.Trace(err)
}
Expand Down