[PATCH 1 of 4 saem_ref v2] [ark] Account for control char length in gen_ark_name()

Denis Laxalde denis.laxalde at logilab.fr
Thu Feb 15 15:04:03 CET 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1518701341 -3600
#      Thu Feb 15 14:29:01 2018 +0100
# Node ID 828385bddd63694089ede151c4b309a8d0683f1f
# Parent  f584d40d5f5a3caeded786b72d831f068a1ca00d
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 828385bddd63
# EXP-Topic ark/qualifiers
[ark] Account for control char length in gen_ark_name()

Instead of assuming it will always be 1-character long.

diff --git a/cubicweb_saem_ref/schema/ark.postgres.sql b/cubicweb_saem_ref/schema/ark.postgres.sql
--- a/cubicweb_saem_ref/schema/ark.postgres.sql
+++ b/cubicweb_saem_ref/schema/ark.postgres.sql
@@ -16,11 +16,14 @@ DECLARE
     characters TEXT;
     next_char TEXT;
     tail TEXT;
+    break_length INTEGER;
 BEGIN
     ASSERT len > length(prefix) + length(control_char);
     letters := 'bcdfghjkmnpqrstvwxz';
     numbers := '0123456789';
     characters := letters || numbers;
+    -- Length of "ark" at which we break the loop.
+    break_length = len - length(control_char);
     -- Prefix ARK identifier.
     ark := prefix;
     LOOP
@@ -32,7 +35,7 @@ BEGIN
             next_char := random_char(characters);
         END IF;
         ark := ark || next_char;
-        IF length(ark) = len - 1 THEN
+        IF length(ark) = break_length THEN
             EXIT;
         END IF;
     END LOOP;



More information about the saem-devel mailing list