@@ -327,4 +327,141 @@ func (s *testSuite) TestValidateSetVar(c *C) {
327
327
tk .MustExec ("set time_zone='SySTeM'" )
328
328
result = tk .MustQuery ("select @@time_zone;" )
329
329
result .Check (testkit .Rows ("SYSTEM" ))
330
+
331
+ // The following cases test value out of range and illegal type when setting system variables.
332
+ // See https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html for more details.
333
+ tk .MustExec ("set @@global.max_connections=100001" )
334
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect max_connections value: '100001'" ))
335
+ result = tk .MustQuery ("select @@global.max_connections;" )
336
+ result .Check (testkit .Rows ("100000" ))
337
+
338
+ tk .MustExec ("set @@global.max_connections=-1" )
339
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect max_connections value: '-1'" ))
340
+ result = tk .MustQuery ("select @@global.max_connections;" )
341
+ result .Check (testkit .Rows ("1" ))
342
+
343
+ _ , err = tk .Exec ("set @@global.max_connections='hello'" )
344
+ c .Assert (terror .ErrorEqual (err , variable .ErrWrongTypeForVar ), IsTrue )
345
+
346
+ tk .MustExec ("set @@global.max_connect_errors=18446744073709551615" )
347
+
348
+ tk .MustExec ("set @@global.max_connect_errors=-1" )
349
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect max_connect_errors value: '-1'" ))
350
+ result = tk .MustQuery ("select @@global.max_connect_errors;" )
351
+ result .Check (testkit .Rows ("1" ))
352
+
353
+ _ , err = tk .Exec ("set @@global.max_connect_errors=18446744073709551616" )
354
+ c .Assert (terror .ErrorEqual (err , variable .ErrWrongTypeForVar ), IsTrue )
355
+
356
+ tk .MustExec ("set @@global.max_connections=100001" )
357
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect max_connections value: '100001'" ))
358
+ result = tk .MustQuery ("select @@global.max_connections;" )
359
+ result .Check (testkit .Rows ("100000" ))
360
+
361
+ tk .MustExec ("set @@global.max_connections=-1" )
362
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect max_connections value: '-1'" ))
363
+ result = tk .MustQuery ("select @@global.max_connections;" )
364
+ result .Check (testkit .Rows ("1" ))
365
+
366
+ _ , err = tk .Exec ("set @@global.max_connections='hello'" )
367
+ c .Assert (terror .ErrorEqual (err , variable .ErrWrongTypeForVar ), IsTrue )
368
+
369
+ tk .MustExec ("set @@max_sort_length=1" )
370
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect max_sort_length value: '1'" ))
371
+ result = tk .MustQuery ("select @@max_sort_length;" )
372
+ result .Check (testkit .Rows ("4" ))
373
+
374
+ tk .MustExec ("set @@max_sort_length=-100" )
375
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect max_sort_length value: '-100'" ))
376
+ result = tk .MustQuery ("select @@max_sort_length;" )
377
+ result .Check (testkit .Rows ("4" ))
378
+
379
+ tk .MustExec ("set @@max_sort_length=8388609" )
380
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect max_sort_length value: '8388609'" ))
381
+ result = tk .MustQuery ("select @@max_sort_length;" )
382
+ result .Check (testkit .Rows ("8388608" ))
383
+
384
+ _ , err = tk .Exec ("set @@max_sort_length='hello'" )
385
+ c .Assert (terror .ErrorEqual (err , variable .ErrWrongTypeForVar ), IsTrue )
386
+
387
+ tk .MustExec ("set @@global.table_definition_cache=399" )
388
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect table_definition_cache value: '399'" ))
389
+ result = tk .MustQuery ("select @@global.table_definition_cache;" )
390
+ result .Check (testkit .Rows ("400" ))
391
+
392
+ tk .MustExec ("set @@global.table_definition_cache=-1" )
393
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect table_definition_cache value: '-1'" ))
394
+ result = tk .MustQuery ("select @@global.table_definition_cache;" )
395
+ result .Check (testkit .Rows ("400" ))
396
+
397
+ tk .MustExec ("set @@global.table_definition_cache=524289" )
398
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect table_definition_cache value: '524289'" ))
399
+ result = tk .MustQuery ("select @@global.table_definition_cache;" )
400
+ result .Check (testkit .Rows ("524288" ))
401
+
402
+ _ , err = tk .Exec ("set @@global.table_definition_cache='hello'" )
403
+ c .Assert (terror .ErrorEqual (err , variable .ErrWrongTypeForVar ), IsTrue )
404
+
405
+ tk .MustExec ("set @@old_passwords=-1" )
406
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect old_passwords value: '-1'" ))
407
+ result = tk .MustQuery ("select @@old_passwords;" )
408
+ result .Check (testkit .Rows ("0" ))
409
+
410
+ tk .MustExec ("set @@old_passwords=3" )
411
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect old_passwords value: '3'" ))
412
+ result = tk .MustQuery ("select @@old_passwords;" )
413
+ result .Check (testkit .Rows ("2" ))
414
+
415
+ _ , err = tk .Exec ("set @@old_passwords='hello'" )
416
+ c .Assert (terror .ErrorEqual (err , variable .ErrWrongTypeForVar ), IsTrue )
417
+
418
+ tk .MustExec ("set @@tmp_table_size=-1" )
419
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect tmp_table_size value: '-1'" ))
420
+ result = tk .MustQuery ("select @@tmp_table_size;" )
421
+ result .Check (testkit .Rows ("1024" ))
422
+
423
+ tk .MustExec ("set @@tmp_table_size=1020" )
424
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect tmp_table_size value: '1020'" ))
425
+ result = tk .MustQuery ("select @@tmp_table_size;" )
426
+ result .Check (testkit .Rows ("1024" ))
427
+
428
+ tk .MustExec ("set @@tmp_table_size=167772161" )
429
+ result = tk .MustQuery ("select @@tmp_table_size;" )
430
+ result .Check (testkit .Rows ("167772161" ))
431
+
432
+ tk .MustExec ("set @@tmp_table_size=18446744073709551615" )
433
+ result = tk .MustQuery ("select @@tmp_table_size;" )
434
+ result .Check (testkit .Rows ("18446744073709551615" ))
435
+
436
+ _ , err = tk .Exec ("set @@tmp_table_size=18446744073709551616" )
437
+ c .Assert (terror .ErrorEqual (err , variable .ErrWrongTypeForVar ), IsTrue )
438
+
439
+ _ , err = tk .Exec ("set @@tmp_table_size='hello'" )
440
+ c .Assert (terror .ErrorEqual (err , variable .ErrWrongTypeForVar ), IsTrue )
441
+
442
+ tk .MustExec ("set @@global.connect_timeout=1" )
443
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect connect_timeout value: '1'" ))
444
+ result = tk .MustQuery ("select @@global.connect_timeout;" )
445
+ result .Check (testkit .Rows ("2" ))
446
+
447
+ tk .MustExec ("set @@global.connect_timeout=31536000" )
448
+ result = tk .MustQuery ("select @@global.connect_timeout;" )
449
+ result .Check (testkit .Rows ("31536000" ))
450
+
451
+ tk .MustExec ("set @@global.connect_timeout=31536001" )
452
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect connect_timeout value: '31536001'" ))
453
+ result = tk .MustQuery ("select @@global.connect_timeout;" )
454
+ result .Check (testkit .Rows ("31536000" ))
455
+
456
+ result = tk .MustQuery ("select @@sql_select_limit;" )
457
+ result .Check (testkit .Rows ("18446744073709551615" ))
458
+ tk .MustExec ("set @@sql_select_limit=default" )
459
+ result = tk .MustQuery ("select @@sql_select_limit;" )
460
+ result .Check (testkit .Rows ("18446744073709551615" ))
461
+
462
+ tk .MustExec ("set @@global.flush_time=31536001" )
463
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect flush_time value: '31536001'" ))
464
+
465
+ tk .MustExec ("set @@global.interactive_timeout=31536001" )
466
+ tk .MustQuery ("show warnings" ).Check (testutil .RowsWithSep ("|" , "Warning|1292|Truncated incorrect interactive_timeout value: '31536001'" ))
330
467
}
0 commit comments