diff --git a/procedures/deleteIsaCache.sql b/procedures/deleteIsaCache.sql index 7ae0518e9f867c7f23d339365d928fd6d6c1044b..793f7f5f616113a315e2961a9e1b97f0597455a2 100644 --- a/procedures/deleteIsaCache.sql +++ b/procedures/deleteIsaCache.sql @@ -52,7 +52,7 @@ BEGIN SELECT e.child, IVersion AS child_iversion, e.parent FROM isa_cache AS e WHERE e.child = EntityID - AND e.rpath = CAST(EntityID AS BINARY); + AND e.rpath = CAST(EntityID AS CHAR) COLLATE utf8_unicode_ci; END IF; DELETE FROM isa_cache diff --git a/procedures/insertEntityProperty.sql b/procedures/insertEntityProperty.sql index 796b8922835502fd64113d20f51d4365f9df2905..8ed9579074ba2298b41494b6bc302b6358042580 100644 --- a/procedures/insertEntityProperty.sql +++ b/procedures/insertEntityProperty.sql @@ -23,74 +23,86 @@ DROP PROCEDURE IF EXISTS db_2_0.insertEntityProperty; delimiter // -CREATE PROCEDURE db_2_0.insertEntityProperty(in DomainID INT UNSIGNED, in EntityID INT UNSIGNED, in PropertyID INT UNSIGNED, in Datatable VARCHAR(255), in PropertyValue TEXT, in PropertyUnitSig BIGINT, in PropertyStatus VARCHAR(255), in NameOverride VARCHAR(255), in DescOverride TEXT, in datatypeOverride INT UNSIGNED, in Collection VARCHAR(255), in PropertyIndex INT UNSIGNED) +CREATE PROCEDURE db_2_0.insertEntityProperty( + in DomainID INT UNSIGNED, + in EntityID INT UNSIGNED, + in PropertyID INT UNSIGNED, + in Datatable VARCHAR(255), + in PropertyValue TEXT, + in PropertyUnitSig BIGINT, + in PropertyStatus VARCHAR(255), + in NameOverride VARCHAR(255), + in DescOverride TEXT, + in DatatypeOverride INT UNSIGNED, + in Collection VARCHAR(255), + in PropertyIndex INT UNSIGNED) BEGIN - CASE Datatable - WHEN 'double_data' THEN - INSERT INTO double_data - (domain_id, entity_id, property_id, value, unit_sig, status, pidx) - VALUES - (DomainID, EntityID, PropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex); - WHEN 'integer_data' THEN - INSERT INTO integer_data - (domain_id, entity_id, property_id, value, unit_sig, status, pidx) - VALUES - (DomainID, EntityID, PropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex); - WHEN 'datetime_data' THEN - INSERT INTO datetime_data - (domain_id, entity_id, property_id, value, value_ns, status, pidx) - VALUES - (DomainID, EntityID, PropertyID, SUBSTRING_INDEX(PropertyValue, 'UTC', 1), IF(SUBSTRING_INDEX(PropertyValue, 'UTC', -1)='',NULL,SUBSTRING_INDEX(PropertyValue, 'UTC', -1)), PropertyStatus, PropertyIndex); - WHEN 'reference_data' THEN - INSERT INTO reference_data - (domain_id, entity_id, property_id, value, status, pidx) - VALUES - (DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); - WHEN 'enum_data' THEN - INSERT INTO enum_data - (domain_id, entity_id, property_id, value, status, pidx) - VALUES - (DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); - WHEN 'date_data' THEN - INSERT INTO date_data - (domain_id, entity_id, property_id, value, status, pidx) - VALUES - (DomainID, EntityID, PropertyID, SUBSTRING_INDEX(PropertyValue, '.', 1), PropertyStatus, PropertyIndex); - WHEN 'text_data' THEN - INSERT INTO text_data - (domain_id, entity_id, property_id, value, status, pidx) - VALUES - (DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); - WHEN 'null_data' THEN - INSERT INTO null_data - (domain_id, entity_id, property_id, status, pidx) - VALUES - (DomainID, EntityID, PropertyID, PropertyStatus, PropertyIndex); - WHEN 'name_data' THEN - INSERT INTO name_data - (domain_id, entity_id, property_id, value, status, pidx) - VALUES - (DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); + CASE Datatable + WHEN 'double_data' THEN + INSERT INTO double_data + (domain_id, entity_id, property_id, value, unit_sig, status, pidx) + VALUES + (DomainID, EntityID, PropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex); + WHEN 'integer_data' THEN + INSERT INTO integer_data + (domain_id, entity_id, property_id, value, unit_sig, status, pidx) + VALUES + (DomainID, EntityID, PropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex); + WHEN 'datetime_data' THEN + INSERT INTO datetime_data + (domain_id, entity_id, property_id, value, value_ns, status, pidx) + VALUES + (DomainID, EntityID, PropertyID, SUBSTRING_INDEX(PropertyValue, 'UTC', 1), IF(SUBSTRING_INDEX(PropertyValue, 'UTC', -1)='',NULL,SUBSTRING_INDEX(PropertyValue, 'UTC', -1)), PropertyStatus, PropertyIndex); + WHEN 'reference_data' THEN + INSERT INTO reference_data + (domain_id, entity_id, property_id, value, status, pidx) + VALUES + (DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); + WHEN 'enum_data' THEN + INSERT INTO enum_data + (domain_id, entity_id, property_id, value, status, pidx) + VALUES + (DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); + WHEN 'date_data' THEN + INSERT INTO date_data + (domain_id, entity_id, property_id, value, status, pidx) + VALUES + (DomainID, EntityID, PropertyID, SUBSTRING_INDEX(PropertyValue, '.', 1), PropertyStatus, PropertyIndex); + WHEN 'text_data' THEN + INSERT INTO text_data + (domain_id, entity_id, property_id, value, status, pidx) + VALUES + (DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); + WHEN 'null_data' THEN + INSERT INTO null_data + (domain_id, entity_id, property_id, status, pidx) + VALUES + (DomainID, EntityID, PropertyID, PropertyStatus, PropertyIndex); + WHEN 'name_data' THEN + INSERT INTO name_data + (domain_id, entity_id, property_id, value, status, pidx) + VALUES + (DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); - ELSE - SELECT * FROM table_does_not_exist; - END CASE; + ELSE + SELECT * FROM table_does_not_exist; + END CASE; - IF DatatypeOverride IS NOT NULL THEN - call overrideType(DomainID, EntityID, PropertyID, DatatypeOverride); - IF Collection IS NOT NULL THEN - INSERT INTO collection_type (domain_id, entity_id, property_id, collection) VALUES (DomainID, EntityID, PropertyID, Collection); - END IF; - END IF; + IF DatatypeOverride IS NOT NULL THEN + call overrideType(DomainID, EntityID, PropertyID, DatatypeOverride); + IF Collection IS NOT NULL THEN + INSERT INTO collection_type (domain_id, entity_id, property_id, collection) VALUES (DomainID, EntityID, PropertyID, Collection); + END IF; + END IF; - IF NameOverride IS NOT NULL THEN - call overrideName(DomainID, EntityID, PropertyID, NameOverride); - END IF; + IF NameOverride IS NOT NULL THEN + call overrideName(DomainID, EntityID, PropertyID, NameOverride); + END IF; - IF DescOverride IS NOT NULL THEN - call overrideDesc(DomainID, EntityID, PropertyID, DescOverride); - END IF; + IF DescOverride IS NOT NULL THEN + call overrideDesc(DomainID, EntityID, PropertyID, DescOverride); + END IF; END; // diff --git a/procedures/retrieveEntity.sql b/procedures/retrieveEntity.sql index e197177363d7464ddcb6dd35a53486f03029f958..08cba84e014837969d66396684416c3bb9d3ede5 100644 --- a/procedures/retrieveEntity.sql +++ b/procedures/retrieveEntity.sql @@ -27,20 +27,26 @@ delimiter // drop procedure if exists db_2_0.retrieveEntity // -create procedure db_2_0.retrieveEntity(in EntityID INT UNSIGNED) -BEGIN +create procedure db_2_0.retrieveEntity(in EntityID INT UNSIGNED, in Version VARBINARY(255)) +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 CollectionName VARCHAR(255) DEFAULT NULL; - DECLARE Version VARBINARY(255) DEFAULT NULL; DECLARE VersionSeconds BIGINT UNSIGNED DEFAULT NULL; DECLARE VersionNanos INT(10) UNSIGNED DEFAULT NULL; + DECLARE IsHead BOOLEAN DEFAULT TRUE; + DECLARE IVersion INT UNSIGNED DEFAULT NULL; IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN - SET Version = get_head_version(EntityID); + IF Version IS NULL THEN + SET Version = get_head_version(EntityID); + ELSE + SELECT get_head_version(EntityID) = Version INTO IsHead; + END IF; + SELECT t.seconds, t.nanos INTO VersionSeconds, VersionNanos FROM entity_version AS e @@ -48,6 +54,66 @@ BEGIN ON ( e.srid = t.srid ) WHERE e.entity_id = EntityID AND e.version = Version; + + IF IsHead IS FALSE THEN + SELECT e._iversion INTO IVersion + FROM entity_version as e + WHERE e.entity_id = EntityID + AND e.version = Version; + + IF IVersion IS NULL THEN + -- RETURN EARLY - Version does not exist. + LEAVE retrieveEntityBody; + END IF; + + SELECT path, size, HEX(hash) + INTO FilePath, FileSize, FileHash + FROM archive_files + WHERE file_id = EntityID + AND _iversion = IVersion + LIMIT 1; + + SELECT datatype + INTO DatatypeID + FROM archive_data_type + WHERE domain_id = 0 + AND entity_id = 0 + AND property_id = EntityID + AND _iversion = IVersion + LIMIT 1; + + SELECT collection + INTO CollectionName + FROM archive_collection_type + WHERE domain_id = 0 + AND entity_id = 0 + AND property_id = EntityID + AND _iversion = IVersion + LIMIT 1; + + Select + (SELECT Name FROM entities WHERE id=DatatypeID) AS Datatype, + CollectionName AS Collection, + EntityID AS EntityID, + e.name AS EntityName, + e.description AS EntityDesc, + e.role AS EntityRole, + FileSize AS FileSize, + FilePath AS FilePath, + FileHASh AS FileHASh, + (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL, + Version AS Version, + VersionSeconds AS VersionSeconds, + VersionNanos AS VersionNanos + FROM archive_entities AS e + WHERE e.id = EntityID + AND e._iversion = IVersion + LIMIT 1; + + -- RETURN EARLY + LEAVE retrieveEntityBody; + + END IF; END IF; Select path, size, hex(hash) diff --git a/procedures/retrieveEntityOverrides.sql b/procedures/retrieveEntityOverrides.sql index f1f1bddbbe759862036a3789d20247f3e6699842..e070cbcff1d43cff168ecebd42b4041857eba573 100644 --- a/procedures/retrieveEntityOverrides.sql +++ b/procedures/retrieveEntityOverrides.sql @@ -24,14 +24,141 @@ DROP PROCEDURE IF EXISTS db_2_0.retrieveOverrides; delimiter // -CREATE PROCEDURE db_2_0.retrieveOverrides(in DomainID INT UNSIGNED, in EntityID INT UNSIGNED) -BEGIN - - SELECT NULL as collection_override, name as name_override, NULL as desc_override, NULL as type_override, entity_id, property_id from name_overrides where domain_id=DomainID and entity_id=EntityID UNION ALL - SELECT NULL as collection_override, NULL as name_override, description as desc_override, NULL as type_override, entity_id, property_id from desc_overrides where domain_id=DomainID and entity_id=EntityID UNION ALL - SELECT NULL as collection_override, NULL as name_override, NULL as desc_override, (Select name from entities where id=datatype LIMIT 1) as type_override, entity_id, property_id from data_type where domain_id=DomainID and entity_id=EntityID UNION ALL - SELECT collection as collection_override, NULL as name_override, NULL as desc_override, NULL as type_override, entity_id, property_id from collection_type where domain_id=DomainID and entity_id=EntityID; - +CREATE PROCEDURE db_2_0.retrieveOverrides( + in DomainID INT UNSIGNED, + in EntityID INT UNSIGNED, + in Version VARBINARY(255)) +retrieveOverridesBody: BEGIN + + DECLARE IVersion INT UNSIGNED DEFAULT NULL; + DECLARE IsHead BOOLEAN DEFAULT TRUE; + + IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN + IF Version IS NOT NULL THEN + SELECT get_head_version(EntityID) = Version INTO IsHead; + END IF; + + IF IsHead IS FALSE THEN + SELECT e._iversion INTO IVersion + FROM entity_version as e + WHERE e.entity_id = EntityID + AND e.version = Version; + + IF IVersion IS NULL THEN + -- RETURN EARLY - Version does not exist. + LEAVE retrieveOverridesBody; + END IF; + + SELECT + NULL AS collection_override, + name AS name_override, + NULL AS desc_override, + NULL AS type_override, + entity_id, + property_id + FROM archive_name_overrides + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion + + UNION ALL + + SELECT + NULL AS collection_override, + NULL AS name_override, + description AS desc_override, + NULL AS type_override, + entity_id, + property_id + FROM archive_desc_overrides + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion + + UNION ALL + + SELECT + NULL AS collection_override, + NULL AS name_override, + NULL AS desc_override, + (Select name FROM entities WHERE id=datatype LIMIT 1) + AS type_override, + entity_id, + property_id + FROM archive_data_type + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion + + UNION ALL + + SELECT + collection AS collection_override, + NULL AS name_override, + NULL AS desc_override, + NULL AS type_override, + entity_id, + property_id + FROM archive_collection_type + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion; + + + LEAVE retrieveOverridesBody; + END IF; + END IF; + + SELECT + NULL AS collection_override, + name AS name_override, + NULL AS desc_override, + NULL AS type_override, + entity_id, + property_id + FROM name_overrides + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + SELECT + NULL AS collection_override, + NULL AS name_override, + description AS desc_override, + NULL AS type_override, + entity_id, + property_id + FROM desc_overrides + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + SELECT + NULL AS collection_override, + NULL AS name_override, + NULL AS desc_override, + (Select name FROM entities WHERE id=datatype LIMIT 1) AS type_override, + entity_id, + property_id + FROM data_type + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + SELECT + collection AS collection_override, + NULL AS name_override, + NULL AS desc_override, + NULL AS type_override, + entity_id, + property_id + FROM collection_type + WHERE domain_id = DomainID + AND entity_id = EntityID; + END; // diff --git a/procedures/retrieveEntityParents.sql b/procedures/retrieveEntityParents.sql index ffd9f13799b066c251b3941ffb8438e283014ebc..bbde5dbc8dfb267763edeebcc086bbaf49fa8bc2 100644 --- a/procedures/retrieveEntityParents.sql +++ b/procedures/retrieveEntityParents.sql @@ -51,13 +51,57 @@ ParentRole : ACL : Access control list something */ -CREATE PROCEDURE db_2_0.retrieveEntityParents(in EntityID INT UNSIGNED) -BEGIN +CREATE PROCEDURE db_2_0.retrieveEntityParents( + in EntityID INT UNSIGNED, + in Version VARBINARY(255)) +retrieveEntityParentsBody: BEGIN -SELECT parent AS ParentID, name AS ParentName, description AS ParentDescription, role AS ParentRole, (SELECT acl from entity_acl as a WHERE a.id=e.acl) AS ACL FROM isa_cache AS i JOIN entities AS e ON (i.parent=e.id AND i.child=EntityID and i.rpath=EntityID); + DECLARE IVersion INT UNSIGNED DEFAULT NULL; + DECLARE IsHead BOOLEAN DEFAULT TRUE; + IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN + IF Version IS NOT NULL THEN + SELECT get_head_version(EntityID) = Version INTO IsHead; + END IF; + IF IsHead IS FALSE THEN + SELECT e._iversion INTO IVersion + FROM entity_version as e + WHERE e.entity_id = EntityID + AND e.version = Version; + IF IVersion IS NULL THEN + -- RETURN EARLY - Version does not exist. + LEAVE retrieveEntityParentsBody; + END IF; + + SELECT + i.parent AS ParentID, + e.name AS ParentName, + e.description AS ParentDescription, + e.role AS ParentRole, + (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL + FROM archive_isa AS i + JOIN entities AS e + ON (i.parent = e.id) + WHERE i.child = EntityID + AND i.child_iversion = IVersion; + + LEAVE retrieveEntityParentsBody; + END IF; + END IF; + + SELECT + i.parent AS ParentID, + e.name AS ParentName, + e.description AS ParentDescription, + e.role AS ParentRole, + (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL + FROM isa_cache AS i + JOIN entities AS e + ON (i.parent = e.id) + WHERE i.child = EntityID + AND i.rpath = CAST(EntityID AS CHAR) COLLATE utf8_unicode_ci; END // diff --git a/procedures/retrieveEntityProperties.sql b/procedures/retrieveEntityProperties.sql index 8df949a44978b91f822a2e3de7535f678f1ff62d..4829c53b70c33f57f69feb6bd51e948f010a4f47 100644 --- a/procedures/retrieveEntityProperties.sql +++ b/procedures/retrieveEntityProperties.sql @@ -26,61 +26,257 @@ delimiter // drop procedure if exists db_2_0.retrieveEntityProperties // -create procedure db_2_0.retrieveEntityProperties(in DomainID INT UNSIGNED, in EntityID INT UNSIGNED) -BEGIN +create procedure db_2_0.retrieveEntityProperties( + in DomainID INT UNSIGNED, + in EntityID INT UNSIGNED, + in Version VARBINARY(255)) +retrieveEntityPropertiesBody: BEGIN - #-- double properties - Select - property_id as PropertyID, value as PropertyValue, status as PropertyStatus, pidx as PropertyIndex from double_data where domain_id = DomainID and entity_id = EntityID + DECLARE IVersion INT UNSIGNED DEFAULT NULL; + DECLARE IsHead BOOLEAN DEFAULT TRUE; - UNION ALL - - #-- integer properties - Select - property_id as PropertyID, value as PropertyValue, status as PropertyStatus, pidx as PropertyIndex from integer_data where domain_id = DomainID and entity_id = EntityID + IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN + IF Version IS NOT NULL THEN + SELECT get_head_version(EntityID) = Version INTO IsHead; + END IF; - UNION ALL + IF IsHead IS FALSE THEN + SELECT e._iversion INTO IVersion + FROM entity_version as e + WHERE e.entity_id = EntityID + AND e.version = Version; - #-- date properties - Select - property_id as PropertyID, CONCAT(value, '.NULL.NULL') as PropertyValue, status as PropertyStatus, pidx as PropertyIndex from date_data where domain_id = DomainID and entity_id = EntityID + IF IVersion IS NULL THEN + -- RETURN EARLY - Version does not exist. + LEAVE retrieveEntityPropertiesBody; + END IF; - UNION ALL + #-- double properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM archive_double_data + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion - #-- datetime properties - Select - property_id as PropertyID, CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns)) as PropertyValue, status as PropertyStatus, pidx as PropertyIndex from datetime_data where domain_id = DomainID and entity_id = EntityID + UNION ALL - UNION ALL + #-- integer properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM archive_integer_data + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion - #-- text properties - Select - property_id as PropertyID, value as PropertyValue, status as PropertyStatus, pidx as PropertyIndex from text_data where domain_id = DomainID and entity_id = EntityID + UNION ALL - UNION ALL + #-- date properties + SELECT + property_id AS PropertyID, + CONCAT(value, '.NULL.NULL') AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM archive_date_data + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion - #-- enum properties - Select - property_id as PropertyID, value as PropertyValue, status as PropertyStatus, pidx as PropertyIndex from enum_data where domain_id = DomainID and entity_id = EntityID + UNION ALL - UNION ALL + #-- datetime properties + SELECT + property_id AS PropertyID, + CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns)) + AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM archive_datetime_data + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion - #-- reference properties - Select - property_id as PropertyID, value as PropertyValue, status as PropertyStatus, pidx as PropertyIndex from reference_data where domain_id = DomainID and entity_id = EntityID + UNION ALL - UNION ALL + #-- text properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM archive_text_data + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion - #-- null properties - Select - property_id as PropertyID, NULL AS PropertyValue, status as PropertyStatus, pidx as PropertyIndex from null_data WHERE domain_id = DomainID and entity_id = EntityID - - UNION ALL + UNION ALL - #-- name properties - Select - property_id as PropertyID, value as PropertyValue, status as PropertyStatus, pidx as PropertyIndex from name_data where domain_id = DomainID and entity_id = EntityID; + #-- enum properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM archive_enum_data + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion + UNION ALL + + #-- reference properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM archive_reference_data + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion + + UNION ALL + + #-- null properties + SELECT + property_id AS PropertyID, + NULL AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM archive_null_data + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion + + UNION ALL + + #-- name properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM archive_name_data + WHERE domain_id = DomainID + AND entity_id = EntityID + AND _iversion = IVersion; + + LEAVE retrieveEntityPropertiesBody; + END IF; + END IF; + + #-- double properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM double_data + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + #-- integer properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM integer_data + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + #-- date properties + SELECT + property_id AS PropertyID, + CONCAT(value, '.NULL.NULL') AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM date_data + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + #-- datetime properties + SELECT + property_id AS PropertyID, + CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns)) + AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM datetime_data + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + #-- text properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM text_data + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + #-- enum properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM enum_data + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + #-- reference properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM reference_data + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + #-- null properties + SELECT + property_id AS PropertyID, + NULL AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM null_data + WHERE domain_id = DomainID + AND entity_id = EntityID + + UNION ALL + + #-- name properties + SELECT + property_id AS PropertyID, + value AS PropertyValue, + status AS PropertyStatus, + pidx AS PropertyIndex + FROM name_data + WHERE domain_id = DomainID + AND entity_id = EntityID; END; diff --git a/tests/test_0_next_patch.sql b/tests/test_0_next_patch.sql index d2cbdaeef9271b35a07ddfdba51a16ced749d364..d52fe5a6b2683c2277930b7f89fe4406aef468d5 100644 --- a/tests/test_0_next_patch.sql +++ b/tests/test_0_next_patch.sql @@ -1,5 +1,5 @@ ---USE _caosdb_schema_unit_tests; +USE _caosdb_schema_unit_tests; DROP TABLE IF EXISTS archive_reference_data; DROP TABLE IF EXISTS archive_null_data; diff --git a/tests/test_entity_versioning.sql b/tests/test_entity_versioning.sql index dea994513ad274233467d21e636f0a22799ddc02..653e11e0138e465ed173bcda7feef28c9317871d 100644 --- a/tests/test_entity_versioning.sql +++ b/tests/test_entity_versioning.sql @@ -75,6 +75,12 @@ SELECT tap.eq(@x, 0, "before insertEntity, no versions there"); SET @SRID = "SRIDbla"; CALL insertEntity("EntityName", "EntityDesc", "RECORDTYPE", "{acl1}"); SELECT id INTO @EntityID FROM entities WHERE name="EntityName"; +CALL insertEntity("ParentName", "ParentDesc", "RECORDTYPE", "{acl1}"); +SELECT id INTO @ParentID FROM entities WHERE name="ParentName"; +CALL insertIsa(@EntityID, @ParentID); +CALL insertEntityProperty(0, @EntityID, 17, "null_data", NULL, NULL, + "RECOMMENDED", NULL, "DescOverride", NULL, NULL, 0); + SELECT count(*) INTO @x FROM entity_version WHERE entity_id = @EntityID; SELECT tap.eq(@x, 1, "after insertEntity, a version is there."); SELECT _iversion INTO @x FROM entity_version WHERE entity_id = @EntityID and _ipparent is NULL; @@ -88,6 +94,7 @@ SELECT tap.eq(count(*), 0, "no entity in archive_entities before first update") -- TEST updateEntity - should produce a version with a parent SET @SRID = "SRIDblub"; +CALL deleteEntityProperties(@EntityID); CALL updateEntity(@EntityID, "NewEntityName", "NewEntityDesc", "RECORD", NULL, NULL, "{acl1}"); SELECT count(*) INTO @x FROM entity_version WHERE entity_id = @EntityID; SELECT tap.eq(@x, 2, "after updateEntity, a second version is there."); @@ -100,6 +107,39 @@ SELECT tap.eq(@x, 0, "after updateEntity, the _pparent points to the first versi SELECT tap.eq(count(*), 1, "after updateEntity, one entity in archive_entities") FROM archive_entities; + +-- TEST retrieveEntity + +SELECT version INTO @x FROM entity_version + WHERE entity_id = @EntityID + AND _iversion = 0; +CALL retrieveEntity(@EntityID, NULL); +CALL retrieveEntity(@EntityID, "non-existing-version"); +CALL retrieveEntity(@EntityID, get_head_version(@EntityID)); +CALL retrieveEntity(@EntityID, @x); + +-- TEST retrieveEntityParents + +CALL retrieveEntityParents(@EntityID, NULL); +CALL retrieveEntityParents(@EntityID, "non-existing-version"); +CALL retrieveEntityParents(@EntityID, get_head_version(@EntityID)); +CALL retrieveEntityParents(@EntityID, @x); + +-- TEST retrieveEntityProperties + +CALL retrieveEntityProperties(0, @EntityID, NULL); +CALL retrieveEntityProperties(0, @EntityID, "non-existing-version"); +CALL retrieveEntityProperties(0, @EntityID, get_head_version(@EntityID)); +CALL retrieveEntityProperties(0, @EntityID, @x); + +-- TEST retrieveOverrides + +CALL retrieveOverrides(0, @EntityID, NULL); +CALL retrieveOverrides(0, @EntityID, "non-existing-version"); +CALL retrieveOverrides(0, @EntityID, get_head_version(@EntityID)); +CALL retrieveOverrides(0, @EntityID, @x); + + -- and 2nd updateEntity SET @SRID = "SRIDblieb"; CALL updateEntity(@EntityID, "EntityName", "EntityDesc", "RECORDTYPE", NULL, NULL, "{acl1}"); @@ -113,15 +153,13 @@ SELECT tap.eq(@x, 1, "after 2nd updateEntity, the _pparent points to the 2nd ver SELECT tap.eq("SRIDblieb", srid, "correct transaction was stored") FROM entity_version WHERE entity_id = @EntityID AND _ipparent = 1; --- TEST retrieveEntity - -CALL retrieveEntity(@EntityID); - -- TEST deleteEntity - should remove all versions +CALL deleteIsa(@EntityID); CALL deleteEntity(@EntityID); -SELECT count(*) INTO @x FROM entity_version; +SELECT count(*) INTO @x FROM entity_version WHERE entity_id = @EntityID; SELECT tap.eq(@x, 0, "no versions there any more"); +CALL deleteEntity(@ParentID); -- TEARDOWN diff --git a/utils/make_db b/utils/make_db index e1cdc2f8673de6e043a67e85106f40c7c655c2f0..6144563bf3ef3de6af7f486b30f3996e7359b50c 100755 --- a/utils/make_db +++ b/utils/make_db @@ -56,12 +56,13 @@ function _execute_tests () { for tfile in $TESTS ; do echo "Running $tfile" echo "----- $tfile -----" >> .TEST_RESULTS - cat $tfile | $MYSQL_CMD $(get_db_args_nodb) --disable-pager --batch --raw --skip-column-names --unbuffered >> .TEST_RESULTS + cat $tfile | $MYSQL_CMD $(get_db_args_nodb) --disable-pager --batch --raw --skip-column-names --unbuffered >> .TEST_RESULTS 2>&1 done; popd cat tests/.TEST_RESULTS grep -c -i "failed" tests/.TEST_RESULTS > /dev/null && return 1 + grep -c -i "ERROR" tests/.TEST_RESULTS > /dev/null && return 1 return 0 }