############## mysql-test\t\max_length_for_sort_data_basic.test ###############
#                                                                             #
# Variable Name: max_length_for_sort_data                                     #
# Scope: GLOBAL | SESSION                                                     #
# Access Type: Dynamic                                                        #
# Data Type: numeric                                                          #
# Default Value:   1024                                                       #
# Range: 4-8388608                                                            #
#                                                                             #
#                                                                             #
# Creation Date: 2008-02-07                                                   #
# Author:  Salman                                                             #
#                                                                             #
# Description: Test Cases of Dynamic System Variable max_length_for_sort_data #
#              that checks the behavior of this variable in the following ways#
#              * Default Value                                                #
#              * Valid & Invalid values                                       #
#              * Scope & Access method                                        #
#              * Data Integrity                                               #
#                                                                             #
# Reference: http://dev.mysql.com/doc/refman/5.1/en/                          #
#  server-system-variables.html                                               #
#                                                                             #
###############################################################################

--source include/load_sysvars.inc

#####################################################
#        START OF max_length_for_sort_data TESTS    #
#####################################################


#############################################################
#                 Save initial value                        #
#############################################################

SET @start_global_value = @@global.max_length_for_sort_data;
SELECT @start_global_value;
SET @start_session_value = @@session.max_length_for_sort_data;
SELECT @start_session_value;


--echo '#--------------------FN_DYNVARS_080_01-------------------------#'
################################################################
#    Display the DEFAULT value of max_length_for_sort_data     #
################################################################

SET @@global.max_length_for_sort_data = 1000;
SET @@global.max_length_for_sort_data = DEFAULT;
SELECT @@global.max_length_for_sort_data;


SET @@session.max_length_for_sort_data = 1000;
SET @@session.max_length_for_sort_data = DEFAULT;
SELECT @@session.max_length_for_sort_data;


--echo '#--------------------FN_DYNVARS_080_02-------------------------#'
################################################################
#     Check the DEFAULT value of max_length_for_sort_data      #
################################################################

SET @@global.max_length_for_sort_data = DEFAULT;
SELECT @@global.max_length_for_sort_data = 1024;

SET @@session.max_length_for_sort_data = DEFAULT;
SELECT @@session.max_length_for_sort_data = 1024;



--echo '#--------------------FN_DYNVARS_080_03-------------------------#'
##################################################################################
# Change the value of max_length_for_sort_data to a valid value for GLOBAL Scope #
##################################################################################

SET @@global.max_length_for_sort_data = 4;
SELECT @@global.max_length_for_sort_data;
SET @@global.max_length_for_sort_data = 5;
SELECT @@global.max_length_for_sort_data;
SET @@global.max_length_for_sort_data = 8388608;
SELECT @@global.max_length_for_sort_data;
SET @@global.max_length_for_sort_data = 8388607;
SELECT @@global.max_length_for_sort_data;
SET @@global.max_length_for_sort_data = 65536;
SELECT @@global.max_length_for_sort_data;

--echo '#--------------------FN_DYNVARS_080_04-------------------------#'
###################################################################################
# Change the value of max_length_for_sort_data to a valid value for SESSION Scope #
###################################################################################

SET @@session.max_length_for_sort_data = 4;
SELECT @@session.max_length_for_sort_data;

SET @@session.max_length_for_sort_data = 5;
SELECT @@session.max_length_for_sort_data;

SET @@session.max_length_for_sort_data = 8388608;
SELECT @@session.max_length_for_sort_data;

SET @@session.max_length_for_sort_data = 8388607;
SELECT @@session.max_length_for_sort_data;

SET @@session.max_length_for_sort_data = 65536;
SELECT @@session.max_length_for_sort_data;


--echo '#------------------FN_DYNVARS_080_05-----------------------#'
####################################################################
# Change the value of max_length_for_sort_data to an invalid value #
####################################################################

