1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

MDEV-30879 Add support for up to BASE 62 to CONV()

BASE 62 uses 0-9, A-Z and then a-z to give the numbers 0-61. This patch
increases the range of the string functions to cover this.

Based on ideas and tests in PR #2589, but re-written into the charset
functions.

Includes fix by Sergei, UBSAN complained:
ctype-simple.c:683:38: runtime error: negation of -9223372036854775808
cannot be represented in type 'long long int'; cast to an unsigned
type to negate this value to itself

Co-authored-by: Weijun Huang <huangweijun1001@gmail.com>
Co-authored-by: Sergei Golubchik <serg@mariadb.org>
This commit is contained in:
Andrew Hutchings
2023-11-17 17:41:23 +00:00
committed by Andrew Hutchings
parent be6d48fd53
commit f552febe43
10 changed files with 160 additions and 22 deletions

View File

@ -570,7 +570,7 @@ SELECT lpad(12345, 5, "#");
#
SELECT conv(71, 10, 36), conv('1Z', 36, 10);
SELECT conv(71, 10, 37), conv('1Z', 37, 10), conv(0,1,10),conv(0,0,10), conv(0,-1,10);
SELECT conv(71, 10, 63), conv('1Z', 63, 10), conv(0,1,10),conv(0,0,10), conv(0,-1,10);
#
# Bug in SUBSTRING when mixed with CONCAT and ORDER BY (Bug #3089)
@ -2481,3 +2481,40 @@ select aes_encrypt(a,a) is null from (values('a'),(NULL),('b')) x;
--echo #
--echo # End of 11.2 tests
--echo #
--echo #
--echo # MDEV-30879 Add conversion to based 62 for CONV function
--echo #
SELECT CONV('1z', 62, 10);
SELECT CONV('1Z', 62, 10);
SELECT CONV('-1Z', 62, 10);
SELECT CONV('-1Z', -62, 10);
SELECT CONV('-1Z', 62, -10);
SELECT CONV('-1Z', -62, -10);
# Check limits
SELECT CONV('AzL8n0Y58m7', 62, 10);
SELECT CONV('LygHa16AHYE', 62, 10);
SELECT CONV('LygHa16AHYF', 62, 10);
# Overflow doesn't appear to warn, but does overflow
SELECT CONV('LygHa16AHZ0', 62, 10);
SELECT CONV('-AzL8n0Y58m7', -62, -10);
SELECT CONV('-AzL8n0Y58m8', -62, -10);
SELECT CONV('-AzL8n0Y58m9', -62, -10);
SELECT CONV('-LygHa16AHZ0', -62, -10);
# Should NULL
SELECT CONV('LygHa16AHYF', 63, 10);
SELECT CONV(18446744073709551615, 10, 63);
# Test 10 -> 62
SELECT CONV(18446744073709551615, 10, 62);
SELECT CONV(-9223372036854775808, -10, -62);
--echo #
--echo # End of 11.4 tests
--echo #