forked from pingcap/tidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_test.go
578 lines (456 loc) · 26.6 KB
/
set_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
// Copyright 2016 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package executor_test
import (
"context"
. "github.com/pingcap/check"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testutil"
)
func (s *testSuite) TestSetVar(c *C) {
tk := testkit.NewTestKit(c, s.store)
testSQL := "SET @a = 1;"
tk.MustExec(testSQL)
testSQL = `SET @a = "1";`
tk.MustExec(testSQL)
testSQL = "SET @a = null;"
tk.MustExec(testSQL)
testSQL = "SET @@global.autocommit = 1;"
tk.MustExec(testSQL)
// TODO: this test case should returns error.
// testSQL = "SET @@global.autocommit = null;"
// _, err := tk.Exec(testSQL)
// c.Assert(err, NotNil)
testSQL = "SET @@autocommit = 1;"
tk.MustExec(testSQL)
testSQL = "SET @@autocommit = null;"
_, err := tk.Exec(testSQL)
c.Assert(err, NotNil)
errTestSql := "SET @@date_format = 1;"
_, err = tk.Exec(errTestSql)
c.Assert(err, NotNil)
errTestSql = "SET @@rewriter_enabled = 1;"
_, err = tk.Exec(errTestSql)
c.Assert(err, NotNil)
errTestSql = "SET xxx = abcd;"
_, err = tk.Exec(errTestSql)
c.Assert(err, NotNil)
errTestSql = "SET @@global.a = 1;"
_, err = tk.Exec(errTestSql)
c.Assert(err, NotNil)
errTestSql = "SET @@global.timestamp = 1;"
_, err = tk.Exec(errTestSql)
c.Assert(err, NotNil)
// For issue 998
testSQL = "SET @issue998a=1, @issue998b=5;"
tk.MustExec(testSQL)
tk.MustQuery(`select @issue998a, @issue998b;`).Check(testkit.Rows("1 5"))
testSQL = "SET @@autocommit=0, @issue998a=2;"
tk.MustExec(testSQL)
tk.MustQuery(`select @issue998a, @@autocommit;`).Check(testkit.Rows("2 0"))
testSQL = "SET @@global.autocommit=1, @issue998b=6;"
tk.MustExec(testSQL)
tk.MustQuery(`select @issue998b, @@global.autocommit;`).Check(testkit.Rows("6 1"))
// For issue 4302
testSQL = "use test;drop table if exists x;create table x(a int);insert into x value(1);"
tk.MustExec(testSQL)
testSQL = "SET @issue4302=(select a from x limit 1);"
tk.MustExec(testSQL)
tk.MustQuery(`select @issue4302;`).Check(testkit.Rows("1"))
// Set default
// {ScopeGlobal | ScopeSession, "low_priority_updates", "OFF"},
// For global var
tk.MustQuery(`select @@global.low_priority_updates;`).Check(testkit.Rows("0"))
tk.MustExec(`set @@global.low_priority_updates="ON";`)
tk.MustQuery(`select @@global.low_priority_updates;`).Check(testkit.Rows("1"))
tk.MustExec(`set @@global.low_priority_updates=DEFAULT;`) // It will be set to compiled-in default value.
tk.MustQuery(`select @@global.low_priority_updates;`).Check(testkit.Rows("0"))
// For session
tk.MustQuery(`select @@session.low_priority_updates;`).Check(testkit.Rows("0"))
tk.MustExec(`set @@global.low_priority_updates="ON";`)
tk.MustExec(`set @@session.low_priority_updates=DEFAULT;`) // It will be set to global var value.
tk.MustQuery(`select @@session.low_priority_updates;`).Check(testkit.Rows("1"))
// For mysql jdbc driver issue.
tk.MustQuery(`select @@session.tx_read_only;`).Check(testkit.Rows("0"))
// Test session variable states.
vars := tk.Se.(sessionctx.Context).GetSessionVars()
tk.Se.CommitTxn(context.TODO())
tk.MustExec("set @@autocommit = 1")
c.Assert(vars.InTxn(), IsFalse)
c.Assert(vars.IsAutocommit(), IsTrue)
tk.MustExec("set @@autocommit = 0")
c.Assert(vars.IsAutocommit(), IsFalse)
tk.MustExec("set @@sql_mode = 'strict_trans_tables'")
c.Assert(vars.StrictSQLMode, IsTrue)
tk.MustExec("set @@sql_mode = ''")
c.Assert(vars.StrictSQLMode, IsFalse)
tk.MustExec("set names utf8")
charset, collation := vars.GetCharsetInfo()
c.Assert(charset, Equals, "utf8")
c.Assert(collation, Equals, "utf8_bin")
tk.MustExec("set names latin1 collate latin1_swedish_ci")
charset, collation = vars.GetCharsetInfo()
c.Assert(charset, Equals, "latin1")
c.Assert(collation, Equals, "latin1_swedish_ci")
tk.MustExec("set names utf8 collate default")
charset, collation = vars.GetCharsetInfo()
c.Assert(charset, Equals, "utf8")
c.Assert(collation, Equals, "utf8_bin")
tk.MustExec("set character_set_results = NULL")
tk.MustQuery("select @@character_set_results").Check(testkit.Rows(""))
// Test set transaction isolation level, which is equivalent to setting variable "tx_isolation".
tk.MustExec("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED")
tk.MustQuery("select @@session.tx_isolation").Check(testkit.Rows("READ-COMMITTED"))
tk.MustQuery("select @@session.transaction_isolation").Check(testkit.Rows("READ-COMMITTED"))
// error
_, err = tk.Exec("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED")
c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedValueForVar), IsTrue, Commentf("err %v", err))
tk.MustQuery("select @@session.tx_isolation").Check(testkit.Rows("READ-COMMITTED"))
tk.MustQuery("select @@session.transaction_isolation").Check(testkit.Rows("READ-COMMITTED"))
// Fails
_, err = tk.Exec("SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE")
c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedValueForVar), IsTrue, Commentf("err %v", err))
tk.MustQuery("select @@global.tx_isolation").Check(testkit.Rows("REPEATABLE-READ"))
tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Rows("REPEATABLE-READ"))
// test synonyms variables
tk.MustExec("SET SESSION tx_isolation = 'READ-COMMITTED'")
tk.MustQuery("select @@session.tx_isolation").Check(testkit.Rows("READ-COMMITTED"))
tk.MustQuery("select @@session.transaction_isolation").Check(testkit.Rows("READ-COMMITTED"))
_, err = tk.Exec("SET SESSION tx_isolation = 'READ-UNCOMMITTED'")
c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedValueForVar), IsTrue, Commentf("err %v", err))
tk.MustQuery("select @@session.tx_isolation").Check(testkit.Rows("READ-COMMITTED"))
tk.MustQuery("select @@session.transaction_isolation").Check(testkit.Rows("READ-COMMITTED"))
// fails
_, err = tk.Exec("SET SESSION transaction_isolation = 'SERIALIZABLE'")
c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedValueForVar), IsTrue, Commentf("err %v", err))
tk.MustQuery("select @@session.tx_isolation").Check(testkit.Rows("READ-COMMITTED"))
tk.MustQuery("select @@session.transaction_isolation").Check(testkit.Rows("READ-COMMITTED"))
// fails
_, err = tk.Exec("SET GLOBAL transaction_isolation = 'SERIALIZABLE'")
c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedValueForVar), IsTrue, Commentf("err %v", err))
tk.MustQuery("select @@global.tx_isolation").Check(testkit.Rows("REPEATABLE-READ"))
tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Rows("REPEATABLE-READ"))
_, err = tk.Exec("SET GLOBAL transaction_isolation = 'READ-UNCOMMITTED'")
c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedValueForVar), IsTrue, Commentf("err %v", err))
tk.MustQuery("select @@global.tx_isolation").Check(testkit.Rows("REPEATABLE-READ"))
tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Rows("REPEATABLE-READ"))
_, err = tk.Exec("SET GLOBAL tx_isolation = 'SERIALIZABLE'")
c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedValueForVar), IsTrue, Commentf("err %v", err))
tk.MustQuery("select @@global.tx_isolation").Check(testkit.Rows("REPEATABLE-READ"))
tk.MustQuery("select @@global.transaction_isolation").Check(testkit.Rows("REPEATABLE-READ"))
tk.MustExec("SET SESSION tx_read_only = 1")
tk.MustExec("SET SESSION tx_read_only = 0")
tk.MustQuery("select @@session.tx_read_only").Check(testkit.Rows("0"))
tk.MustQuery("select @@session.transaction_read_only").Check(testkit.Rows("0"))
tk.MustExec("SET GLOBAL tx_read_only = 1")
tk.MustExec("SET GLOBAL tx_read_only = 0")
tk.MustQuery("select @@global.tx_read_only").Check(testkit.Rows("0"))
tk.MustQuery("select @@global.transaction_read_only").Check(testkit.Rows("0"))
tk.MustExec("SET SESSION transaction_read_only = 1")
tk.MustExec("SET SESSION transaction_read_only = 0")
tk.MustQuery("select @@session.tx_read_only").Check(testkit.Rows("0"))
tk.MustQuery("select @@session.transaction_read_only").Check(testkit.Rows("0"))
tk.MustExec("SET SESSION transaction_read_only = 1")
tk.MustQuery("select @@session.tx_read_only").Check(testkit.Rows("1"))
tk.MustQuery("select @@session.transaction_read_only").Check(testkit.Rows("1"))
tk.MustExec("SET GLOBAL transaction_read_only = 1")
tk.MustExec("SET GLOBAL transaction_read_only = 0")
tk.MustQuery("select @@global.tx_read_only").Check(testkit.Rows("0"))
tk.MustQuery("select @@global.transaction_read_only").Check(testkit.Rows("0"))
tk.MustExec("SET GLOBAL transaction_read_only = 1")
tk.MustQuery("select @@global.tx_read_only").Check(testkit.Rows("1"))
tk.MustQuery("select @@global.transaction_read_only").Check(testkit.Rows("1"))
// Even the transaction fail, set session variable would success.
tk.MustExec("BEGIN")
tk.MustExec("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED")
_, err = tk.Exec(`INSERT INTO t VALUES ("sdfsdf")`)
c.Assert(err, NotNil)
tk.MustExec("COMMIT")
tk.MustQuery("select @@session.tx_isolation").Check(testkit.Rows("READ-COMMITTED"))
tk.MustExec("set global avoid_temporal_upgrade = on")
tk.MustQuery(`select @@global.avoid_temporal_upgrade;`).Check(testkit.Rows("1"))
tk.MustExec("set @@global.avoid_temporal_upgrade = off")
tk.MustQuery(`select @@global.avoid_temporal_upgrade;`).Check(testkit.Rows("0"))
tk.MustExec("set session sql_log_bin = on")
tk.MustQuery(`select @@session.sql_log_bin;`).Check(testkit.Rows("1"))
tk.MustExec("set sql_log_bin = off")
tk.MustQuery(`select @@session.sql_log_bin;`).Check(testkit.Rows("0"))
tk.MustExec("set @@sql_log_bin = on")
tk.MustQuery(`select @@session.sql_log_bin;`).Check(testkit.Rows("1"))
tk.MustExec("set @@tidb_general_log = 1")
tk.MustExec("set @@tidb_general_log = 0")
tk.MustExec(`set tidb_force_priority = "no_priority"`)
tk.MustQuery(`select @@tidb_force_priority;`).Check(testkit.Rows("NO_PRIORITY"))
tk.MustExec(`set tidb_force_priority = "low_priority"`)
tk.MustQuery(`select @@tidb_force_priority;`).Check(testkit.Rows("LOW_PRIORITY"))
tk.MustExec(`set tidb_force_priority = "high_priority"`)
tk.MustQuery(`select @@tidb_force_priority;`).Check(testkit.Rows("HIGH_PRIORITY"))
tk.MustExec(`set tidb_force_priority = "delayed"`)
tk.MustQuery(`select @@tidb_force_priority;`).Check(testkit.Rows("DELAYED"))
tk.MustExec(`set tidb_force_priority = "abc"`)
tk.MustQuery(`select @@tidb_force_priority;`).Check(testkit.Rows("NO_PRIORITY"))
_, err = tk.Exec(`set global tidb_force_priority = ""`)
c.Assert(err, NotNil)
tk.MustExec("set tidb_constraint_check_in_place = 1")
tk.MustQuery(`select @@session.tidb_constraint_check_in_place;`).Check(testkit.Rows("1"))
tk.MustExec("set global tidb_constraint_check_in_place = 0")
tk.MustQuery(`select @@global.tidb_constraint_check_in_place;`).Check(testkit.Rows("0"))
tk.MustExec("set tidb_slow_log_threshold = 0")
tk.MustQuery("select @@session.tidb_slow_log_threshold;").Check(testkit.Rows("0"))
tk.MustExec("set tidb_slow_log_threshold = 1")
tk.MustQuery("select @@session.tidb_slow_log_threshold;").Check(testkit.Rows("1"))
_, err = tk.Exec("set global tidb_slow_log_threshold = 0")
c.Assert(err, NotNil)
tk.MustExec("set tidb_query_log_max_len = 0")
tk.MustQuery("select @@session.tidb_query_log_max_len;").Check(testkit.Rows("0"))
tk.MustExec("set tidb_query_log_max_len = 20")
tk.MustQuery("select @@session.tidb_query_log_max_len;").Check(testkit.Rows("20"))
_, err = tk.Exec("set global tidb_query_log_max_len = 20")
c.Assert(err, NotNil)
tk.MustExec("set tidb_batch_commit = 0")
tk.MustQuery("select @@session.tidb_batch_commit;").Check(testkit.Rows("0"))
tk.MustExec("set tidb_batch_commit = 1")
tk.MustQuery("select @@session.tidb_batch_commit;").Check(testkit.Rows("1"))
_, err = tk.Exec("set global tidb_batch_commit = 0")
c.Assert(err, NotNil)
_, err = tk.Exec("set global tidb_batch_commit = 2")
c.Assert(err, NotNil)
}
func (s *testSuite) TestSetCharset(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`SET NAMES latin1`)
ctx := tk.Se.(sessionctx.Context)
sessionVars := ctx.GetSessionVars()
for _, v := range variable.SetNamesVariables {
sVar, err := variable.GetSessionSystemVar(sessionVars, v)
c.Assert(err, IsNil)
c.Assert(sVar != "utf8", IsTrue)
}
tk.MustExec(`SET NAMES utf8`)
for _, v := range variable.SetNamesVariables {
sVar, err := variable.GetSessionSystemVar(sessionVars, v)
c.Assert(err, IsNil)
c.Assert(sVar, Equals, "utf8")
}
sVar, err := variable.GetSessionSystemVar(sessionVars, variable.CollationConnection)
c.Assert(err, IsNil)
c.Assert(sVar, Equals, "utf8_bin")
// Issue 1523
tk.MustExec(`SET NAMES binary`)
}
func (s *testSuite) TestValidateSetVar(c *C) {
tk := testkit.NewTestKit(c, s.store)
_, err := tk.Exec("set global tidb_distsql_scan_concurrency='fff';")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("set global tidb_distsql_scan_concurrency=-1;")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("set @@tidb_distsql_scan_concurrency='fff';")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("set @@tidb_distsql_scan_concurrency=-1;")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("set @@tidb_batch_delete='ok';")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
tk.MustExec("set @@tidb_batch_delete='On';")
tk.MustExec("set @@tidb_batch_delete='oFf';")
tk.MustExec("set @@tidb_batch_delete=1;")
tk.MustExec("set @@tidb_batch_delete=0;")
_, err = tk.Exec("set @@tidb_batch_delete=3;")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("set @@tidb_mem_quota_mergejoin='tidb';")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
tk.MustExec("set @@group_concat_max_len=1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect group_concat_max_len value: '1'"))
result := tk.MustQuery("select @@group_concat_max_len;")
result.Check(testkit.Rows("4"))
_, err = tk.Exec("set @@group_concat_max_len = 18446744073709551616")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue, Commentf("err %v", err))
// Test illegal type
_, err = tk.Exec("set @@group_concat_max_len='hello'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue, Commentf("err %v", err))
tk.MustExec("set @@default_week_format=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect default_week_format value: '-1'"))
result = tk.MustQuery("select @@default_week_format;")
result.Check(testkit.Rows("0"))
tk.MustExec("set @@default_week_format=9")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect default_week_format value: '9'"))
result = tk.MustQuery("select @@default_week_format;")
result.Check(testkit.Rows("7"))
_, err = tk.Exec("set @@error_count = 0")
c.Assert(terror.ErrorEqual(err, variable.ErrReadOnly), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("set @@warning_count = 0")
c.Assert(terror.ErrorEqual(err, variable.ErrReadOnly), IsTrue, Commentf("err %v", err))
tk.MustExec("set time_zone='SySTeM'")
result = tk.MustQuery("select @@time_zone;")
result.Check(testkit.Rows("SYSTEM"))
// The following cases test value out of range and illegal type when setting system variables.
// See https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html for more details.
tk.MustExec("set @@global.max_connections=100001")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_connections value: '100001'"))
result = tk.MustQuery("select @@global.max_connections;")
result.Check(testkit.Rows("100000"))
tk.MustExec("set @@global.max_connections=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_connections value: '-1'"))
result = tk.MustQuery("select @@global.max_connections;")
result.Check(testkit.Rows("1"))
_, err = tk.Exec("set @@global.max_connections='hello'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)
tk.MustExec("set @@global.max_allowed_packet=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_allowed_packet value: '-1'"))
result = tk.MustQuery("select @@global.max_allowed_packet;")
result.Check(testkit.Rows("1024"))
_, err = tk.Exec("set @@global.max_allowed_packet='hello'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)
tk.MustExec("set @@global.max_connect_errors=18446744073709551615")
tk.MustExec("set @@global.max_connect_errors=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_connect_errors value: '-1'"))
result = tk.MustQuery("select @@global.max_connect_errors;")
result.Check(testkit.Rows("1"))
_, err = tk.Exec("set @@global.max_connect_errors=18446744073709551616")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)
tk.MustExec("set @@global.max_connections=100001")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_connections value: '100001'"))
result = tk.MustQuery("select @@global.max_connections;")
result.Check(testkit.Rows("100000"))
tk.MustExec("set @@global.max_connections=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_connections value: '-1'"))
result = tk.MustQuery("select @@global.max_connections;")
result.Check(testkit.Rows("1"))
_, err = tk.Exec("set @@global.max_connections='hello'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)
tk.MustExec("set @@max_sort_length=1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_sort_length value: '1'"))
result = tk.MustQuery("select @@max_sort_length;")
result.Check(testkit.Rows("4"))
tk.MustExec("set @@max_sort_length=-100")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_sort_length value: '-100'"))
result = tk.MustQuery("select @@max_sort_length;")
result.Check(testkit.Rows("4"))
tk.MustExec("set @@max_sort_length=8388609")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect max_sort_length value: '8388609'"))
result = tk.MustQuery("select @@max_sort_length;")
result.Check(testkit.Rows("8388608"))
_, err = tk.Exec("set @@max_sort_length='hello'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)
tk.MustExec("set @@global.table_definition_cache=399")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect table_definition_cache value: '399'"))
result = tk.MustQuery("select @@global.table_definition_cache;")
result.Check(testkit.Rows("400"))
tk.MustExec("set @@global.table_definition_cache=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect table_definition_cache value: '-1'"))
result = tk.MustQuery("select @@global.table_definition_cache;")
result.Check(testkit.Rows("400"))
tk.MustExec("set @@global.table_definition_cache=524289")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect table_definition_cache value: '524289'"))
result = tk.MustQuery("select @@global.table_definition_cache;")
result.Check(testkit.Rows("524288"))
_, err = tk.Exec("set @@global.table_definition_cache='hello'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)
tk.MustExec("set @@old_passwords=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect old_passwords value: '-1'"))
result = tk.MustQuery("select @@old_passwords;")
result.Check(testkit.Rows("0"))
tk.MustExec("set @@old_passwords=3")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect old_passwords value: '3'"))
result = tk.MustQuery("select @@old_passwords;")
result.Check(testkit.Rows("2"))
_, err = tk.Exec("set @@old_passwords='hello'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)
tk.MustExec("set @@tmp_table_size=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect tmp_table_size value: '-1'"))
result = tk.MustQuery("select @@tmp_table_size;")
result.Check(testkit.Rows("1024"))
tk.MustExec("set @@tmp_table_size=1020")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect tmp_table_size value: '1020'"))
result = tk.MustQuery("select @@tmp_table_size;")
result.Check(testkit.Rows("1024"))
tk.MustExec("set @@tmp_table_size=167772161")
result = tk.MustQuery("select @@tmp_table_size;")
result.Check(testkit.Rows("167772161"))
tk.MustExec("set @@tmp_table_size=18446744073709551615")
result = tk.MustQuery("select @@tmp_table_size;")
result.Check(testkit.Rows("18446744073709551615"))
_, err = tk.Exec("set @@tmp_table_size=18446744073709551616")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)
_, err = tk.Exec("set @@tmp_table_size='hello'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongTypeForVar), IsTrue)
tk.MustExec("set @@global.connect_timeout=1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect connect_timeout value: '1'"))
result = tk.MustQuery("select @@global.connect_timeout;")
result.Check(testkit.Rows("2"))
tk.MustExec("set @@global.connect_timeout=31536000")
result = tk.MustQuery("select @@global.connect_timeout;")
result.Check(testkit.Rows("31536000"))
tk.MustExec("set @@global.connect_timeout=31536001")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect connect_timeout value: '31536001'"))
result = tk.MustQuery("select @@global.connect_timeout;")
result.Check(testkit.Rows("31536000"))
result = tk.MustQuery("select @@sql_select_limit;")
result.Check(testkit.Rows("18446744073709551615"))
tk.MustExec("set @@sql_select_limit=default")
result = tk.MustQuery("select @@sql_select_limit;")
result.Check(testkit.Rows("18446744073709551615"))
tk.MustExec("set @@global.sync_binlog=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect sync_binlog value: '-1'"))
tk.MustExec("set @@global.sync_binlog=4294967299")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect sync_binlog value: '4294967299'"))
tk.MustExec("set @@global.flush_time=31536001")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect flush_time value: '31536001'"))
tk.MustExec("set @@global.interactive_timeout=31536001")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect interactive_timeout value: '31536001'"))
tk.MustExec("set @@global.innodb_commit_concurrency = -1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect innodb_commit_concurrency value: '-1'"))
tk.MustExec("set @@global.innodb_commit_concurrency = 1001")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect innodb_commit_concurrency value: '1001'"))
tk.MustExec("set @@global.innodb_fast_shutdown = -1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect innodb_fast_shutdown value: '-1'"))
tk.MustExec("set @@global.innodb_fast_shutdown = 3")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect innodb_fast_shutdown value: '3'"))
tk.MustExec("set @@global.innodb_lock_wait_timeout = 0")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect innodb_lock_wait_timeout value: '0'"))
tk.MustExec("set @@global.innodb_lock_wait_timeout = 1073741825")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect innodb_lock_wait_timeout value: '1073741825'"))
tk.MustExec("set @@innodb_lock_wait_timeout = 0")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect innodb_lock_wait_timeout value: '0'"))
tk.MustExec("set @@innodb_lock_wait_timeout = 1073741825")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect innodb_lock_wait_timeout value: '1073741825'"))
tk.MustExec("set @@global.validate_password_number_count=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect validate_password_number_count value: '-1'"))
tk.MustExec("set @@global.validate_password_length=-1")
tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1292|Truncated incorrect validate_password_length value: '-1'"))
tk.MustExec("set @@global.validate_password_length=8")
tk.MustQuery("show warnings").Check(testkit.Rows())
_, err = tk.Exec("set @@tx_isolation=''")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("set global tx_isolation=''")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("set @@transaction_isolation=''")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("set global transaction_isolation=''")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
_, err = tk.Exec("set global tx_isolation='REPEATABLE-READ1'")
c.Assert(terror.ErrorEqual(err, variable.ErrWrongValueForVar), IsTrue, Commentf("err %v", err))
tk.MustExec("set @@tx_isolation='READ-COMMITTED'")
result = tk.MustQuery("select @@tx_isolation;")
result.Check(testkit.Rows("READ-COMMITTED"))
tk.MustExec("set @@tx_isolation='read-COMMITTED'")
result = tk.MustQuery("select @@tx_isolation;")
result.Check(testkit.Rows("READ-COMMITTED"))
tk.MustExec("set @@tx_isolation='REPEATABLE-READ'")
result = tk.MustQuery("select @@tx_isolation;")
result.Check(testkit.Rows("REPEATABLE-READ"))
_, err = tk.Exec("set @@tx_isolation='SERIALIZABLE'")
c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedValueForVar), IsTrue, Commentf("err %v", err))
}