Environment:
MariaDB v 10.6.2 HeidiSQL v 11.3.0.6321 32 bit Windows 10 Charset: utf8mb4 Collation: utf8mb4_bin
Issue
I am working on a function that accepts user input, validates the input, updates a table if input is valid, and builds a return message.
The issue I am running into is that one of the input values can only be lower case letters. To test for an error condition where the user has input capitol letters,
I have the following if statement:
if lower(cast(in_lk_token as char collate utf8mb4_bin))
<> cast(in_lk_token as char collate utf8mb4_bin)
then
set v_error_ct = v_error_ct + 1;
set v_msg_out = concat(v_msg_out, '\t', cast(v_error_ct as char), '. Input Parameter: ', in_lk_token, ' not equal to, ', lower(in_lk_token), ' must contain lower case letters only.\r\n');
end if;
I also tried the same if statement but wrapped the output of lower() around cast:
if cast(lower(in_lk_token) as char collate utf8mb4_bin)
<> cast(in_lk_token as char collate utf8mb4_bin)
then
set v_error_ct = v_error_ct + 1;
set v_msg_out = concat(v_msg_out, '\t', cast(v_error_ct as char), '. Input Parameter: ', in_lk_token, ' not equal to, ', lower(in_lk_token), ' must contain lower case letters only.\r\n');
end if;
If I call the procedure from the command line, the procedure behaves as expected, it is only when I call the procedure from within HeidiSQL that the evaluation behaves unexpectedly.
I have tested this procedure with varchar() and currently I am using mediumtext, and in both cases this is evaluating to TRUE for all test cases.
The input value must also follow the format '{lk_xy}' where x and y are the only characters that can be changed. I am saying this because there may be something strange going on with how HS treats string values before it is passed to to MariaDB.
While trying to trouble shoot, I also tried the following SQL from a query tab:
select 'True' `with_cast_should_be_true`
where cast(lower('{lk_aZ') as char collate utf8mb4_bin)
<> cast('{lk_aZ}' as char collate utf8mb4_bin);
select 'True' `should_be_true`
where lower('{lk_aZ}')
<> '{lk_aZ}';
Since the second select statement is not true even though the two sides are not equal, I thought that the issue was possibly caused by a collation problem, though if this is the cause of the problem, the direct cast in the if statement should have fixed the issue.
Does anyone have any thoughts or ideas that could help me figure out what is causing this issue?