From 0d07184b5a0e6e10cdd9a0e5cdeef300d8d90e6f Mon Sep 17 00:00:00 2001 From: Nick Dobie <85509245+prewittridge-nick@users.noreply.github.com> Date: Wed, 17 Aug 2022 16:03:26 -0500 Subject: [PATCH] fix: Allow for encoding bigint Internal functions were casting bigint to int which would cause an out of bounds error if an integer larger than int was passed. --- src/4_create_hashids_hash.sql | 2 +- src/6_create_hashids_encode_list.sql | 2 +- src/all_hashids.sql | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/4_create_hashids_hash.sql b/src/4_create_hashids_hash.sql index 6b1b5d0..1750baa 100644 --- a/src/4_create_hashids_hash.sql +++ b/src/4_create_hashids_hash.sql @@ -21,7 +21,7 @@ BEGIN --raise notice 'SUBSTRING(%, %, 1): %', p_alphabet, v_pos, (SUBSTRING(p_alphabet, v_pos, 1)); --raise notice '% || % == %', SUBSTRING(p_alphabet, v_pos, 1), v_hash, SUBSTRING(p_alphabet, v_pos, 1) || v_hash; v_hash := SUBSTRING(p_alphabet, v_pos, 1) || v_hash; - p_input := CAST((p_input / v_alphabet_length) as int); + p_input := CAST((p_input / v_alphabet_length) as bigint); --raise notice 'p_input %', p_input; IF p_input <= 0 THEN EXIT; diff --git a/src/6_create_hashids_encode_list.sql b/src/6_create_hashids_encode_list.sql index 0e9f5a3..cfa29d0 100644 --- a/src/6_create_hashids_encode_list.sql +++ b/src/6_create_hashids_encode_list.sql @@ -35,7 +35,7 @@ $$ v_count int = array_length(p_numbers, 1); v_i int = 0; v_id int = 0; - v_number int; + v_number bigint; v_guardIndex int; v_guard char(1); v_halfLength int; diff --git a/src/all_hashids.sql b/src/all_hashids.sql index 9649c21..c890251 100644 --- a/src/all_hashids.sql +++ b/src/all_hashids.sql @@ -280,7 +280,7 @@ BEGIN --raise notice 'SUBSTRING(%, %, 1): %', p_alphabet, v_pos, (SUBSTRING(p_alphabet, v_pos, 1)); --raise notice '% || % == %', SUBSTRING(p_alphabet, v_pos, 1), v_hash, SUBSTRING(p_alphabet, v_pos, 1) || v_hash; v_hash := SUBSTRING(p_alphabet, v_pos, 1) || v_hash; - p_input := CAST((p_input / v_alphabet_length) as int); + p_input := CAST((p_input / v_alphabet_length) as bigint); --raise notice 'p_input %', p_input; IF p_input <= 0 THEN EXIT; @@ -355,7 +355,7 @@ $$ v_count int = array_length(p_numbers, 1); v_i int = 0; v_id int = 0; - v_number int; + v_number bigint; v_guardIndex int; v_guard char(1); v_halfLength int;