diff --git a/procedures/insertEntityDataType.sql b/procedures/insertEntityDataType.sql index 78df168f72972a2ccc8dd95792e9849d0715aaf9..bd75099ba5317d997ca7a6bc9b4ae00d5f0a04c7 100644 --- a/procedures/insertEntityDataType.sql +++ b/procedures/insertEntityDataType.sql @@ -28,16 +28,16 @@ DELIMITER // * ---------- * PropertyID : VARCHAR(255) * The property id. - * DataType : VARCHAR(255) - * The data type, e.g. "DOUBLE", "Person" + * DataTypeID : VARCHAR(255) + * The data type id (not the name!) */ -CREATE PROCEDURE db_5_0.insertEntityDataType(in PropertyID VARCHAR(255), in DataType VARCHAR(255)) +CREATE PROCEDURE db_5_0.insertEntityDataType(in PropertyID VARCHAR(255), in DataTypeID VARCHAR(255)) BEGIN DECLARE InternalPropertyID INT UNSIGNED DEFAULT NULL; SELECT internal_id INTO InternalPropertyID FROM entity_ids WHERE id=PropertyID; - INSERT INTO data_type (domain_id, entity_id, property_id, datatype) SELECT 0, 0, InternalPropertyID, ( SELECT entity_id FROM name_data WHERE domain_id = 0 AND property_id = 20 AND value = DataType LIMIT 1); + INSERT INTO data_type (domain_id, entity_id, property_id, datatype) SELECT 0, 0, InternalPropertyID, ( SELECT internal_id FROM entity_ids WHERE id = DataTypeID); END; diff --git a/procedures/insertEntityProperty.sql b/procedures/insertEntityProperty.sql index ee26c168612cacf93f19576e21e36d23ff4270ca..cd26e62bade4fbb59c45e9c5af90bd7cca19ba43 100644 --- a/procedures/insertEntityProperty.sql +++ b/procedures/insertEntityProperty.sql @@ -76,9 +76,20 @@ BEGIN DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL; DECLARE InternalDomainID INT UNSIGNED DEFAULT 0; - SELECT temp.internal_id INTO InternalDomainID FROM (SELECT internal_id AS internal_id FROM entity_ids WHERE id = DomainID UNION SELECT DomainID AS internal_id) AS temp LIMIT 1; - SELECT temp.internal_id INTO InternalEntityID FROM (SELECT internal_id AS internal_id FROM entity_ids WHERE id = EntityID UNION SELECT EntityID AS internal_id) AS temp LIMIT 1; - SELECT temp.internal_id INTO InternalPropertyID FROM (SELECT internal_id AS internal_id FROM entity_ids WHERE id = PropertyID UNION SELECT PropertyID AS internal_id) AS temp LIMIT 1; + SELECT internal_id INTO InternalDomainID FROM entity_ids WHERE id = DomainID; + -- When DomainID != 0 the EntityID could possibly be a 'replacement id' + -- which are internal ids by definition (and do not have external + -- equivalents). + IF LOCATE("$", EntityID) = 1 THEN + SET InternalEntityID=SUBSTRING(EntityID, 2); + ELSE + SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID; + END IF; + IF LOCATE("$", PropertyID) = 1 THEN + SET InternalPropertyID=SUBSTRING(PropertyID, 2); + ELSE + SELECT internal_id INTO InternalPropertyID FROM entity_ids WHERE id = PropertyID; + END IF; CASE Datatable WHEN 'double_data' THEN @@ -109,8 +120,10 @@ BEGIN SELECT 0 from `ReferenceValueIVersion_WAS_NULL`; END IF; + ELSEIF LOCATE("$", PropertyValue) = 1 THEN + SET ReferenceValue = SUBSTRING(PropertyValue, 2); ELSE - SELECT temp.internal_id INTO ReferenceValue FROM (SELECT internal_id AS internal_id FROM entity_ids WHERE id = PropertyValue UNION SELECT PropertyValue AS internal_id) AS temp LIMIT 1; + SELECT internal_id INTO ReferenceValue FROM entity_ids WHERE id = PropertyValue; END IF; diff --git a/procedures/registerReplacementIds.sql b/procedures/registerReplacementIds.sql index 2fc04ccb082ef080b7b7ae238b32cc3a7f6b415f..fed8835d632c3334771318e29640a0ba5d425833 100644 --- a/procedures/registerReplacementIds.sql +++ b/procedures/registerReplacementIds.sql @@ -36,7 +36,7 @@ BEGIN SET ED = ED + 1; END WHILE; - SELECT e.id as ReplacementID FROM entities AS e WHERE e.Role='_REPLACEMENT' and e.id!=0; + SELECT CONCAT("$", e.id) as ReplacementID FROM entities AS e WHERE e.Role='_REPLACEMENT' and e.id!=0; END; // diff --git a/procedures/retrieveEntity.sql b/procedures/retrieveEntity.sql index a4264e3d44fd0b9cddbd24192b118add7bdc4e15..92434bda9de56240b2055c8bcb8a192626defca7 100644 --- a/procedures/retrieveEntity.sql +++ b/procedures/retrieveEntity.sql @@ -42,8 +42,9 @@ drop procedure if exists db_5_0.retrieveEntity // * * ResultSet * --------- - * Tuple of (Datatype, Collection, EntityID, EntityName, EntityDesc, - * EntityRole, FileSize, FilePath, FileHash, ACL, Version) + * Tuple of (DatatypeID, DatatypeName, Collection, EntityID, EntityName, + * EntityDesc, EntityRole, FileSize, FilePath, FileHash, ACL, + * Version) */ create procedure db_5_0.retrieveEntity( in EntityID VARCHAR(255), @@ -52,7 +53,8 @@ retrieveEntityBody: BEGIN DECLARE FilePath VARCHAR(255) DEFAULT NULL; DECLARE FileSize VARCHAR(255) DEFAULT NULL; DECLARE FileHash VARCHAR(255) DEFAULT NULL; - DECLARE DatatypeID INT UNSIGNED DEFAULT NULL; + DECLARE DatatypeID VARCHAR(255) DEFAULT NULL; + DECLARE InternalDatatypeID INT UNSIGNED DEFAULT NULL; DECLARE CollectionName VARCHAR(255) DEFAULT NULL; DECLARE IsHead BOOLEAN DEFAULT TRUE; DECLARE IVersion INT UNSIGNED DEFAULT NULL; @@ -94,7 +96,7 @@ retrieveEntityBody: BEGIN LIMIT 1; SELECT datatype - INTO DatatypeID + INTO InternalDatatypeID FROM archive_data_type WHERE domain_id = 0 AND entity_id = 0 @@ -116,10 +118,10 @@ retrieveEntityBody: BEGIN ( SELECT value FROM ( SELECT value FROM name_data WHERE domain_id = 0 - AND entity_ID = DatatypeID + AND entity_id = InternalDatatypeID AND property_id = 20 - UNION SELECT DatatypeID AS value - ) AS tmp LIMIT 1 ) AS Datatype, + ) AS tmp LIMIT 1 ) AS DatatypeName, + ( SELECT id FROM entity_ids WHERE internal_id=InternalDatatypeID ) AS DatatypeID, CollectionName AS Collection, EntityID AS EntityID, ( SELECT value FROM archive_name_data @@ -152,7 +154,7 @@ retrieveEntityBody: BEGIN WHERE file_id = InternalEntityID LIMIT 1; - SELECT dt.datatype INTO DatatypeID + SELECT dt.datatype INTO InternalDatatypeID FROM data_type as dt WHERE dt.domain_id=0 AND dt.entity_id=0 @@ -169,8 +171,9 @@ retrieveEntityBody: BEGIN SELECT ( SELECT value FROM name_data WHERE domain_id = 0 - AND entity_id = DatatypeID - AND property_id = 20 LIMIT 1 ) AS Datatype, + AND entity_id = InternalDatatypeID + AND property_id = 20 LIMIT 1 ) AS DatatypeName, + ( SELECT id FROM entity_ids WHERE internal_id=InternalDatatypeID ) AS DatatypeID, CollectionName AS Collection, EntityID AS EntityID, ( SELECT value FROM name_data diff --git a/procedures/retrieveEntityOverrides.sql b/procedures/retrieveEntityOverrides.sql index f552a2c3b7ceafae5255ee69655af426f44b8bb7..4852cccbb85ce4857c43e715183c7065e44b84e7 100644 --- a/procedures/retrieveEntityOverrides.sql +++ b/procedures/retrieveEntityOverrides.sql @@ -41,7 +41,8 @@ delimiter // * collection_override, # e.g. LIST * name_override, # the name * desc_override, # the description - * type_override, # the datatype, e.g. DOUBLE + * type_name_override, # the datatype, e.g. DOUBLE + * type_id_override, # data type id. * entity_id, # same as input EntityID * InternalPropertyID, # internal property id, to be used when property_id * # is NULL because a replacement is used. @@ -60,11 +61,12 @@ retrieveOverridesBody: BEGIN -- When DomainID != 0 the EntityID could possibly be a 'replacement id' -- which are internal ids by definition (and do not have external - -- equivalents). That's why we do the UNION here, falling back to the - -- EntityID. - SELECT temp.internal_id INTO InternalEntityID - FROM (SELECT internal_id AS internal_id FROM - entity_ids WHERE id = EntityID UNION SELECT EntityID AS internal_id) AS temp LIMIT 1; + -- equivalents). + IF LOCATE("$", EntityID) = 1 THEN + SET InternalEntityID=SUBSTRING(EntityID, 2); + ELSE + SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID; + END IF; -- DomainID != 0 are always normal (i.e. external) Entity ids. SELECT internal_id INTO InternalDomainID from entity_ids WHERE id = DomainID; @@ -94,9 +96,10 @@ retrieveOverridesBody: BEGIN NULL AS collection_override, name AS name_override, NULL AS desc_override, - NULL AS type_override, + NULL AS type_name_override, + NULL AS type_id_override, EntityID AS entity_id, - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id FROM archive_name_overrides WHERE domain_id = InternalDomainID @@ -110,9 +113,10 @@ retrieveOverridesBody: BEGIN NULL AS collection_override, NULL AS name_override, description AS desc_override, - NULL AS type_override, + NULL AS type_name_override, + NULL AS type_id_override, EntityID AS entity_id, - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id FROM archive_desc_overrides WHERE domain_id = InternalDomainID @@ -126,13 +130,14 @@ retrieveOverridesBody: BEGIN NULL AS collection_override, NULL AS name_override, NULL AS desc_override, - IFNULL((SELECT value FROM name_data + (SELECT value FROM name_data WHERE domain_id = 0 AND entity_id = datatype AND property_id = 20 - LIMIT 1), datatype) AS type_override, + LIMIT 1) AS type_name_override, + (SELECT id FROM entity_ids WHERE internal_id = datatype) AS type_id_override, EntityID AS entity_id, - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id FROM archive_data_type WHERE domain_id = InternalDomainID @@ -146,9 +151,10 @@ retrieveOverridesBody: BEGIN collection AS collection_override, NULL AS name_override, NULL AS desc_override, - NULL AS type_override, + NULL AS type_name_override, + NULL AS type_id_override, EntityID AS entity_id, - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id FROM archive_collection_type WHERE domain_id = InternalDomainID @@ -163,9 +169,10 @@ retrieveOverridesBody: BEGIN NULL AS collection_override, name AS name_override, NULL AS desc_override, - NULL AS type_override, + NULL AS type_name_override, + NULL AS type_id_override, EntityID AS entity_id, - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id FROM name_overrides WHERE domain_id = InternalDomainID @@ -177,9 +184,10 @@ retrieveOverridesBody: BEGIN NULL AS collection_override, NULL AS name_override, description AS desc_override, - NULL AS type_override, + NULL AS type_name_override, + NULL AS type_id_override, EntityID AS entity_id, - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id FROM desc_overrides WHERE domain_id = InternalDomainID @@ -191,12 +199,13 @@ retrieveOverridesBody: BEGIN NULL AS collection_override, NULL AS name_override, NULL AS desc_override, - IFNULL((SELECT value FROM name_data + (SELECT value FROM name_data WHERE domain_id = 0 AND entity_ID = datatype - AND property_id = 20 LIMIT 1), datatype) AS type_override, + AND property_id = 20 LIMIT 1) AS type_name_override, + (SELECT id FROM entity_ids WHERE internal_id = datatype) AS type_id_override, EntityID AS entity_id, - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id FROM data_type WHERE domain_id = InternalDomainID @@ -208,9 +217,10 @@ retrieveOverridesBody: BEGIN collection AS collection_override, NULL AS name_override, NULL AS desc_override, - NULL AS type_override, + NULL AS type_name_override, + NULL AS type_id_override, EntityID AS entity_id, - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id FROM collection_type WHERE domain_id = InternalDomainID diff --git a/procedures/retrieveEntityProperties.sql b/procedures/retrieveEntityProperties.sql index 024f3b0cf2dfb6a83eb41078ec30060c88693f2c..b948af286e6c38a934c65131f2a6133b426d609c 100644 --- a/procedures/retrieveEntityProperties.sql +++ b/procedures/retrieveEntityProperties.sql @@ -66,9 +66,12 @@ retrieveEntityPropertiesBody: BEGIN -- When DomainID != 0 the EntityID could possibly be a 'replacement id' -- which are internal ids by definition (and do not have external - -- equivalents). That's why we do the UNION here, falling back to the - -- EntityID. - SELECT temp.internal_id INTO InternalEntityID FROM (SELECT internal_id AS internal_id FROM entity_ids WHERE id = EntityID UNION SELECT EntityID AS internal_id) AS temp LIMIT 1; + -- equivalents). + IF LOCATE("$", EntityID) = 1 THEN + SET InternalEntityID=SUBSTRING(EntityID, 2); + ELSE + SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID; + END IF; -- DomainID != 0 are always normal (i.e. external) Entity ids. SELECT internal_id INTO InternalDomainID from entity_ids WHERE id = DomainID; @@ -95,7 +98,7 @@ retrieveEntityPropertiesBody: BEGIN #-- double properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, value AS PropertyValue, status AS PropertyStatus, @@ -109,7 +112,7 @@ retrieveEntityPropertiesBody: BEGIN #-- integer properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, value AS PropertyValue, status AS PropertyStatus, @@ -123,7 +126,7 @@ retrieveEntityPropertiesBody: BEGIN #-- date properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, CONCAT(value, '.NULL.NULL') AS PropertyValue, status AS PropertyStatus, @@ -137,7 +140,7 @@ retrieveEntityPropertiesBody: BEGIN #-- datetime properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns)) AS PropertyValue, @@ -152,7 +155,7 @@ retrieveEntityPropertiesBody: BEGIN #-- text properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, value AS PropertyValue, status AS PropertyStatus, @@ -166,7 +169,7 @@ retrieveEntityPropertiesBody: BEGIN #-- enum properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, value AS PropertyValue, status AS PropertyStatus, @@ -180,11 +183,11 @@ retrieveEntityPropertiesBody: BEGIN #-- reference properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, IF(value_iversion IS NULL, IF(status = "REPLACEMENT", - value, + CONCAT("$", value), ( SELECT id FROM entity_ids WHERE internal_id = value )), -- make it "value@version" if necessary CONCAT( @@ -202,7 +205,7 @@ retrieveEntityPropertiesBody: BEGIN #-- null properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, NULL AS PropertyValue, status AS PropertyStatus, @@ -216,7 +219,7 @@ retrieveEntityPropertiesBody: BEGIN #-- name properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, value AS PropertyValue, status AS PropertyStatus, @@ -233,7 +236,7 @@ retrieveEntityPropertiesBody: BEGIN #-- double properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, value AS PropertyValue, status AS PropertyStatus, @@ -246,7 +249,7 @@ retrieveEntityPropertiesBody: BEGIN #-- integer properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, value AS PropertyValue, status AS PropertyStatus, @@ -259,7 +262,7 @@ retrieveEntityPropertiesBody: BEGIN #-- date properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, CONCAT(value, '.NULL.NULL') AS PropertyValue, status AS PropertyStatus, @@ -272,7 +275,7 @@ retrieveEntityPropertiesBody: BEGIN #-- datetime properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns)) AS PropertyValue, @@ -286,7 +289,7 @@ retrieveEntityPropertiesBody: BEGIN #-- text properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, value AS PropertyValue, status AS PropertyStatus, @@ -299,7 +302,7 @@ retrieveEntityPropertiesBody: BEGIN #-- enum properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, value AS PropertyValue, status AS PropertyStatus, @@ -312,11 +315,11 @@ retrieveEntityPropertiesBody: BEGIN #-- reference properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, IF(value_iversion IS NULL, IF(status = "REPLACEMENT", - value, + CONCAT("$", value), ( SELECT id FROM entity_ids WHERE internal_id = value )), -- make it "value@version" if necessary CONCAT( @@ -333,7 +336,7 @@ retrieveEntityPropertiesBody: BEGIN #-- null properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, NULL AS PropertyValue, status AS PropertyStatus, @@ -346,7 +349,7 @@ retrieveEntityPropertiesBody: BEGIN #-- name properties SELECT - property_id AS InternalPropertyID, + CONCAT("$", property_id) AS InternalPropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID, value AS PropertyValue, status AS PropertyStatus, diff --git a/procedures/updateEntity.sql b/procedures/updateEntity.sql index 3e0a53c11c2899bdea1fb9d90466ca0de0aa8cb1..88538bbd38a2b3ead5caae9b379b9d202e5a3789 100644 --- a/procedures/updateEntity.sql +++ b/procedures/updateEntity.sql @@ -35,7 +35,7 @@ CREATE PROCEDURE db_5_0.updateEntity( in EntityName VARCHAR(255), in EntityDescription TEXT, in EntityRole VARCHAR(255), - in Datatype VARCHAR(255), + in DatatypeID VARCHAR(255), in Collection VARCHAR(255), in ACL VARBINARY(65525)) BEGIN @@ -114,11 +114,10 @@ BEGIN DELETE FROM collection_type WHERE domain_id=0 AND entity_id=0 AND property_id=InternalEntityID; - IF Datatype IS NOT NULL THEN + IF DatatypeID IS NOT NULL THEN INSERT INTO data_type (domain_id, entity_id, property_id, datatype) SELECT 0, 0, InternalEntityID, - ( SELECT entity_id FROM name_data WHERE domain_id = 0 - AND property_id = 20 AND value = Datatype LIMIT 1 ); + ( SELECT internal_id FROM entity_ids WHERE id = DatatypeID ); IF Collection IS NOT NULL THEN INSERT INTO collection_type (domain_id, entity_id, property_id,