SET @@global.max_length_for_sort_data = -1024;
SELECT @@global.max_length_for_sort_data;
SET @@global.max_length_for_sort_data = 3;
SELECT @@global.max_length_for_sort_data;
SET @@global.max_length_for_sort_data = 8388609;
SELECT @@global.max_length_for_sort_data;
SET @@global.max_length_for_sort_data = 0;
SELECT @@global.max_length_for_sort_data;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.max_length_for_sort_data = 65530.34;
SELECT @@global.max_length_for_sort_data;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@global.max_length_for_sort_data = test;
SELECT @@global.max_length_for_sort_data;

SET @@session.max_length_for_sort_data = 8388610;
SELECT @@session.max_length_for_sort_data;
SET @@session.max_length_for_sort_data = -1;
SELECT @@session.max_length_for_sort_data;
SET @@session.max_length_for_sort_data = 3;
SELECT @@session.max_length_for_sort_data;
SET @@session.max_length_for_sort_data = 0;
SELECT @@session.max_length_for_sort_data;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.max_length_for_sort_data = 65530.34;
SET @@session.max_length_for_sort_data = 10737418241;
SELECT @@session.max_length_for_sort_data;
--Error ER_WRONG_TYPE_FOR_VAR
SET @@session.max_length_for_sort_data = test;
SELECT @@session.max_length_for_sort_data;


--echo '#------------------FN_DYNVARS_080_06-----------------------#'
####################################################################
#   Check if the value in GLOBAL Table matches value in variable   #
####################################################################


SELECT @@global.max_length_for_sort_data = VARIABLE_VALUE 
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES 
WHERE VARIABLE_NAME='max_length_for_sort_data';

--echo '#------------------FN_DYNVARS_080_07-----------------------#'
####################################################################
#  Check if the value in SESSION Table matches value in variable   #
####################################################################

SELECT @@session.max_length_for_sort_data = VARIABLE_VALUE 
FROM INFORMATION_SCHEMA.SESSION_VARIABLES 
WHERE VARIABLE_NAME='max_length_for_sort_data';


--echo '#------------------FN_DYNVARS_080_08-----------------------#'
####################################################################
#     Check if TRUE and FALSE values can be used on variable       #
####################################################################

SET @@global.max_length_for_sort_data = TRUE;
SELECT @@global.max_length_for_sort_data;
SET @@global.max_length_for_sort_data = FALSE;
SELECT @@global.max_length_for_sort_data;


--echo '#---------------------FN_DYNVARS_080_09----------------------#'
#################################################################################
#  Check if accessing variable with and without GLOBAL point to same variable   #
#################################################################################

SET @@global.max_length_for_sort_data = 2048;
SELECT @@max_length_for_sort_data = @@global.max_length_for_sort_data;


--echo '#---------------------FN_DYNVARS_080_10----------------------#'
########################################################################################################
#    Check if accessing variable with SESSION,LOCAL and without SCOPE points to same session variable  #
########################################################################################################

SET @@max_length_for_sort_data = 100000;
SELECT @@max_length_for_sort_data = @@local.max_length_for_sort_data;
SELECT @@local.max_length_for_sort_data = @@session.max_length_for_sort_data;


--echo '#---------------------FN_DYNVARS_080_11----------------------#'
###################################################################################
#   Check if max_length_for_sort_data can be accessed with and without @@ sign    #
###################################################################################


SET max_length_for_sort_data = 1024;
SELECT @@max_length_for_sort_data;
--Error ER_UNKNOWN_TABLE
SELECT local.max_length_for_sort_data;
--Error ER_UNKNOWN_TABLE
SELECT session.max_length_for_sort_data;
--Error ER_BAD_FIELD_ERROR
SELECT max_length_for_sort_data = @@session.max_length_for_sort_data;


####################################
#     Restore initial value        #
####################################

SET @@global.max_length_for_sort_data = @start_global_value;
SELECT @@global.max_length_for_sort_data;
SET @@session.max_length_for_sort_data = @start_session_value;
SELECT @@session.max_length_for_sort_data;


#############################################################
#                 END OF max_length_for_sort_data TESTS     #
#############################################################

