Uses underscore prefix for private tables 173

This commit is contained in:
Guido Fioravantti
2015-10-22 19:00:18 +02:00
parent 58deeb088d
commit aed8671e77
2 changed files with 19 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
-- UTF8 safe and lenght aware. Find a unique identifier with a given prefix
-- and/or suffix and withing a schema.
CREATE OR REPLACE FUNCTION cartodb.CDB_Unique_Identifier(prefix TEXT, relname TEXT, suffix TEXT, schema TEXT DEFAULT NULL)
CREATE OR REPLACE FUNCTION cartodb._CDB_Unique_Identifier(prefix TEXT, relname TEXT, suffix TEXT, schema TEXT DEFAULT NULL)
RETURNS TEXT
AS $$
DECLARE
@@ -17,10 +17,10 @@ BEGIN
usedspace := usedspace + coalesce(octet_length(prefix), 0);
usedspace := usedspace + coalesce(octet_length(suffix), 0);
relname := CDB_Octet_Trim(relname, usedspace + octet_length(relname) - maxlen);
relname := _CDB_Octet_Trim(relname, usedspace + octet_length(relname) - maxlen);
IF relname = '' 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;
ident := coalesce(prefix, '') || relname || coalesce(suffix, '');
@@ -52,13 +52,13 @@ BEGIN
i := i + 1;
END LOOP;
PERFORM _CDB_Error('looping too far', 'CDB_Unique_Identifier');
PERFORM _CDB_Error('looping too far', '_CDB_Unique_Identifier');
END;
$$ LANGUAGE 'plpgsql';
-- UTF8 safe and lenght aware. Find a unique identifier for a column with a given prefix
-- and/or suffix and withing a realtion. If no reloid is give, all relations are examined
CREATE OR REPLACE FUNCTION cartodb.CDB_Unique_Column_Identifier(prefix TEXT, relname TEXT, suffix TEXT, reloid REGCLASS DEFAULT NULL)
CREATE OR REPLACE FUNCTION cartodb._CDB_Unique_Column_Identifier(prefix TEXT, relname TEXT, suffix TEXT, reloid REGCLASS DEFAULT NULL)
RETURNS TEXT
AS $$
DECLARE
@@ -75,10 +75,10 @@ BEGIN
usedspace := usedspace + coalesce(octet_length(prefix), 0);
usedspace := usedspace + coalesce(octet_length(suffix), 0);
relname := CDB_Octet_Trim(relname, usedspace + octet_length(relname) - maxlen);
relname := _CDB_Octet_Trim(relname, usedspace + octet_length(relname) - maxlen);
IF relname = '' 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_Column_Identifier');
END IF;
ident := coalesce(prefix, '') || relname || coalesce(suffix, '');
@@ -114,13 +114,13 @@ BEGIN
i := i + 1;
END LOOP;
PERFORM _CDB_Error('looping too far', 'CDB_Unique_Column_Identifier');
PERFORM _CDB_Error('looping too far', '_CDB_Unique_Column_Identifier');
END;
$$ LANGUAGE 'plpgsql';
-- Trims the end of a given string by the given number of octets taking care
-- not to leave characters in half. UTF8 safe.
CREATE OR REPLACE FUNCTION cartodb.CDB_Octet_Trim(tostrip TEXT, octets INTEGER)
CREATE OR REPLACE FUNCTION cartodb._CDB_Octet_Trim(tostrip TEXT, octets INTEGER)
RETURNS TEXT
AS $$
DECLARE