Uses underscore prefix for private tables 173
This commit is contained in:
parent
58deeb088d
commit
aed8671e77
@ -428,7 +428,7 @@ END;
|
|||||||
$$ LANGUAGE 'plpgsql';
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
|
||||||
-- DEPRECATED: Use cartodb.CDB_Unique_Identifier since it's UTF8 Safe and length
|
-- DEPRECATED: Use _CDB_Unique_Identifier since it's UTF8 Safe and length
|
||||||
-- aware. Find a unique relation name in the given schema, starting from the
|
-- aware. Find a unique relation name in the given schema, starting from the
|
||||||
-- template given. If the template is already unique, just return it;
|
-- template given. If the template is already unique, just return it;
|
||||||
-- otherwise, append an increasing integer until you find a unique variant.
|
-- otherwise, append an increasing integer until you find a unique variant.
|
||||||
@ -441,7 +441,7 @@ DECLARE
|
|||||||
newrelname TEXT;
|
newrelname TEXT;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
RAISE ERROR '_CDB_Unique_Relation_Name is DEPRECATED. Use CDB_Unique_Identifier(prefix TEXT, relname TEXT, suffix TEXT, schema TEXT DEFAULT NULL)';
|
RAISE ERROR '_CDB_Unique_Relation_Name is DEPRECATED. Use _CDB_Unique_Identifier(prefix TEXT, relname TEXT, suffix TEXT, schema TEXT DEFAULT NULL)';
|
||||||
|
|
||||||
i := 0;
|
i := 0;
|
||||||
newrelname := relationname;
|
newrelname := relationname;
|
||||||
@ -471,7 +471,7 @@ END;
|
|||||||
$$ LANGUAGE 'plpgsql';
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
|
||||||
-- DEPRECATED: Use cartodb.CDB_Unique_Column_Identifier since it's UTF8 Safe and length
|
-- DEPRECATED: Use _CDB_Unique_Column_Identifier since it's UTF8 Safe and length
|
||||||
-- aware. Find a unique column name in the given relation, starting from the
|
-- aware. Find a unique column name in the given relation, starting from the
|
||||||
-- column name given. If the column name is already unique, just return it;
|
-- column name given. If the column name is already unique, just return it;
|
||||||
-- otherwise, append an increasing integer until you find a unique variant.
|
-- otherwise, append an increasing integer until you find a unique variant.
|
||||||
@ -484,7 +484,7 @@ DECLARE
|
|||||||
newcolname TEXT;
|
newcolname TEXT;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
RAISE ERROR '_CDB_Unique_Column_Name is DEPRECATED. Use CDB_Unique_Column_Identifier(prefix TEXT, relname TEXT, suffix TEXT, reloid REGCLASS DEFAULT NULL)';
|
RAISE ERROR '_CDB_Unique_Column_Name is DEPRECATED. Use _CDB_Unique_Column_Identifier(prefix TEXT, relname TEXT, suffix TEXT, reloid REGCLASS DEFAULT NULL)';
|
||||||
|
|
||||||
i := 0;
|
i := 0;
|
||||||
newcolname := columnname;
|
newcolname := columnname;
|
||||||
@ -596,7 +596,7 @@ BEGIN
|
|||||||
PERFORM _CDB_SQL(
|
PERFORM _CDB_SQL(
|
||||||
Format('ALTER TABLE %s RENAME COLUMN %s TO %I',
|
Format('ALTER TABLE %s RENAME COLUMN %s TO %I',
|
||||||
reloid::text, rec.attname,
|
reloid::text, rec.attname,
|
||||||
cartodb.CDB_Unique_Column_Identifier(NULL, const.pkey, NULL, reloid)),
|
cartodb._CDB_Unique_Column_Identifier(NULL, const.pkey, NULL, reloid)),
|
||||||
'_CDB_Has_Usable_Primary_ID');
|
'_CDB_Has_Usable_Primary_ID');
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
@ -613,7 +613,7 @@ BEGIN
|
|||||||
|
|
||||||
PERFORM _CDB_SQL(
|
PERFORM _CDB_SQL(
|
||||||
Format('ALTER TABLE %s RENAME COLUMN %s TO %I',
|
Format('ALTER TABLE %s RENAME COLUMN %s TO %I',
|
||||||
reloid::text, rec.attname, cartodb.CDB_Unique_Column_Identifier(NULL, const.pkey, NULL, reloid)),
|
reloid::text, rec.attname, cartodb._CDB_Unique_Column_Identifier(NULL, const.pkey, NULL, reloid)),
|
||||||
'_CDB_Has_Usable_Primary_ID');
|
'_CDB_Has_Usable_Primary_ID');
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
@ -779,7 +779,7 @@ BEGIN
|
|||||||
WHEN others THEN
|
WHEN others THEN
|
||||||
IF SQLERRM = 'parse error - invalid geometry' THEN
|
IF SQLERRM = 'parse error - invalid geometry' THEN
|
||||||
text_geom_column := false;
|
text_geom_column := false;
|
||||||
str := cartodb.CDB_Unique_Column_Identifier(NULL, r1.attname, NULL, reloid);
|
str := cartodb._CDB_Unique_Column_Identifier(NULL, r1.attname, NULL, reloid);
|
||||||
sql := Format('ALTER TABLE %s RENAME COLUMN %s TO %I', reloid::text, r1.attname, str);
|
sql := Format('ALTER TABLE %s RENAME COLUMN %s TO %I', reloid::text, r1.attname, str);
|
||||||
PERFORM _CDB_SQL(sql,'_CDB_Has_Usable_Geom');
|
PERFORM _CDB_SQL(sql,'_CDB_Has_Usable_Geom');
|
||||||
RAISE DEBUG 'CDB(_CDB_Has_Usable_Geom): %',
|
RAISE DEBUG 'CDB(_CDB_Has_Usable_Geom): %',
|
||||||
@ -791,7 +791,7 @@ BEGIN
|
|||||||
|
|
||||||
-- Just change its name so we can write a new column into that name.
|
-- Just change its name so we can write a new column into that name.
|
||||||
ELSE
|
ELSE
|
||||||
str := cartodb.CDB_Unique_Column_Identifier(NULL, r1.attname, NULL, reloid);
|
str := cartodb._CDB_Unique_Column_Identifier(NULL, r1.attname, NULL, reloid);
|
||||||
sql := Format('ALTER TABLE %s RENAME COLUMN %s TO %I', reloid::text, r1.attname, str);
|
sql := Format('ALTER TABLE %s RENAME COLUMN %s TO %I', reloid::text, r1.attname, str);
|
||||||
PERFORM _CDB_SQL(sql,'_CDB_Has_Usable_Geom');
|
PERFORM _CDB_SQL(sql,'_CDB_Has_Usable_Geom');
|
||||||
RAISE DEBUG 'CDB(_CDB_Has_Usable_Geom): %',
|
RAISE DEBUG 'CDB(_CDB_Has_Usable_Geom): %',
|
||||||
@ -968,14 +968,14 @@ BEGIN
|
|||||||
-- Put the primary key sequence in the right schema
|
-- Put the primary key sequence in the right schema
|
||||||
-- If the new table is not moving, better ensure the sequence name
|
-- If the new table is not moving, better ensure the sequence name
|
||||||
-- is unique
|
-- is unique
|
||||||
destseq := cartodb.CDB_Unique_Identifier(NULL, relname, '_' || const.pkey || '_seq', destschema);
|
destseq := cartodb._CDB_Unique_Identifier(NULL, relname, '_' || const.pkey || '_seq', destschema);
|
||||||
destseq := Format('%I.%I', destschema, destseq);
|
destseq := Format('%I.%I', destschema, destseq);
|
||||||
PERFORM _CDB_SQL(Format('CREATE SEQUENCE %s', destseq), '_CDB_Rewrite_Table');
|
PERFORM _CDB_SQL(Format('CREATE SEQUENCE %s', destseq), '_CDB_Rewrite_Table');
|
||||||
|
|
||||||
-- Salt a temporary table name if we are re-writing in place
|
-- Salt a temporary table name if we are re-writing in place
|
||||||
-- Note copyname is already escaped and safe to use as identifier
|
-- Note copyname is already escaped and safe to use as identifier
|
||||||
IF destschema = relschema THEN
|
IF destschema = relschema THEN
|
||||||
copyname := Format('%I.%I', destschema, cartodb.CDB_Unique_Identifier(NULL, destname, '_' || salt), destschema);
|
copyname := Format('%I.%I', destschema, cartodb._CDB_Unique_Identifier(NULL, destname, '_' || salt), destschema);
|
||||||
ELSE
|
ELSE
|
||||||
copyname := Format('%I.%I', destschema, destname);
|
copyname := Format('%I.%I', destschema, destname);
|
||||||
END IF;
|
END IF;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
-- UTF8 safe and lenght aware. Find a unique identifier with a given prefix
|
-- UTF8 safe and lenght aware. Find a unique identifier with a given prefix
|
||||||
-- and/or suffix and withing a schema.
|
-- 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
|
RETURNS TEXT
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -17,10 +17,10 @@ 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_Trim(relname, usedspace + octet_length(relname) - maxlen);
|
relname := _CDB_Octet_Trim(relname, usedspace + octet_length(relname) - maxlen);
|
||||||
|
|
||||||
IF relname = '' THEN
|
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;
|
END IF;
|
||||||
|
|
||||||
ident := coalesce(prefix, '') || relname || coalesce(suffix, '');
|
ident := coalesce(prefix, '') || relname || coalesce(suffix, '');
|
||||||
@ -52,13 +52,13 @@ BEGIN
|
|||||||
i := i + 1;
|
i := i + 1;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
|
||||||
PERFORM _CDB_Error('looping too far', 'CDB_Unique_Identifier');
|
PERFORM _CDB_Error('looping too far', '_CDB_Unique_Identifier');
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE 'plpgsql';
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
-- UTF8 safe and lenght aware. Find a unique identifier for a column with a given prefix
|
-- 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
|
-- 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
|
RETURNS TEXT
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -75,10 +75,10 @@ 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_Trim(relname, usedspace + octet_length(relname) - maxlen);
|
relname := _CDB_Octet_Trim(relname, usedspace + octet_length(relname) - maxlen);
|
||||||
|
|
||||||
IF relname = '' THEN
|
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;
|
END IF;
|
||||||
|
|
||||||
ident := coalesce(prefix, '') || relname || coalesce(suffix, '');
|
ident := coalesce(prefix, '') || relname || coalesce(suffix, '');
|
||||||
@ -114,13 +114,13 @@ BEGIN
|
|||||||
i := i + 1;
|
i := i + 1;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
|
||||||
PERFORM _CDB_Error('looping too far', 'CDB_Unique_Column_Identifier');
|
PERFORM _CDB_Error('looping too far', '_CDB_Unique_Column_Identifier');
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE 'plpgsql';
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
-- Trims the end of a given string by the given number of octets taking care
|
-- Trims the end of a given string by the given number of octets taking care
|
||||||
-- not to leave characters in half. UTF8 safe.
|
-- 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
|
RETURNS TEXT
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
|
Loading…
Reference in New Issue
Block a user