Refactors code 173

This commit is contained in:
Guido Fioravantti 2015-10-27 10:33:15 +01:00
parent 58b2705383
commit 32c729e464

View File

@ -11,6 +11,7 @@ DECLARE
usedspace INTEGER; usedspace INTEGER;
ident TEXT; ident TEXT;
origident TEXT; origident TEXT;
candrelname TEXT;
i INTEGER; i INTEGER;
BEGIN BEGIN
@ -19,13 +20,13 @@ BEGIN
usedspace := usedspace + coalesce(octet_length(prefix), 0); usedspace := usedspace + coalesce(octet_length(prefix), 0);
usedspace := usedspace + coalesce(octet_length(suffix), 0); usedspace := usedspace + coalesce(octet_length(suffix), 0);
relname := _CDB_Octet_Truncate(relname, maxlen - usedspace); candrelname := _CDB_Octet_Truncate(relname, maxlen - usedspace);
IF relname = '' THEN IF candrelname = '' THEN
PERFORM _CDB_Error('prefixes are to long to generate a valid identifier', '_CDB_Unique_Identifier'); PERFORM _CDB_Error('prefixes are to long to generate a valid identifier', '_CDB_Unique_Identifier');
END IF; END IF;
ident := coalesce(prefix, '') || relname || coalesce(suffix, ''); ident := coalesce(prefix, '') || candrelname || coalesce(suffix, '');
i := 0; i := 0;
origident := ident; origident := ident;
@ -68,6 +69,7 @@ DECLARE
maxlen CONSTANT INTEGER := 63; maxlen CONSTANT INTEGER := 63;
rec RECORD; rec RECORD;
candcolname TEXT;
usedspace INTEGER; usedspace INTEGER;
ident TEXT; ident TEXT;
origident TEXT; origident TEXT;
@ -79,13 +81,13 @@ BEGIN
usedspace := usedspace + coalesce(octet_length(prefix), 0); usedspace := usedspace + coalesce(octet_length(prefix), 0);
usedspace := usedspace + coalesce(octet_length(suffix), 0); usedspace := usedspace + coalesce(octet_length(suffix), 0);
colname := _CDB_Octet_Truncate(colname, maxlen - usedspace); candcolname := _CDB_Octet_Truncate(colname, maxlen - usedspace);
IF colname = '' THEN IF candcolname = '' THEN
PERFORM _CDB_Error('prefixes are to long to generate a valid identifier', '_CDB_Unique_Column_Identifier'); PERFORM _CDB_Error('prefixes are to long to generate a valid identifier', '_CDB_Unique_Column_Identifier');
END IF; END IF;
ident := coalesce(prefix, '') || colname || coalesce(suffix, ''); ident := coalesce(prefix, '') || candcolname || coalesce(suffix, '');
i := 0; i := 0;
origident := ident; origident := ident;
@ -140,15 +142,15 @@ BEGIN
examined := octet_length(string); examined := octet_length(string);
IF expected = examined THEN IF expected = examined THEN
RETURN SUBSTRING(string from 1 for max_octets); RETURN left(string, max_octets);
END IF; END IF;
i := max_octets / extcharlen; i := max_octets / extcharlen;
WHILE octet_length(SUBSTRING(string from 1 for i)) <= max_octets LOOP WHILE octet_length(left(string, i)) <= max_octets LOOP
i := i + 1; i := i + 1;
END LOOP; END LOOP;
RETURN SUBSTRING(string from 1 for (i - 1)); RETURN left(string, (i - 1));
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql';