From 4eace27fa759f21dda281c03edcc900109e807eb Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Thu, 27 Feb 2020 15:38:06 +0100 Subject: [PATCH] TT#76457 lnp_number lookup Change-Id: Icfe6c6aa52f20810aaf4b4bbcf519b1a453e1081 (cherry picked from commit 60cf0621d1ec488bfb13228055ec4726c483b224) --- db_scripts/diff/15580_not_replicated.down | 4 +++ db_scripts/diff/15580_not_replicated.up | 38 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 db_scripts/diff/15580_not_replicated.down create mode 100644 db_scripts/diff/15580_not_replicated.up diff --git a/db_scripts/diff/15580_not_replicated.down b/db_scripts/diff/15580_not_replicated.down new file mode 100644 index 00000000..d0621869 --- /dev/null +++ b/db_scripts/diff/15580_not_replicated.down @@ -0,0 +1,4 @@ +SET sql_log_bin=0; +use billing; + +drop function get_lnp_number_id; diff --git a/db_scripts/diff/15580_not_replicated.up b/db_scripts/diff/15580_not_replicated.up new file mode 100644 index 00000000..08ce291b --- /dev/null +++ b/db_scripts/diff/15580_not_replicated.up @@ -0,0 +1,38 @@ +SET sql_log_bin=0; +use billing; + +delimiter ;; + +create function get_lnp_number_id( + _destination varchar(511), + _epoch decimal(13,3) +) returns int(11) +deterministic reads sql data +begin + + declare _destination_prefix varchar(511); + declare _i int(3); + declare _number_id int(11); + + set _i = length(_destination); + + destination_loop: loop + if _i < 0 or _number_id is not null then + leave destination_loop; + end if; + set _destination_prefix = substr(coalesce(_destination,""),1,_i); + set _number_id = (select id from billing.lnp_numbers + use index (number_idx) + where number = _destination_prefix + and (start <= from_unixtime(_epoch) or start is null) + and (end > from_unixtime(_epoch) or end is null) + limit 1); + set _i = _i - 1; + end loop destination_loop; + + return _number_id; + +end;; + +delimiter ; +