Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • dev
  • f-filesystem-cleanup
  • f-filesystem-core
  • f-filesystem-directory
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-main
  • f-linkahead-rename
  • f-mysql8-tests
  • f-name
  • f-permission-checks-2
  • f-real-id
  • f-retrieve-history
  • keep_changes
  • main
  • t-distinct-parents
  • v2.0.30
  • v3.0
  • v4.0.0
  • v4.1.0
  • v5.0.0
  • v6.0.0
  • v6.0.1
  • v7.0.0
  • v7.0.1
  • v7.0.2
  • v8.0.0
  • v8.1.0
28 results

Target

Select target project
  • caosdb/src/caosdb-mysqlbackend
1 result
Select Git revision
  • dev
  • f-filesystem-cleanup
  • f-filesystem-core
  • f-filesystem-directory
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-main
  • f-linkahead-rename
  • f-mysql8-tests
  • f-name
  • f-permission-checks-2
  • f-real-id
  • f-retrieve-history
  • keep_changes
  • main
  • t-distinct-parents
  • v2.0.30
  • v3.0
  • v4.0.0
  • v4.1.0
  • v5.0.0
  • v6.0.0
  • v6.0.1
  • v7.0.0
  • v7.0.1
  • v7.0.2
  • v8.0.0
  • v8.1.0
28 results
Show changes
Showing
with 837 additions and 476 deletions
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -17,28 +16,56 @@ ...@@ -17,28 +16,56 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.insertEntityDataType;
DELIMITER //
/*
* Insert the (default) datatype of a property.
*
* Parameters
* ----------
* PropertyID : VARCHAR(255)
* The property id.
* DataTypeID : VARCHAR(255)
* The data type id (not the name!)
*/
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 internal_id FROM entity_ids WHERE id = DataTypeID);
END;
//
DELIMITER ;
DROP PROCEDURE IF EXISTS db_5_0.getRole;
delimiter //
CREATE PROCEDURE db_5_0.getRole(in RoleName VARCHAR(255))
BEGIN
Select e.id INTO @RoleID from entities e where e.name=RoleName AND e.role=RoleName LIMIT 1;
call retrieveEntity(@RoleID); DROP PROCEDURE IF EXISTS db_5_0.insertEntityCollection;
DELIMITER //
/*
* Insert the (default) collection type of a property.
*
* Parameters
* ----------
* PropertyID : VARCHAR(255)
* The property id.
* Collection : VARCHAR(255)
* The collection, e.g. "LIST"
*/
CREATE PROCEDURE db_5_0.insertEntityCollection(in PropertyID VARCHAR(255), in Collection VARCHAR(255))
BEGIN
DECLARE InternalPropertyID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalPropertyID FROM entity_ids WHERE id=PropertyID;
INSERT INTO collection_type (domain_id, entity_id, property_id, collection) SELECT 0, 0, InternalPropertyID, Collection;
END; END;
// //
delimiter ; DELIMITER ;
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> * Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale * Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -19,112 +18,166 @@ ...@@ -19,112 +18,166 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.insertEntityProperty; DROP PROCEDURE IF EXISTS db_5_0.insertEntityProperty;
delimiter // delimiter //
/*
* Insert the property of an entity (level 1 and 2, only one *_data table entry at a time).
*
* Parameters
* ----------
* DomainID : VARCHAR(255)
* The domain id (0 or the entity's id for level-2-data)
* EntityID : VARCHAR(255)
* The entity id (or the property's id for level-2-data)
* PropertyID : VARCHAR(255)
* The property id (or the sub-property's id for level-2-data)
* Datatable : VARCHAR(255)
* Name of the *_data table, e.g. 'double_data'.
* PropertyValue : TEXT
* The property's value
* PropertyUnitSig : BIGINT
* The unit signature.
* PropertyStatus : VARCHAR(255)
* E.g. OBLIGATORY, FIX,...
* NameOverride : VARCHAR(255)
* The overridden name
* DescOverride : TEXT
* The overridden description
* DatatypeOverride : VARCHAR(255)
* The overridden datatype
* Collection : VARCHAR(255)
* The overridden collection (only if DatatypeOverride is present).
* PropertyIndex : INT UNSIGNED
* The property's index (for ordering of properties and values).
*/
CREATE PROCEDURE db_5_0.insertEntityProperty( CREATE PROCEDURE db_5_0.insertEntityProperty(
in DomainID INT UNSIGNED, in DomainID VARCHAR(255),
in EntityID INT UNSIGNED, in EntityID VARCHAR(255),
in PropertyID INT UNSIGNED, in PropertyID VARCHAR(255),
in Datatable VARCHAR(255), in Datatable VARCHAR(255),
in PropertyValue TEXT, in PropertyValue TEXT,
in PropertyUnitSig BIGINT, in PropertyUnitSig BIGINT,
in PropertyStatus VARCHAR(255), in PropertyStatus VARCHAR(255),
in NameOverride VARCHAR(255), in NameOverride VARCHAR(255),
in DescOverride TEXT, in DescOverride TEXT,
in DatatypeOverride INT UNSIGNED, in DatatypeOverride VARCHAR(255),
in Collection VARCHAR(255), in Collection VARCHAR(255),
in PropertyIndex INT UNSIGNED) in PropertyIndex INT UNSIGNED)
BEGIN BEGIN
DECLARE ReferenceValueIVersion INT UNSIGNED DEFAULT NULL; DECLARE ReferenceValueIVersion INT UNSIGNED DEFAULT NULL;
DECLARE ReferenceValue INT UNSIGNED DEFAULT NULL; DECLARE ReferenceValue INT UNSIGNED DEFAULT NULL;
DECLARE AT_PRESENT INTEGER DEFAULT NULL; DECLARE AT_PRESENT INTEGER DEFAULT NULL;
DECLARE InternalDataTypeID INT UNSIGNED DEFAULT NULL;
DECLARE InternalPropertyID INT UNSIGNED DEFAULT NULL;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
DECLARE InternalDomainID INT UNSIGNED DEFAULT 0;
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 CASE Datatable
WHEN 'double_data' THEN WHEN 'double_data' THEN
INSERT INTO double_data INSERT INTO double_data
(domain_id, entity_id, property_id, value, unit_sig, status, pidx) (domain_id, entity_id, property_id, value, unit_sig, status, pidx)
VALUES VALUES
(DomainID, EntityID, PropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex); (InternalDomainID, InternalEntityID, InternalPropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex);
WHEN 'integer_data' THEN WHEN 'integer_data' THEN
INSERT INTO integer_data INSERT INTO integer_data
(domain_id, entity_id, property_id, value, unit_sig, status, pidx) (domain_id, entity_id, property_id, value, unit_sig, status, pidx)
VALUES VALUES
(DomainID, EntityID, PropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex); (InternalDomainID, InternalEntityID, InternalPropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex);
WHEN 'datetime_data' THEN WHEN 'datetime_data' THEN
INSERT INTO datetime_data INSERT INTO datetime_data
(domain_id, entity_id, property_id, value, value_ns, status, pidx) (domain_id, entity_id, property_id, value, value_ns, status, pidx)
VALUES VALUES
(DomainID, EntityID, PropertyID, SUBSTRING_INDEX(PropertyValue, 'UTC', 1), IF(SUBSTRING_INDEX(PropertyValue, 'UTC', -1)='',NULL,SUBSTRING_INDEX(PropertyValue, 'UTC', -1)), PropertyStatus, PropertyIndex); (InternalDomainID, InternalEntityID, InternalPropertyID, SUBSTRING_INDEX(PropertyValue, 'UTC', 1), IF(SUBSTRING_INDEX(PropertyValue, 'UTC', -1)='',NULL,SUBSTRING_INDEX(PropertyValue, 'UTC', -1)), PropertyStatus, PropertyIndex);
WHEN 'reference_data' THEN WHEN 'reference_data' THEN
-- special handling if versioning enabled and specific version of referenced entity is given. -- special handling if versioning enabled and specific version of referenced entity is given.
SET AT_PRESENT=LOCATE("@", PropertyValue); SET AT_PRESENT=LOCATE("@", PropertyValue);
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") AND AT_PRESENT > 0 THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") AND AT_PRESENT > 0 THEN
SET ReferenceValue = SUBSTRING_INDEX(PropertyValue, '@', 1); SELECT internal_id INTO ReferenceValue FROM entity_ids WHERE id = SUBSTRING_INDEX(PropertyValue, '@', 1);
SET ReferenceValueIVersion = get_iversion(ReferenceValue, SET ReferenceValueIVersion = get_iversion(ReferenceValue,
SUBSTRING_INDEX(PropertyValue, '@', -1)); SUBSTRING_INDEX(PropertyValue, '@', -1));
-- TODO raise error when @ present but iversion is null
IF ReferenceValueIVersion IS NULL THEN IF ReferenceValueIVersion IS NULL THEN
-- Raise error when @ present but iversion is null
SELECT 0 from `ReferenceValueIVersion_WAS_NULL`; SELECT 0 from `ReferenceValueIVersion_WAS_NULL`;
END IF; END IF;
ELSEIF LOCATE("$", PropertyValue) = 1 THEN
SET ReferenceValue = SUBSTRING(PropertyValue, 2);
ELSE ELSE
SET ReferenceValue = PropertyValue; SELECT internal_id INTO ReferenceValue FROM entity_ids WHERE id = PropertyValue;
END IF; END IF;
INSERT INTO reference_data INSERT INTO reference_data
(domain_id, entity_id, property_id, value, value_iversion, status, (domain_id, entity_id, property_id, value, value_iversion, status,
pidx) pidx)
VALUES VALUES
(DomainID, EntityID, PropertyID, ReferenceValue, (InternalDomainID, InternalEntityID, InternalPropertyID, ReferenceValue,
ReferenceValueIVersion, PropertyStatus, PropertyIndex); ReferenceValueIVersion, PropertyStatus, PropertyIndex);
WHEN 'enum_data' THEN WHEN 'enum_data' THEN
INSERT INTO enum_data INSERT INTO enum_data
(domain_id, entity_id, property_id, value, status, pidx) (domain_id, entity_id, property_id, value, status, pidx)
VALUES VALUES
(DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); (InternalDomainID, InternalEntityID, InternalPropertyID, PropertyValue, PropertyStatus, PropertyIndex);
WHEN 'date_data' THEN WHEN 'date_data' THEN
INSERT INTO date_data INSERT INTO date_data
(domain_id, entity_id, property_id, value, status, pidx) (domain_id, entity_id, property_id, value, status, pidx)
VALUES VALUES
(DomainID, EntityID, PropertyID, SUBSTRING_INDEX(PropertyValue, '.', 1), PropertyStatus, PropertyIndex); (InternalDomainID, InternalEntityID, InternalPropertyID, SUBSTRING_INDEX(PropertyValue, '.', 1), PropertyStatus, PropertyIndex);
WHEN 'text_data' THEN WHEN 'text_data' THEN
INSERT INTO text_data INSERT INTO text_data
(domain_id, entity_id, property_id, value, status, pidx) (domain_id, entity_id, property_id, value, status, pidx)
VALUES VALUES
(DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); (InternalDomainID, InternalEntityID, InternalPropertyID, PropertyValue, PropertyStatus, PropertyIndex);
WHEN 'null_data' THEN WHEN 'null_data' THEN
INSERT INTO null_data INSERT INTO null_data
(domain_id, entity_id, property_id, status, pidx) (domain_id, entity_id, property_id, status, pidx)
VALUES VALUES
(DomainID, EntityID, PropertyID, PropertyStatus, PropertyIndex); (InternalDomainID, InternalEntityID, InternalPropertyID, PropertyStatus, PropertyIndex);
WHEN 'name_data' THEN WHEN 'name_data' THEN
INSERT INTO name_data INSERT INTO name_data
(domain_id, entity_id, property_id, value, status, pidx) (domain_id, entity_id, property_id, value, status, pidx)
VALUES VALUES
(DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex); (InternalDomainID, InternalEntityID, InternalPropertyID, PropertyValue, PropertyStatus, PropertyIndex);
ELSE ELSE
-- raise error
SELECT * FROM table_does_not_exist; SELECT * FROM table_does_not_exist;
END CASE; END CASE;
IF DatatypeOverride IS NOT NULL THEN IF DatatypeOverride IS NOT NULL THEN
call overrideType(DomainID, EntityID, PropertyID, DatatypeOverride); SELECT internal_id INTO InternalDataTypeID from entity_ids WHERE id = DatatypeOverride;
call overrideType(InternalDomainID, InternalEntityID, InternalPropertyID, InternalDataTypeID);
IF Collection IS NOT NULL THEN IF Collection IS NOT NULL THEN
INSERT INTO collection_type (domain_id, entity_id, property_id, collection) VALUES (DomainID, EntityID, PropertyID, Collection); INSERT INTO collection_type (domain_id, entity_id, property_id, collection) VALUES (InternalDomainID, InternalEntityID, InternalPropertyID, Collection);
END IF; END IF;
END IF; END IF;
IF NameOverride IS NOT NULL THEN IF NameOverride IS NOT NULL THEN
call overrideName(DomainID, EntityID, PropertyID, NameOverride); call overrideName(InternalDomainID, InternalEntityID, InternalPropertyID, NameOverride);
END IF; END IF;
IF DescOverride IS NOT NULL THEN IF DescOverride IS NOT NULL THEN
call overrideDesc(DomainID, EntityID, PropertyID, DescOverride); call overrideDesc(InternalDomainID, InternalEntityID, InternalPropertyID, DescOverride);
END IF; END IF;
END; END;
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> * Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.insertIsa; DROP PROCEDURE IF EXISTS db_5_0.insertIsa;
DELIMITER // DELIMITER //
...@@ -33,15 +31,21 @@ DELIMITER // ...@@ -33,15 +31,21 @@ DELIMITER //
* Parameters * Parameters
* ========== * ==========
* *
* c : UNSIGNED * ChildID : VARCHAR(255)
* The child entity * The child entity.
* *
* p : UNSIGNED * ParentID : VARCHAR(255)
* The parent entity * The parent entity.
*/ */
CREATE PROCEDURE db_5_0.insertIsa(IN c INT UNSIGNED, IN p INT UNSIGNED) CREATE PROCEDURE db_5_0.insertIsa(IN ChildID VARCHAR(255), IN ParentID VARCHAR(255))
insert_is_a_proc: BEGIN insert_is_a_proc: BEGIN
DECLARE c INT UNSIGNED DEFAULT NULL;
DECLARE p INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO c FROM entity_ids WHERE id = ChildID;
SELECT internal_id INTO p FROM entity_ids WHERE id = ParentID;
INSERT INTO isa_cache (child, parent, rpath) VALUES (c, p, c); INSERT INTO isa_cache (child, parent, rpath) VALUES (c, p, c);
IF p = c THEN IF p = c THEN
...@@ -69,17 +73,17 @@ insert_is_a_proc: BEGIN ...@@ -69,17 +73,17 @@ insert_is_a_proc: BEGIN
INSERT IGNORE INTO isa_cache SELECT INSERT IGNORE INTO isa_cache SELECT
l.child, -- Descendant as found in isa_cache l.child, -- Descendant as found in isa_cache
r.parent, -- Ancestor as found in isa_cache r.parent, -- Ancestor as found in isa_cache
if(l.rpath=l.child and r.rpath=c, -- if distance=1 for left and right: IF(l.rpath=l.child AND r.rpath=c, -- if distance=1 for left and right:
c, -- rpath = current child c, -- rpath = current child
concat(if(l.rpath=l.child, -- if dist=1 for descendant: concat(IF(l.rpath=l.child, -- if dist=1 for descendant:
c, -- rpath starts with c c, -- rpath starts with c
concat(l.rpath, '>', c)), -- rpath starts with "desc.rpath > c" concat(l.rpath, '>', c)), -- rpath starts with "desc.rpath > c"
if(r.rpath=c, -- if dist=1 for ancestor IF(r.rpath=c, -- if dist=1 for ancestor
'', -- rpath is finished '', -- rpath is finished
concat('>', r.rpath)))) -- rpath continuees with " > ancest.rpath" concat('>', r.rpath)))) -- rpath continuees with " > ancest.rpath"
AS rpath AS rpath
FROM FROM
isa_cache as l INNER JOIN isa_cache as r isa_cache AS l INNER JOIN isa_cache AS r
ON (l.parent = c AND c = r.child AND l.child != l.parent); -- Left: descendants of c, right: ancestors ON (l.parent = c AND c = r.child AND l.child != l.parent); -- Left: descendants of c, right: ancestors
END; END;
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
Drop Procedure if exists db_5_0.insertUser;
Delimiter //
Create Procedure db_5_0.insertUser(in Name VARCHAR(255), in Password VARCHAR(255))
BEGIN
INSERT INTO entities (name, role, acl) VALUES (Name, 'USER', 0);
SET @LAST_UserID = LAST_INSERT_ID();
INSERT INTO passwords VALUES (@LAST_UserID, Password);
Select @LAST_UserID as UserID;
END;
//
delimiter ;
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -17,17 +18,36 @@ ...@@ -17,17 +18,36 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.isSubtype; DROP PROCEDURE IF EXISTS db_5_0.isSubtype;
delimiter // delimiter //
CREATE PROCEDURE db_5_0.isSubtype(in c INT UNSIGNED, in p INT UNSIGNED) /*
* Return TRUE if the given Child is indeed a (direct or indirect) child of the
* given Parent.
*
* Parameters
* ----------
* ChildID : VARCHAR(255)
* The entity id of the child.
* ParentID : VARCHAR(255)
* The entity id of the parent.
*
* Returns
* -------
* ISA : BOOLEAN
*/
CREATE PROCEDURE db_5_0.isSubtype(in ChildID VARCHAR(255), in ParentID VARCHAR(255))
BEGIN BEGIN
DECLARE c INT UNSIGNED DEFAULT NULL;
DECLARE p INT UNSIGNED DEFAULT NULL;
DECLARE ret BOOLEAN DEFAULT FALSE; DECLARE ret BOOLEAN DEFAULT FALSE;
SELECT internal_id INTO c from entity_ids WHERE id = ChildID;
SELECT internal_id INTO p from entity_ids WHERE id = ParentID;
SELECT TRUE INTO ret FROM isa_cache AS i WHERE i.child=c AND i.parent=p LIMIT 1; SELECT TRUE INTO ret FROM isa_cache AS i WHERE i.child=c AND i.parent=p LIMIT 1;
SELECT ret as ISA; SELECT ret as ISA;
END; END;
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -17,8 +18,6 @@ ...@@ -17,8 +18,6 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.overrideName; DROP PROCEDURE IF EXISTS db_5_0.overrideName;
...@@ -26,21 +25,61 @@ DROP PROCEDURE IF EXISTS db_5_0.overrideDesc; ...@@ -26,21 +25,61 @@ DROP PROCEDURE IF EXISTS db_5_0.overrideDesc;
DROP PROCEDURE IF EXISTS db_5_0.overrideType; DROP PROCEDURE IF EXISTS db_5_0.overrideType;
DELIMITER // DELIMITER //
CREATE PROCEDURE db_5_0.overrideName(in DomainID INT UNSIGNED, in EntityID INT UNSIGNED, in PropertyID INT UNSIGNED, in Name VARCHAR(255)) /*
* Insert a name override.
*
* Parameters
* ----------
* InternalDomainID : INT UNSIGNED
* The *internal* id of the domain.
* InternalEntityID : INT UNSIGNED
* The *internal* id of the entity.
* InternalPropertyID : INT UNSIGNED
* The *internal* id of the property.
* Name : VARCHAR(255)
*/
CREATE PROCEDURE db_5_0.overrideName(in InternalDomainID INT UNSIGNED, in InternalEntityID INT UNSIGNED, in InternalPropertyID INT UNSIGNED, in Name VARCHAR(255))
BEGIN BEGIN
INSERT INTO name_overrides (domain_id, entity_id, property_id, name) VALUES (DomainID, EntityID, PropertyID, Name); INSERT INTO name_overrides (domain_id, entity_id, property_id, name) VALUES (InternalDomainID, InternalEntityID, InternalPropertyID, Name);
END; END;
// //
CREATE PROCEDURE db_5_0.overrideDesc(in DomainID INT UNSIGNED, in EntityID INT UNSIGNED, in PropertyID INT UNSIGNED, in Description TEXT) /*
* Insert a description override.
*
* Parameters
* ----------
* InternalDomainID : INT UNSIGNED
* The *internal* id of the domain.
* InternalEntityID : INT UNSIGNED
* The *internal* id of the entity.
* InternalPropertyID : INT UNSIGNED
* The *internal* id of the property.
* Description : TEXT
*/
CREATE PROCEDURE db_5_0.overrideDesc(in InternalDomainID INT UNSIGNED, in InternalEntityID INT UNSIGNED, in InternalPropertyID INT UNSIGNED, in Description TEXT)
BEGIN BEGIN
INSERT INTO desc_overrides (domain_id, entity_id, property_id, description) VALUES (DomainID, EntityID, PropertyID, Description); INSERT INTO desc_overrides (domain_id, entity_id, property_id, description) VALUES (InternalDomainID, InternalEntityID, InternalPropertyID, Description);
END; END;
// //
CREATE PROCEDURE db_5_0.overrideType(in DomainID INT UNSIGNED, in EntityID INT UNSIGNED, in PropertyID INT UNSIGNED, in Datatype INT UNSIGNED) /*
* Insert a data type override.
*
* Parameters
* ----------
* InternalDomainID : INT UNSIGNED
* The *internal* id of the domain.
* InternalEntityID : INT UNSIGNED
* The *internal* id of the entity.
* InternalPropertyID : INT UNSIGNED
* The *internal* id of the property.
* InternalDatatypeID : INT UNSIGNED
* The *internal* id of the data type.
*/
CREATE PROCEDURE db_5_0.overrideType(in InternalDomainID INT UNSIGNED, in InternalEntityID INT UNSIGNED, in InternalPropertyID INT UNSIGNED, in InternalDataTypeID INT UNSIGNED)
BEGIN BEGIN
INSERT INTO data_type (domain_id, entity_id, property_id, datatype) VALUES (DomainID, EntityID, PropertyID, Datatype); INSERT INTO data_type (domain_id, entity_id, property_id, datatype) VALUES (InternalDomainID, InternalEntityID, InternalPropertyID, InternalDataTypeID);
END; END;
// //
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -17,8 +18,6 @@ ...@@ -17,8 +18,6 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.applyIDFilter; DROP PROCEDURE IF EXISTS db_5_0.applyIDFilter;
...@@ -32,71 +31,114 @@ DELIMITER // ...@@ -32,71 +31,114 @@ DELIMITER //
* *
* The `versioned` flag currently only has the effect that an `_iversion` column is also copied to * The `versioned` flag currently only has the effect that an `_iversion` column is also copied to
* the target. * the target.
*
* Parameters
* ----------
* sourceSet : VARCHAR(255)
* The name of the table from where we start.
* targetSet : VARCHAR(255)
* The name of the table where we collect all the "good" ids (or NULL or same as sourceSet).
* o : CHAR(2)
* The operator used for filtering, e.g. '=', '!=', '>', ...
* EntityID : VARCHAR(255)
* An entity id, existing or non-existing, which we use to compare the
* existing entities to using the operator.
* agg : CHAR(3)
* An aggregate function, e.g. 'max' or 'min'. This only makes sense for number-based ids.
* versioned : BOOLEAN
* The filter belongs to a version-aware query (e.g. FIND ANY VERSION OF
* ...) and hence the sourceSet and targetSet have an `_iversion` column.
*/ */
CREATE PROCEDURE db_5_0.applyIDFilter(in sourceSet VARCHAR(255), in targetSet VARCHAR(255), CREATE PROCEDURE db_5_0.applyIDFilter(in sourceSet VARCHAR(255), in targetSet VARCHAR(255),
in o CHAR(2), in vInt BIGINT, in agg CHAR(3), in versioned BOOLEAN) in o CHAR(2), in EntityID VARCHAR(255), in agg CHAR(3), in versioned BOOLEAN)
IDFILTER_LABEL: BEGIN IDFILTER_LABEL: BEGIN
DECLARE data VARCHAR(20000) DEFAULT NULL; DECLARE data VARCHAR(20000) DEFAULT NULL;
DECLARE aggVal VARCHAR(255) DEFAULT NULL; DECLARE aggVal VARCHAR(255) DEFAULT NULL;
DECLARE direction CHAR(4) DEFAULT NULL;
DECLARE entity_id_type VARCHAR(255) DEFAULT "eids.id ";
#-- get aggVal if possible #-- get aggVal if possible
IF agg IS NOT NULL THEN IF agg IS NOT NULL THEN
IF versioned THEN IF versioned THEN
-- TODO versioned queries -- TODO versioned queries
SELECT 1 FROM id_agg_with_versioning_not_implemented; SELECT 1 FROM id_agg_with_versioning_not_implemented;
ELSEIF agg = "max" THEN
SET direction = "DESC";
ELSEIF agg = "min" THEN
SET direction = "ASC ";
ELSE
SELECT 1 FROM unknown_agg_parameter;
END IF; END IF;
SET @stmtIDAggValStr = CONCAT( SET @stmtIDAggValStr = CONCAT(
"SELECT ", "SELECT e.internal_id INTO @sAggVal FROM `",
agg,
"(id) INTO @sAggVal FROM `",
sourceSet, sourceSet,
"`"); "` AS s LEFT JOIN entity_ids AS e ON (s.id=e.internal_id) WHERE s.id>99 ORDER BY CAST(e.id AS UNSIGNED INT) ",
direction,
" LIMIT 1");
PREPARE stmtIDAggVal FROM @stmtIDAggValStr; PREPARE stmtIDAggVal FROM @stmtIDAggValStr;
EXECUTE stmtIDAggVal; EXECUTE stmtIDAggVal;
DEALLOCATE PREPARE stmtIDAggVal; DEALLOCATE PREPARE stmtIDAggVal;
SET aggVal = @sAggVal; SET aggVal = @sAggVal;
END IF; END IF;
IF o = ">" OR o = ">=" OR o = "<" or o = "<=" THEN
SET entity_id_type = "CAST(eids.id AS UNSIGNED INT) ";
END IF;
#-- generate stmt string #-- generate stmt string
IF targetSet IS NULL OR targetSet = sourceSet THEN IF targetSet IS NULL OR targetSet = sourceSet THEN
SET data = CONCAT( SET data = CONCAT(
"DELETE FROM `", "DELETE FROM `",
sourceSet, sourceSet,
"` WHERE ", "` WHERE ",
IF(o IS NULL OR vInt IS NULL, IF(o IS NULL OR EntityID IS NULL,
"1=1", "1=1",
CONCAT("NOT id", CONCAT("NOT EXISTS (SELECT 1 FROM entity_ids AS eids WHERE ",
entity_id_type,
o, o,
vInt)), ' "',
EntityID,
'" ',
" AND eids.internal_id = `",
sourceSet,
"`.id)"
)),
IF(aggVal IS NULL, IF(aggVal IS NULL,
"", "",
CONCAT(" AND id!=", CONCAT(" AND `", sourceSet, "`.id!=",
aggVal))); aggVal)));
ELSEIF versioned AND sourceSet = "entities" THEN ELSEIF versioned AND sourceSet = "entities" THEN
-- ################# VERSIONING ##################### -- ################# VERSIONING #####################
SET data = CONCAT( SET data = CONCAT(
"INSERT IGNORE INTO `", "INSERT IGNORE INTO `",
targetSet, targetSet,
'` (id, _iversion) SELECT id, _get_head_iversion(id) FROM `entities` WHERE ', '` (id, _iversion) SELECT e.id, _get_head_iversion(e.id) FROM `entities` AS e JOIN entity_ids AS eids ON (e.id = eids.internal_id) WHERE ',
IF(o IS NULL OR vInt IS NULL, IF(o IS NULL OR EntityID IS NULL,
"1=1", "1=1",
CONCAT("id", CONCAT(entity_id_type,
o, o,
vInt)), ' "',
EntityID,
'"'
)),
IF(aggVal IS NULL, IF(aggVal IS NULL,
"", "",
CONCAT(" AND id=", CONCAT(" AND e.id=",
aggVal)), aggVal)),
' UNION SELECT id, _iversion FROM `archive_entities` WHERE ', ' UNION SELECT e.id, _iversion FROM `archive_entities` AS e JOIN entity_ids AS eids ON (e.id = eids.internal_id) WHERE ',
IF(o IS NULL OR vInt IS NULL, IF(o IS NULL OR EntityID IS NULL,
"1=1", "1=1",
CONCAT("id", CONCAT(entity_id_type,
o, o,
vInt)), ' "',
EntityID,
'"'
)),
IF(aggVal IS NULL, IF(aggVal IS NULL,
"", "",
CONCAT(" AND id=", CONCAT(" AND e.id=",
aggVal))); aggVal)));
-- ################################################## -- ##################################################
...@@ -108,12 +150,15 @@ ELSE ...@@ -108,12 +150,15 @@ ELSE
'` (id, _iversion) SELECT data.id, data._iversion FROM `', '` (id, _iversion) SELECT data.id, data._iversion FROM `',
'` (id) SELECT data.id FROM `'), '` (id) SELECT data.id FROM `'),
sourceSet, sourceSet,
"` AS data WHERE ", "` AS data JOIN entity_ids AS eids ON (eids.internal_id = data.id) WHERE ",
IF(o IS NULL OR vInt IS NULL, IF(o IS NULL OR EntityID IS NULL,
"1=1", "1=1",
CONCAT("data.id", CONCAT(entity_id_type,
o, o,
vInt)), ' "',
EntityID,
'"'
)),
IF(aggVal IS NULL, IF(aggVal IS NULL,
"", "",
CONCAT(" AND data.id=", CONCAT(" AND data.id=",
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
...@@ -17,8 +16,6 @@ ...@@ -17,8 +16,6 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
/* Documentation including (?) has to be checked by an expert. */ /* Documentation including (?) has to be checked by an expert. */
...@@ -37,30 +34,31 @@ DELIMITER // ...@@ -37,30 +34,31 @@ DELIMITER //
* ---------- * ----------
* *
* versioned : boolean * versioned : boolean
* If True, sourceSet and targetSet have an _iversion column, otherwise that column will be * If True, sourceSet and targetSet have an _iversion column, otherwise that column will be ignored
* ignored (or only HEAD will be inserted into targetSet). * (or only HEAD will be inserted into targetSet).
*/ */
CREATE PROCEDURE db_5_0.applyPOV(in sourceSet VARCHAR(255), /* (?) Name of the table that the POV will be applied to. This can be a temporary table. */ CREATE PROCEDURE db_5_0.applyPOV(in sourceSet VARCHAR(255), /* Name of the table that the POV will be applied to. This can be a temporary table or the `entities` table */
in targetSet VARCHAR(255), /* (?) Name of the result table of this POV. */ in targetSet VARCHAR(255), /* Name of the result table of this POV. After the filter has been applied this table only contains matching
entity ids. This may be NULL or same as sourceSet. In that case the filter is applied in-place (delete non-matching). Otherwise the filter is applied by copying only the matching ids from the *source* set to the *target* set. */
in propertiesTable VARCHAR(255), in propertiesTable VARCHAR(255),
in refIdsTable VARCHAR(255), in refIdsTable VARCHAR(255), /* Name of a tmp table that contains all ids of children of the value interpreted as entity name or id */
in o CHAR(4), /* The operator for this operation. can be one of: in o CHAR(4), /* The operator for this operation. can be one of:
0 check for "equals NULL" 0 check for "equals NULL"
!0 check for "not NULL" !0 check for "not NULL"
-> check whether a reference exists -> check whether a reference exists
( (?) check for datetime intervals ( check for datetime interval (say "in")
!( (?) check for being outside of datetime intervals !( check for being outside of datetime intervals (say "not in")
other operators (all SQL operators (?)) other operators (all valid SQL operators)
these other operators can be used either with or without an aggregation these other operators can be used either with or without an aggregation
to use an aggregation set agg to non-zero to use an aggregation set agg to non-zero
all SQL aggregations can be used all SQL aggregations can be used
*/ */
in vText VARCHAR(255), /* (?) the text value to be checked against using operator o */ in vText VARCHAR(255), /* the text value to be checked against using operator o */
in vInt INT, /* the integer value to be checked against using operator o */ in vInt INT, /* the integer value to be checked against using operator o */
in vDouble DOUBLE, /* the double value to be checked against using operator o */ in vDouble DOUBLE, /* the double value to be checked against using operator o */
in unit_sig BIGINT, in unit_sig BIGINT, /* signatur of the unit given by the user. used when we need to convert units. */
in vDoubleStdUnit DOUBLE, /* The numeric value, converted according to the unit rules. */ in vDoubleStdUnit DOUBLE, /* The numeric value, converted according to the unit rules. */
in stdUnit_sig BIGINT, in stdUnit_sig BIGINT, /* signatur of the normalized/standardized unit, e.g when unit_sig is "km/h" this might be "m/s". */
in vDateTime VARCHAR(255), in vDateTime VARCHAR(255),
in vDateTimeDotNotation VARCHAR(255), in vDateTimeDotNotation VARCHAR(255),
in agg CHAR(3), /* an SQL aggregate function or NULL when no aggregation should be used */ in agg CHAR(3), /* an SQL aggregate function or NULL when no aggregation should be used */
...@@ -84,6 +82,10 @@ POV_LABEL: BEGIN ...@@ -84,6 +82,10 @@ POV_LABEL: BEGIN
DECLARE keepTabl VARCHAR(255) DEFAULT NULL; DECLARE keepTabl VARCHAR(255) DEFAULT NULL;
DECLARE existence_op VARCHAR(255) DEFAULT "EXISTS"; DECLARE existence_op VARCHAR(255) DEFAULT "EXISTS";
#-- ######### HINT ##############
#-- first the appropriate statement is created which in the end prepared and executed
#-- #############################
IF o = '->' THEN IF o = '->' THEN
#-- special case: pure reference property #-- special case: pure reference property
call applyRefPOV(sourceSet,targetSet, propertiesTable, refIdsTable, versioned); call applyRefPOV(sourceSet,targetSet, propertiesTable, refIdsTable, versioned);
...@@ -232,6 +234,8 @@ POV_LABEL: BEGIN ...@@ -232,6 +234,8 @@ POV_LABEL: BEGIN
IF o = "!=" AND refIdsTable IS NOT NULL THEN IF o = "!=" AND refIdsTable IS NOT NULL THEN
SET existence_op = "NOT EXISTS"; SET existence_op = "NOT EXISTS";
END IF; END IF;
/* select all entities that reference the entity or a child of the
* value interpreted as ID*/
SET sRefData = IF(vText IS NULL, SET sRefData = IF(vText IS NULL,
' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `reference_data`', ' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `reference_data`',
IF(refIdsTable IS NULL, IF(refIdsTable IS NULL,
...@@ -246,6 +250,7 @@ POV_LABEL: BEGIN ...@@ -246,6 +250,7 @@ POV_LABEL: BEGIN
END IF; END IF;
#-- create array of statement parts (and replace null with empty string) (?)
SET data = CONCAT('(',sTextData, SET data = CONCAT('(',sTextData,
IF(sNameData IS NULL, '', sNameData), IF(sNameData IS NULL, '', sNameData),
IF(sEnumData IS NULL, '', sEnumData), IF(sEnumData IS NULL, '', sEnumData),
...@@ -262,6 +267,7 @@ POV_LABEL: BEGIN ...@@ -262,6 +267,7 @@ POV_LABEL: BEGIN
call createTmpTable(keepTabl, versioned); call createTmpTable(keepTabl, versioned);
IF versioned THEN IF versioned THEN
#-- generate statement from statement parts #-- generate statement from statement parts
#-- (versioned section)
SET @stmtPOVkeepTblStr = CONCAT( SET @stmtPOVkeepTblStr = CONCAT(
'INSERT IGNORE INTO `', keepTabl, '` (id, _iversion) SELECT entity_id AS id, _iversion FROM ', data, 'INSERT IGNORE INTO `', keepTabl, '` (id, _iversion) SELECT entity_id AS id, _iversion FROM ', data,
' as data', IF(propertiesTable IS NULL, '', CONCAT( ' as data', IF(propertiesTable IS NULL, '', CONCAT(
...@@ -302,7 +308,14 @@ POV_LABEL: BEGIN ...@@ -302,7 +308,14 @@ POV_LABEL: BEGIN
DEALLOCATE PREPARE stmtPOVkeepTbl; DEALLOCATE PREPARE stmtPOVkeepTbl;
ELSE ELSE
#-- generate statement from statement parts #-- generate statement from statement parts
SET @stmtPOVkeepTblStr = CONCAT('INSERT IGNORE INTO `', keepTabl, '` (id) SELECT DISTINCT entity_id AS id FROM ', data, ' as data', IF(propertiesTable IS NULL, '', CONCAT(' WHERE EXISTS (Select 1 from `', propertiesTable, '` AS prop WHERE prop.id = data.property_id AND (prop.id2=data.entity_id OR prop.id2=0))'))); SET @stmtPOVkeepTblStr = CONCAT(
'INSERT IGNORE INTO `', keepTabl,
'` (id) SELECT DISTINCT entity_id AS id FROM ', data, ' as data',
IF(propertiesTable IS NULL, '',
CONCAT(' WHERE EXISTS (Select 1 from `', propertiesTable,
'` AS prop WHERE prop.id = data.property_id AND
(prop.id2=data.entity_id OR prop.id2=0))')));
#-- (unversioned section)
SET @stmtPOVStr = CONCAT( SET @stmtPOVStr = CONCAT(
IF(targetSet IS NULL, IF(targetSet IS NULL,
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -17,17 +18,45 @@ ...@@ -17,17 +18,45 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.applyTransactionFilter; DROP PROCEDURE IF EXISTS db_5_0.applyTransactionFilter;
DELIMITER // DELIMITER //
/*
* Apply a transaction filter to the sourceSet and collect the remaining
* entities in the targetSet.
*
* Parameters
* ----------
* sourceSet : VARCHAR(255)
* The name of the table from where we start.
* targetSet : VARCHAR(255)
* The name of the table where we collect all the "good" ids (or NULL or same as sourceSet).
* transaction : VARCHAR(255)
* The transaction's type (INSERT, UPDATE,...)
* operator_u : CHAR(2)
* The operator used for filtering by the user, e.g. '=', '!='.
* realm : VARCHAR(255)
* The user's realm (if filtering by the user).
* userName : VARCHAR(255)
* The user's name (if filtering by the user).
* ilb : BIGINT
* Inclusive Lower Bound of seconds for the transactions time.
* ilb_nanos : BIGINT
* Inclusive Lower Bound of nanoseconds for the transactions time.
* eub : BIGINT
* Exclusive Upper Bound of seconds for the transactions time.
* eub_nanos : BIGINT
* Exclusive Upper Bound of nanoseconds for the transactions time.
* operator_t : CHAR(2)
* The operator used for filtering by the transaction time, e.g. '=', '!=', '<', '>='.
*/
CREATE PROCEDURE db_5_0.applyTransactionFilter(in sourceSet VARCHAR(255), targetSet VARCHAR(255), in transaction VARCHAR(255), in operator_u CHAR(2), in realm VARCHAR(255), in userName VARCHAR(255), in ilb BIGINT, in ilb_nanos INT UNSIGNED, in eub BIGINT, in eub_nanos INT UNSIGNED, in operator_t CHAR(2)) CREATE PROCEDURE db_5_0.applyTransactionFilter(in sourceSet VARCHAR(255), targetSet VARCHAR(255), in transaction VARCHAR(255), in operator_u CHAR(2), in realm VARCHAR(255), in userName VARCHAR(255), in ilb BIGINT, in ilb_nanos INT UNSIGNED, in eub BIGINT, in eub_nanos INT UNSIGNED, in operator_t CHAR(2))
BEGIN BEGIN
DECLARE data TEXT default CONCAT('(SELECT entity_id FROM transaction_log AS t WHERE t.transaction=\'', DECLARE data TEXT default CONCAT("(SELECT internal_id AS entity_id FROM transaction_log AS t JOIN entity_ids AS eids ON ( t.entity_id = eids.id ) WHERE t.transaction='",
transaction, transaction,
'\'', "'",
IF(userName IS NOT NULL, IF(userName IS NOT NULL,
CONCAT(' AND t.realm', operator_u, '? AND t.username', operator_u, '?'), CONCAT(' AND t.realm', operator_u, '? AND t.username', operator_u, '?'),
'' ''
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -17,27 +18,52 @@ ...@@ -17,27 +18,52 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.initBackReference; DROP PROCEDURE IF EXISTS db_5_0.initBackReference;
DELIMITER // DELIMITER //
CREATE PROCEDURE db_5_0.initBackReference(in pid INT UNSIGNED, in pname VARCHAR(255), in entity_id INT UNSIGNED, in ename VARCHAR(255))
/*
* Create and initialize two new temporary tables.
*
* This is used to initialize the filterin for backreferences to a
* particular entity (specified by EntityID or EntityName) or using a
* particular property (specified by PropertyID or PropertyName).
*
* The propertiesTable contains all properties matching the PropertyID or
* PropertyName. The entitiesTable contains all entities matching EntityID or
* EntityName.
* Parameters
* ----------
* PropertyID : VARCHAR(255)
* The property's (external) id.
* PropertyName : VARCHAR(255)
* The property's name.
* EntityID : VARCHAR(255)
* The entity's (external) id.
* EntityName : VARCHAR(255)
* The entity's name.
*
* Select
* ------
* Tuple (propertiesTable, entitiesTable)
*/
CREATE PROCEDURE db_5_0.initBackReference(in PropertyID VARCHAR(255), in PropertyName VARCHAR(255), in EntityID VARCHAR(255), in EntityName VARCHAR(255))
BEGIN BEGIN
DECLARE propertiesTable VARCHAR(255) DEFAULT NULL; DECLARE propertiesTable VARCHAR(255) DEFAULT NULL;
DECLARE entitiesTable VARCHAR(255) DEFAULT NULL; DECLARE entitiesTable VARCHAR(255) DEFAULT NULL;
IF pname IS NOT NULL THEN IF PropertyName IS NOT NULL THEN
-- TODO versioning for properties -- TODO versioning for properties
call createTmpTable(propertiesTable, FALSE); call createTmpTable(propertiesTable, FALSE);
call initSubEntity(pid, pname, propertiesTable); call initSubEntity(PropertyID, PropertyName, propertiesTable);
END IF; END IF;
IF ename IS NOT NULL THEN IF EntityName IS NOT NULL THEN
-- TODO versioning for referencing entities -- TODO versioning for referencing entities
call createTmpTable(entitiesTable, FALSE); call createTmpTable(entitiesTable, FALSE);
call initSubEntity(entity_id, ename, entitiesTable); call initSubEntity(EntityID, EntityName, entitiesTable);
END IF; END IF;
SELECT propertiesTable, entitiesTable; SELECT propertiesTable, entitiesTable;
......
...@@ -30,7 +30,7 @@ DELIMITER // ...@@ -30,7 +30,7 @@ DELIMITER //
* If `versioned` is `TRUE`, also add archived entities (for example if the name was changed in the * If `versioned` is `TRUE`, also add archived entities (for example if the name was changed in the
* past). * past).
*/ */
CREATE PROCEDURE db_5_0.initEntity(in eid INT UNSIGNED, in ename VARCHAR(255), CREATE PROCEDURE db_5_0.initEntity(in eid VARCHAR(255), in ename VARCHAR(255),
in enameLike VARCHAR(255), in enameRegexp VARCHAR(255), in enameLike VARCHAR(255), in enameRegexp VARCHAR(255),
in resultset VARCHAR(255), in versioned BOOLEAN) in resultset VARCHAR(255), in versioned BOOLEAN)
initEntityLabel: BEGIN initEntityLabel: BEGIN
...@@ -78,11 +78,12 @@ initEntityLabel: BEGIN ...@@ -78,11 +78,12 @@ initEntityLabel: BEGIN
'INSERT IGNORE INTO `', 'INSERT IGNORE INTO `',
resultset, resultset,
IF(versioned, IF(versioned,
'` (id, _iversion) SELECT id, _get_head_iversion(id) ', '` (id, _iversion) SELECT eids.internal_id, _get_head_iversion(eids.internal_id) ',
'` (id) SELECT id '), '` (id) SELECT eids.internal_id '),
'FROM entities WHERE id=',eid,';'); 'FROM entity_ids AS eids WHERE eids.id=?;');
SET @query_param = eid;
PREPARE initEntityStmt FROM @initEntityStmtStr; PREPARE initEntityStmt FROM @initEntityStmtStr;
EXECUTE initEntityStmt; EXECUTE initEntityStmt USING @query_param;
DEALLOCATE PREPARE initEntityStmt; DEALLOCATE PREPARE initEntityStmt;
END IF; END IF;
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -17,15 +18,32 @@ ...@@ -17,15 +18,32 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DELIMITER // DELIMITER //
DROP PROCEDURE IF EXISTS db_5_0.initPOVPropertiesTable// DROP PROCEDURE IF EXISTS db_5_0.initPOVPropertiesTable//
CREATE PROCEDURE db_5_0.initPOVPropertiesTable(in pid INT UNSIGNED, in pname VARCHAR(255), in sourceSet VARCHAR(255)) /*
* Create and initialize a new temporary table.
*
* This is used to initialize the POV filtering. The resulting table
* contains all properties matching the Property component of the POV filter.
*
* Parameters
* ----------
* PropertyID : VARCHAR(255)
* The property's (external) id.
* PropertyName : VARCHAR(255)
* The property's name.
* sourceSet : VARCHAR(255)
* The name of the table which will be filtered by the POV filter.
*
* Select
* ------
* Tuple (propertiesTable, ... and a lot of debug output)
*/
CREATE PROCEDURE db_5_0.initPOVPropertiesTable(in PropertyID VARCHAR(255), in PropertyName VARCHAR(255), in sourceSet VARCHAR(255))
BEGIN BEGIN
DECLARE propertiesTable VARCHAR(255) DEFAULT NULL; /*table for property ids*/ DECLARE propertiesTable VARCHAR(255) DEFAULT NULL; /*table for property ids*/
DECLARE replTbl VARCHAR(255) DEFAULT NULL; DECLARE replTbl VARCHAR(255) DEFAULT NULL;
...@@ -38,24 +56,31 @@ BEGIN ...@@ -38,24 +56,31 @@ BEGIN
DECLARE t6 BIGINT DEFAULT 0; DECLARE t6 BIGINT DEFAULT 0;
IF pname is NOT NULL THEN IF PropertyName is NOT NULL THEN
SELECT conv( concat( substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)),16,10) div 10000 - (141427 * 24 * 60 * 60 * 1000) as current_mills INTO t1 from (select uuid() uid) as alias; SELECT conv( concat( substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)),16,10) div 10000 - (141427 * 24 * 60 * 60 * 1000) as current_mills INTO t1 from (select uuid() uid) as alias;
call createTmpTable2(propertiesTable); call createTmpTable2(propertiesTable);
-- fill in all properties named "pname" -- Fill in all properties (plus the domain id and entity id) named
-- "PropertyName", be it their default name or their overridden name.
-- We need *all* properties (mind, the properties of entities not
-- abstract properties) with the given name. If an abstract
-- property has the name "person" it might have the name "author" in
-- the "Article" record type. Now, if I want to collect all properties
-- of the Article named "author" I need to look into the name_overrides
-- table.
SET @initPOVPropertiesTableStmt1 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) SELECT property_id, entity_id, domain_id from name_overrides WHERE name = ? UNION ALL SELECT entity_id, domain_id, 0 FROM name_data WHERE value = ?;'); SET @initPOVPropertiesTableStmt1 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) SELECT property_id, entity_id, domain_id from name_overrides WHERE name = ? UNION ALL SELECT entity_id, domain_id, 0 FROM name_data WHERE value = ?;');
PREPARE stmt FROM @initPOVPropertiesTableStmt1; PREPARE stmt FROM @initPOVPropertiesTableStmt1;
SET @pname = pname; SET @PropertyName = PropertyName;
EXECUTE stmt USING @pname, @pname; EXECUTE stmt USING @PropertyName, @PropertyName;
SET ecount = ROW_COUNT(); SET ecount = ROW_COUNT();
-- fill in all properties with id="pid" -- fill in all properties with id="PropertyID"
SELECT conv( concat( substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)),16,10) div 10000 - (141427 * 24 * 60 * 60 * 1000) as current_mills INTO t2 from (select uuid() uid) as alias; SELECT conv( concat( substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)),16,10) div 10000 - (141427 * 24 * 60 * 60 * 1000) as current_mills INTO t2 from (select uuid() uid) as alias;
IF pid IS NOT NULL THEN IF PropertyID IS NOT NULL THEN
SET @initPOVPropertiesTableStmt2 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) VALUES (?, 0, 0)'); SET @initPOVPropertiesTableStmt2 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) VALUES (?, 0, 0)');
PREPARE stmt FROM @initPOVPropertiesTableStmt2; PREPARE stmt FROM @initPOVPropertiesTableStmt2;
SET @pid = pid; SET @PropertyID = PropertyID;
EXECUTE stmt USING @pid; EXECUTE stmt USING @PropertyID;
SET ecount = ecount + ROW_COUNT(); SET ecount = ecount + ROW_COUNT();
END IF; END IF;
...@@ -91,15 +116,33 @@ END // ...@@ -91,15 +116,33 @@ END //
DROP PROCEDURE IF EXISTS db_5_0.initPOVRefidsTable // DROP PROCEDURE IF EXISTS db_5_0.initPOVRefidsTable //
CREATE PROCEDURE db_5_0.initPOVRefidsTable(in vInt INT UNSIGNED, in vText VARCHAR(255)) /*
* Create and initialize a new temporary table.
*
* This used to initialize the POV filtering. The resulting table
* contains all entities matching the Value component of the POV filter (i.e.
* the referenced entities).
*
* Parameters
* ----------
* PropertyID : VARCHAR(255)
* The property's (external) id.
* PropertyName : VARCHAR(255)
* The property's name.
*
* Select
* ------
* Tuple (refIdsTable)
*/
CREATE PROCEDURE db_5_0.initPOVRefidsTable(in PropertyID VARCHAR(255), in PropertyName VARCHAR(255))
BEGIN BEGIN
DECLARE refIdsTable VARCHAR(255) DEFAULT NULL; /*table for referenced entity ids*/ DECLARE refIdsTable VARCHAR(255) DEFAULT NULL; /*table for referenced entity ids*/
#-- for reference properties: the value is interpreted as a record type name. #-- for reference properties: the value is interpreted as a record type name.
IF vText IS NOT NULL THEN IF PropertyName IS NOT NULL THEN
-- TODO versioned queries -- TODO versioned queries
call createTmpTable(refIdsTable, FALSE); call createTmpTable(refIdsTable, FALSE);
call initSubEntity(vInt, vText, refIdsTable); call initSubEntity(PropertyID, PropertyName, refIdsTable);
#-- now, all ids are in the refIdsTable #-- now, all ids are in the refIdsTable
END IF; END IF;
SELECT refIdsTable; SELECT refIdsTable;
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -17,20 +18,35 @@ ...@@ -17,20 +18,35 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.initSubEntity; DROP PROCEDURE IF EXISTS db_5_0.initSubEntity;
DELIMITER // DELIMITER //
/*
CREATE PROCEDURE db_5_0.initSubEntity(in e_id INT UNSIGNED, in ename VARCHAR(255), in tableName VARCHAR(255)) * Initialize a new temporary table by loading an entity (by name or by id or
* both) and all of its children into the table (i.e. their internal ids).
*
* The table name has to be provided.
*
* This is used by initPOVRefidsTable and initBackReference for sub-property filtering.
*
* Parameters
* ----------
* EntityID : VARCHAR(255)
* The entity's (external) id.
* EntityName : VARCHAR(255)
* The entity's name.
* tableName : VARCHAR(255)
* The table which is to be initialized.
*/
CREATE PROCEDURE db_5_0.initSubEntity(in EntityID VARCHAR(255), in ename VARCHAR(255), in tableName VARCHAR(255))
BEGIN BEGIN
DECLARE ecount INT DEFAULT 0; DECLARE ecount INT DEFAULT 0;
DECLARE op VARCHAR(255) DEFAULT '='; DECLARE op VARCHAR(255) DEFAULT '=';
IF LOCATE("%", ename) > 0 THEN IF LOCATE("%", ename) > 0 THEN
SET op = "LIKE"; SET op = "LIKE";
END IF; END IF;
...@@ -47,10 +63,11 @@ BEGIN ...@@ -47,10 +63,11 @@ BEGIN
SET ecount = ROW_COUNT(); SET ecount = ROW_COUNT();
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
IF e_id IS NOT NULL THEN IF EntityID IS NOT NULL THEN
SET @stmtStr = CONCAT('INSERT IGNORE INTO `', tableName, '` (id) VALUES (', e_id, ')'); SET @stmtStr = CONCAT('INSERT IGNORE INTO `', tableName, '` (id) SELECT internal_id FROM entity_ids WHERE id = ?');
PREPARE stmt FROM @stmtStr; PREPARE stmt FROM @stmtStr;
EXECUTE stmt; SET @eid = EntityID;
EXECUTE stmt USING @eid;
SET ecount = ecount + ROW_COUNT(); SET ecount = ecount + ROW_COUNT();
DEALLOCATE PREPARE stmt; DEALLOCATE PREPARE stmt;
END IF; END IF;
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <www.indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -17,33 +18,25 @@ ...@@ -17,33 +18,25 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.registerSubdomain; DROP PROCEDURE IF EXISTS db_5_0.registerSubdomain;
DROP PROCEDURE IF EXISTS db_5_0.registerReplacementIds;
delimiter // delimiter //
CREATE PROCEDURE db_5_0.registerSubdomain(in amount INT UNSIGNED) CREATE PROCEDURE db_5_0.registerReplacementIds(in amount INT UNSIGNED)
BEGIN BEGIN
DECLARE ED INTEGER DEFAULT NULL; DECLARE ED INTEGER DEFAULT NULL;
SELECT COUNT(id) INTO ED FROM entities WHERE Role='DOMAIN' AND id!=0; SELECT COUNT(id) INTO ED FROM entities WHERE Role='_REPLACEMENT' AND id!=0;
WHILE ED < amount DO WHILE ED < amount DO
INSERT INTO entities (description, role, acl) VALUES INSERT INTO entities (description, role, acl) VALUES
(NULL, 'DOMAIN', 0); (NULL, '_REPLACEMENT', 0);
SET ED = ED + 1; SET ED = ED + 1;
END WHILE; END WHILE;
SELECT id as DomainID FROM entities WHERE Role='DOMAIN' and id!=0; SELECT CONCAT("$", e.id) as ReplacementID FROM entities AS e WHERE e.Role='_REPLACEMENT' and e.id!=0;
END; END;
// //
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.retrieveDatatype;
delimiter //
CREATE PROCEDURE db_5_0.retrieveDatatype(in DatatypeName VARCHAR(255))
BEGIN
Select e.id INTO @DatatypeID from entities e where e.name=DatatypeName AND e.role='DATATYPE' LIMIT 1;
call retrieveEntity(@DatatypeID);
END;
//
delimiter ;
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> * Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale * Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -19,8 +18,6 @@ ...@@ -19,8 +18,6 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
...@@ -36,30 +33,40 @@ drop procedure if exists db_5_0.retrieveEntity // ...@@ -36,30 +33,40 @@ drop procedure if exists db_5_0.retrieveEntity //
* *
* Parameters * Parameters
* ---------- * ----------
* EntityID * EntityID : VARCHAR(255)
* The entity's id. * The entity's id.
* Version * Version : VARBINARY(255)
* The version id. In this procedure only, the version may also be given as * The version id. In this procedure only, the version may also be given as
* `HEAD` for the latest version or as `HEAD~n`, which retrieves the n-th * `HEAD` for the latest version or as `HEAD~n`, which retrieves the n-th
* ancestor of `HEAD`. * ancestor of `HEAD`.
* *
* ResultSet * ResultSet
* --------- * ---------
* Tuple of (Datatype, Collection, EntityID, EntityName, EntityDesc, * Tuple of (DatatypeID, DatatypeName, Collection, EntityID, EntityName,
* EntityRole, FileSize, FilePath, FileHash, ACL, Version) * EntityDesc, EntityRole, FileSize, FilePath, FileHash, ACL,
* Version)
*/ */
create procedure db_5_0.retrieveEntity( create procedure db_5_0.retrieveEntity(
in EntityID INT UNSIGNED, in EntityID VARCHAR(255),
in Version VARBINARY(255)) in Version VARBINARY(255))
retrieveEntityBody: BEGIN retrieveEntityBody: BEGIN
DECLARE FilePath VARCHAR(255) DEFAULT NULL; DECLARE FilePath VARCHAR(255) DEFAULT NULL;
DECLARE FileSize VARCHAR(255) DEFAULT NULL; DECLARE FileSize VARCHAR(255) DEFAULT NULL;
DECLARE FileHash 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 CollectionName VARCHAR(255) DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE; DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE IVersion INT UNSIGNED DEFAULT NULL; DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID from entity_ids WHERE id = EntityID;
IF InternalEntityID IS NULL THEN
-- RETURN EARLY - Entity does not exist.
SELECT 0 FROM entities WHERE 0 = 1;
LEAVE retrieveEntityBody;
END IF;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
-- Find out head-ness and version -- Find out head-ness and version
...@@ -73,7 +80,7 @@ retrieveEntityBody: BEGIN ...@@ -73,7 +80,7 @@ retrieveEntityBody: BEGIN
END IF; END IF;
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
SET IVersion=get_iversion(EntityID, Version); SET IVersion=get_iversion(InternalEntityID, Version);
IF IVersion IS NULL THEN IF IVersion IS NULL THEN
-- RETURN EARLY - Version does not exist. -- RETURN EARLY - Version does not exist.
...@@ -84,16 +91,16 @@ retrieveEntityBody: BEGIN ...@@ -84,16 +91,16 @@ retrieveEntityBody: BEGIN
SELECT path, size, HEX(hash) SELECT path, size, HEX(hash)
INTO FilePath, FileSize, FileHash INTO FilePath, FileSize, FileHash
FROM archive_files FROM archive_files
WHERE file_id = EntityID WHERE file_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
LIMIT 1; LIMIT 1;
SELECT datatype SELECT datatype
INTO DatatypeID INTO InternalDatatypeID
FROM archive_data_type FROM archive_data_type
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_id = 0 AND entity_id = 0
AND property_id = EntityID AND property_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
LIMIT 1; LIMIT 1;
...@@ -102,7 +109,7 @@ retrieveEntityBody: BEGIN ...@@ -102,7 +109,7 @@ retrieveEntityBody: BEGIN
FROM archive_collection_type FROM archive_collection_type
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_id = 0 AND entity_id = 0
AND property_id = EntityID AND property_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
LIMIT 1; LIMIT 1;
...@@ -111,18 +118,17 @@ retrieveEntityBody: BEGIN ...@@ -111,18 +118,17 @@ retrieveEntityBody: BEGIN
( SELECT value FROM ( SELECT value FROM
( SELECT value FROM name_data ( SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_ID = DatatypeID AND entity_id = InternalDatatypeID
AND property_id = 20 AND property_id = 20
UNION SELECT DatatypeID AS value ) AS tmp LIMIT 1 ) AS DatatypeName,
) AS tmp LIMIT 1 ) AS Datatype, ( SELECT id FROM entity_ids WHERE internal_id=InternalDatatypeID ) AS DatatypeID,
CollectionName AS Collection, CollectionName AS Collection,
EntityID AS EntityID, EntityID AS EntityID,
( SELECT value FROM archive_name_data ( SELECT value FROM archive_name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_ID = EntityID AND entity_ID = InternalEntityID
AND property_id = 20 AND property_id = 20
AND _iversion = IVersion AND _iversion = IVersion
-- LIMIT 1 -- TODO Remove this line if all tests pass.
) AS EntityName, ) AS EntityName,
e.description AS EntityDesc, e.description AS EntityDesc,
e.role AS EntityRole, e.role AS EntityRole,
...@@ -132,7 +138,7 @@ retrieveEntityBody: BEGIN ...@@ -132,7 +138,7 @@ retrieveEntityBody: BEGIN
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL, (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL,
Version AS Version Version AS Version
FROM archive_entities AS e FROM archive_entities AS e
WHERE e.id = EntityID WHERE e.id = InternalEntityID
AND e._iversion = IVersion AND e._iversion = IVersion
LIMIT 1; LIMIT 1;
...@@ -145,33 +151,34 @@ retrieveEntityBody: BEGIN ...@@ -145,33 +151,34 @@ retrieveEntityBody: BEGIN
SELECT path, size, hex(hash) SELECT path, size, hex(hash)
INTO FilePath, FileSize, FileHash INTO FilePath, FileSize, FileHash
FROM files FROM files
WHERE file_id = EntityID WHERE file_id = InternalEntityID
LIMIT 1; LIMIT 1;
SELECT datatype INTO DatatypeID SELECT dt.datatype INTO InternalDatatypeID
FROM data_type FROM data_type as dt
WHERE domain_id=0 WHERE dt.domain_id=0
AND entity_id=0 AND dt.entity_id=0
AND property_id=EntityID AND dt.property_id=InternalEntityID
LIMIT 1; LIMIT 1;
SELECT collection INTO CollectionName SELECT collection INTO CollectionName
FROM collection_type FROM collection_type
WHERE domain_id=0 WHERE domain_id=0
AND entity_id=0 AND entity_id=0
AND property_id=EntityID AND property_id=InternalEntityID
LIMIT 1; LIMIT 1;
SELECT SELECT
( SELECT value FROM name_data ( SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_ID = DatatypeID AND entity_id = InternalDatatypeID
AND property_id = 20 LIMIT 1 ) AS Datatype, AND property_id = 20 LIMIT 1 ) AS DatatypeName,
( SELECT id FROM entity_ids WHERE internal_id=InternalDatatypeID ) AS DatatypeID,
CollectionName AS Collection, CollectionName AS Collection,
EntityID AS EntityID, EntityID AS EntityID,
( SELECT value FROM name_data ( SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_ID = EntityID AND entity_ID = InternalEntityID
AND property_id = 20 LIMIT 1) AS EntityName, AND property_id = 20 LIMIT 1) AS EntityName,
e.description AS EntityDesc, e.description AS EntityDesc,
e.role AS EntityRole, e.role AS EntityRole,
...@@ -180,7 +187,7 @@ retrieveEntityBody: BEGIN ...@@ -180,7 +187,7 @@ retrieveEntityBody: BEGIN
FileHash AS FileHash, FileHash AS FileHash,
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL, (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL,
Version AS Version Version AS Version
FROM entities e WHERE id = EntityID LIMIT 1; FROM entities e WHERE id = InternalEntityID LIMIT 1;
END; END;
// //
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 Indiscale GmbH <info@indiscale.com> * Copyright (C) 2020,2023 Indiscale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -19,25 +18,61 @@ ...@@ -19,25 +18,61 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
DROP PROCEDURE IF EXISTS db_5_0.retrieveOverrides; DROP PROCEDURE IF EXISTS db_5_0.retrieveOverrides;
delimiter // delimiter //
/*
* Retrieve the overridden (overriding the Abstract Property's) name, description, and datatype.
*
* Parameters
* ----------
*
* DomainID : VARCHAR(255)
* The domain id (0 or the entity'id for level-2-data)
* EntityID : VARCHAR(255)
* The entity id (or the property'id for level-2-data)
* Version : VARBINARY(255)
* The version of the entity. Optional
*
* ResultSet
* ---------
* collection_override, # e.g. LIST
* name_override, # the name
* desc_override, # the description
* 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.
* property_id, # the property id
*/
CREATE PROCEDURE db_5_0.retrieveOverrides( CREATE PROCEDURE db_5_0.retrieveOverrides(
in DomainID INT UNSIGNED, in DomainID VARCHAR(255),
in EntityID INT UNSIGNED, in EntityID VARCHAR(255),
in Version VARBINARY(255)) in Version VARBINARY(255))
retrieveOverridesBody: BEGIN retrieveOverridesBody: BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL; DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE; DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
DECLARE InternalDomainID INT UNSIGNED DEFAULT 0;
-- 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;
-- DomainID != 0 are always normal (i.e. external) Entity ids.
SELECT internal_id INTO InternalDomainID from entity_ids WHERE id = DomainID;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
IF Version IS NOT NULL THEN IF Version IS NOT NULL THEN
IF DomainID = 0 THEN IF InternalDomainID = 0 THEN
SELECT get_head_version(EntityID) = Version INTO IsHead; SELECT get_head_version(EntityID) = Version INTO IsHead;
ELSE ELSE
SELECT get_head_version(DomainID) = Version INTO IsHead; SELECT get_head_version(DomainID) = Version INTO IsHead;
...@@ -47,8 +82,8 @@ retrieveOverridesBody: BEGIN ...@@ -47,8 +82,8 @@ retrieveOverridesBody: BEGIN
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
SELECT e._iversion INTO IVersion SELECT e._iversion INTO IVersion
FROM entity_version as e FROM entity_version as e
WHERE ((e.entity_id = EntityID AND DomainID = 0) WHERE ((e.entity_id = InternalEntityID AND InternalDomainID = 0)
OR (e.entity_id = DomainID)) OR (e.entity_id = InternalDomainID))
AND e.version = Version; AND e.version = Version;
IF IVersion IS NULL THEN IF IVersion IS NULL THEN
...@@ -61,12 +96,14 @@ retrieveOverridesBody: BEGIN ...@@ -61,12 +96,14 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override, NULL AS collection_override,
name AS name_override, name AS name_override,
NULL AS desc_override, NULL AS desc_override,
NULL AS type_override, NULL AS type_name_override,
entity_id, NULL AS type_id_override,
property_id EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_name_overrides FROM archive_name_overrides
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
...@@ -76,12 +113,14 @@ retrieveOverridesBody: BEGIN ...@@ -76,12 +113,14 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override, NULL AS collection_override,
NULL AS name_override, NULL AS name_override,
description AS desc_override, description AS desc_override,
NULL AS type_override, NULL AS type_name_override,
entity_id, NULL AS type_id_override,
property_id EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_desc_overrides FROM archive_desc_overrides
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
...@@ -91,16 +130,18 @@ retrieveOverridesBody: BEGIN ...@@ -91,16 +130,18 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override, NULL AS collection_override,
NULL AS name_override, NULL AS name_override,
NULL AS desc_override, NULL AS desc_override,
IFNULL((SELECT value FROM name_data (SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_id = datatype AND entity_id = datatype
AND property_id = 20 AND property_id = 20
LIMIT 1), datatype) AS type_override, LIMIT 1) AS type_name_override,
entity_id, (SELECT id FROM entity_ids WHERE internal_id = datatype) AS type_id_override,
property_id EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_data_type FROM archive_data_type
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
...@@ -110,12 +151,14 @@ retrieveOverridesBody: BEGIN ...@@ -110,12 +151,14 @@ retrieveOverridesBody: BEGIN
collection AS collection_override, collection AS collection_override,
NULL AS name_override, NULL AS name_override,
NULL AS desc_override, NULL AS desc_override,
NULL AS type_override, NULL AS type_name_override,
entity_id, NULL AS type_id_override,
property_id EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_collection_type FROM archive_collection_type
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion; AND _iversion = IVersion;
LEAVE retrieveOverridesBody; LEAVE retrieveOverridesBody;
...@@ -126,12 +169,14 @@ retrieveOverridesBody: BEGIN ...@@ -126,12 +169,14 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override, NULL AS collection_override,
name AS name_override, name AS name_override,
NULL AS desc_override, NULL AS desc_override,
NULL AS type_override, NULL AS type_name_override,
entity_id, NULL AS type_id_override,
property_id EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM name_overrides FROM name_overrides
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
...@@ -139,12 +184,14 @@ retrieveOverridesBody: BEGIN ...@@ -139,12 +184,14 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override, NULL AS collection_override,
NULL AS name_override, NULL AS name_override,
description AS desc_override, description AS desc_override,
NULL AS type_override, NULL AS type_name_override,
entity_id, NULL AS type_id_override,
property_id EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM desc_overrides FROM desc_overrides
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
...@@ -152,15 +199,17 @@ retrieveOverridesBody: BEGIN ...@@ -152,15 +199,17 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override, NULL AS collection_override,
NULL AS name_override, NULL AS name_override,
NULL AS desc_override, NULL AS desc_override,
IFNULL((SELECT value FROM name_data (SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_ID = datatype AND entity_ID = datatype
AND property_id = 20 LIMIT 1), datatype) AS type_override, AND property_id = 20 LIMIT 1) AS type_name_override,
entity_id, (SELECT id FROM entity_ids WHERE internal_id = datatype) AS type_id_override,
property_id EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM data_type FROM data_type
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
...@@ -168,12 +217,14 @@ retrieveOverridesBody: BEGIN ...@@ -168,12 +217,14 @@ retrieveOverridesBody: BEGIN
collection AS collection_override, collection AS collection_override,
NULL AS name_override, NULL AS name_override,
NULL AS desc_override, NULL AS desc_override,
NULL AS type_override, NULL AS type_name_override,
entity_id, NULL AS type_id_override,
property_id EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM collection_type FROM collection_type
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID; AND entity_id = InternalEntityID;
END; END;
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> * Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -19,8 +18,6 @@ ...@@ -19,8 +18,6 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
...@@ -28,37 +25,35 @@ DROP PROCEDURE IF EXISTS db_5_0.retrieveEntityParents; ...@@ -28,37 +25,35 @@ DROP PROCEDURE IF EXISTS db_5_0.retrieveEntityParents;
DELIMITER // DELIMITER //
/* Retrieve the parents of an Entity. /* Retrieve the parents of an Entity.
*
Parameters * Parameters
========== * ----------
* EntityID : VARCHAR(255)
EntityID : UNSIGNED * Child entity for which all parental relations should be deleted.
Child entity for which all parental relations should be deleted. *
* ResultSet
Returns * ---------
======= * ParentID : VARCHAR(255)
ParentID : INT UNSIGNED * Each parent's ID
Each parent's ID * ParentName : VARCHAR(255)
* The parent's name.
ParentName : * ParentDescription : TEXT
The parent's name. * The parent's description.
* ParentRole : VARCHAR(255)
ParentDescription : * The parent's Role.
The parent's description. * ACL : VARBINARY(65525)
* Access control list.
ParentRole :
The parent's Role.
ACL :
Access control list something
*/ */
CREATE PROCEDURE db_5_0.retrieveEntityParents( CREATE PROCEDURE db_5_0.retrieveEntityParents(
in EntityID INT UNSIGNED, in EntityID VARCHAR(255),
in Version VARBINARY(255)) in Version VARBINARY(255))
retrieveEntityParentsBody: BEGIN retrieveEntityParentsBody: BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL; DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE; DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID from entity_ids WHERE id = EntityID;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
IF Version IS NOT NULL THEN IF Version IS NOT NULL THEN
...@@ -68,7 +63,7 @@ retrieveEntityParentsBody: BEGIN ...@@ -68,7 +63,7 @@ retrieveEntityParentsBody: BEGIN
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
SELECT e._iversion INTO IVersion SELECT e._iversion INTO IVersion
FROM entity_version as e FROM entity_version as e
WHERE e.entity_id = EntityID WHERE e.entity_id = InternalEntityID
AND e.version = Version; AND e.version = Version;
IF IVersion IS NULL THEN IF IVersion IS NULL THEN
...@@ -77,10 +72,10 @@ retrieveEntityParentsBody: BEGIN ...@@ -77,10 +72,10 @@ retrieveEntityParentsBody: BEGIN
END IF; END IF;
SELECT SELECT
i.parent AS ParentID, ( SELECT id FROM entity_ids WHERE internal_id = i.parent) AS ParentID,
( SELECT value FROM name_data ( SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_id = ParentID AND entity_id = i.parent
AND property_id = 20 AND property_id = 20
) AS ParentName, -- This is not necessarily the name of the parent at the time of ) AS ParentName, -- This is not necessarily the name of the parent at the time of
-- IVersion but it is a good guess. Future implementations of the -- IVersion but it is a good guess. Future implementations of the
...@@ -92,7 +87,7 @@ retrieveEntityParentsBody: BEGIN ...@@ -92,7 +87,7 @@ retrieveEntityParentsBody: BEGIN
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL
FROM archive_isa AS i JOIN entities AS e FROM archive_isa AS i JOIN entities AS e
ON (i.parent = e.id) ON (i.parent = e.id)
WHERE i.child = EntityID WHERE i.child = InternalEntityID
AND i.child_iversion = IVersion AND i.child_iversion = IVersion
AND i.direct IS TRUE AND i.direct IS TRUE
; ;
...@@ -102,18 +97,18 @@ retrieveEntityParentsBody: BEGIN ...@@ -102,18 +97,18 @@ retrieveEntityParentsBody: BEGIN
END IF; END IF;
SELECT SELECT
i.parent AS ParentID, ( SELECT id FROM entity_ids WHERE internal_id = i.parent) AS ParentID,
( SELECT value FROM name_data ( SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_id = ParentID AND entity_id = i.parent
AND property_id = 20 ) AS ParentName, AND property_id = 20 ) AS ParentName,
e.description AS ParentDescription, e.description AS ParentDescription,
e.role AS ParentRole, e.role AS ParentRole,
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL
FROM isa_cache AS i JOIN entities AS e FROM isa_cache AS i JOIN entities AS e
ON (i.parent = e.id) ON (i.parent = e.id)
WHERE i.child = EntityID WHERE i.child = InternalEntityID
AND i.rpath = EntityID; AND i.rpath = InternalEntityID;
END END
// //
......
/* /*
* ** header v3.0
* This file is a part of the CaosDB Project. * This file is a part of the CaosDB Project.
* *
* Copyright (C) 2018 Research Group Biomedical Physics, * Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen * Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> * Copyright (C) 2020-2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> * Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -19,8 +18,6 @@ ...@@ -19,8 +18,6 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/ */
...@@ -28,30 +25,70 @@ delimiter // ...@@ -28,30 +25,70 @@ delimiter //
drop procedure if exists db_5_0.retrieveEntityProperties // drop procedure if exists db_5_0.retrieveEntityProperties //
/*
* Retrieve the properties of an entity (level 1 and 2).
*
* Parameters
* ----------
*
* DomainID : VARCHAR(255)
* The domain id (0 or the entity's id for level-2-data)
* EntityID : VARCHAR(255)
* The entity id (or the property's id for level-2-data)
* Version : VARBINARY(255)
* The version of the entity. Optional
*
* ResultSet
* ---------
* InternalPropertyID
* Internal property id, to be used when PropertyID
* is NULL because a replacement is used.
* PropertyID
* The property id
* PropertyValue
* The property value
* PropertyStatus
* E.g. OBLIGATORY, FIX, ...
* PropertyIndex
* The index of the property (for ordering).
* )
*/
create procedure db_5_0.retrieveEntityProperties( create procedure db_5_0.retrieveEntityProperties(
in DomainID INT UNSIGNED, in DomainID VARCHAR(255),
in EntityID INT UNSIGNED, in EntityID VARCHAR(255),
in Version VARBINARY(255)) in Version VARBINARY(255))
retrieveEntityPropertiesBody: BEGIN retrieveEntityPropertiesBody: BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL; DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE; DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
DECLARE InternalDomainID INT UNSIGNED DEFAULT 0;
-- 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;
-- DomainID != 0 are always normal (i.e. external) Entity ids.
SELECT internal_id INTO InternalDomainID from entity_ids WHERE id = DomainID;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
IF Version IS NOT NULL THEN IF Version IS NOT NULL THEN
IF DomainID = 0 THEN IF InternalDomainID = 0 THEN
SELECT get_head_version(EntityID) = Version INTO IsHead; SELECT get_head_version(EntityID) = Version INTO IsHead;
ELSE ELSE
SELECT get_head_version(DomainID) = Version INTO IsHead; SELECT get_head_version(DomainID) = Version INTO IsHead;
END IF; END IF;
END IF; END IF;
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
SELECT e._iversion INTO IVersion SELECT e._iversion INTO IVersion
FROM entity_version as e FROM entity_version as e
WHERE ((e.entity_id = EntityID AND DomainID = 0) WHERE ((e.entity_id = InternalEntityID AND InternalDomainID = 0)
OR (e.entity_id = DomainID)) OR (e.entity_id = InternalDomainID))
AND e.version = Version; AND e.version = Version;
IF IVersion IS NULL THEN IF IVersion IS NULL THEN
...@@ -61,121 +98,135 @@ retrieveEntityPropertiesBody: BEGIN ...@@ -61,121 +98,135 @@ retrieveEntityPropertiesBody: BEGIN
#-- double properties #-- double properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_double_data FROM archive_double_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- integer properties #-- integer properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_integer_data FROM archive_integer_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- date properties #-- date properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, '.NULL.NULL') AS PropertyValue, CONCAT(value, '.NULL.NULL') AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_date_data FROM archive_date_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- datetime properties #-- datetime properties
SELECT SELECT
property_id AS PropertyID, 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)) CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns))
AS PropertyValue, AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_datetime_data FROM archive_datetime_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- text properties #-- text properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_text_data FROM archive_text_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- enum properties #-- enum properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_enum_data FROM archive_enum_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- reference properties #-- reference properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
IF(value_iversion IS NULL, value, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
IF(value_iversion IS NULL,
IF(status = "REPLACEMENT",
CONCAT("$", value),
( SELECT id FROM entity_ids WHERE internal_id = value )),
-- make it "value@version" if necessary -- make it "value@version" if necessary
CONCAT(value, "@", _get_version(value, value_iversion))) CONCAT(
( SELECT id FROM entity_ids WHERE internal_id = value ),
"@", _get_version(value, value_iversion)))
AS PropertyValue, AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_reference_data FROM archive_reference_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- null properties #-- null properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
NULL AS PropertyValue, NULL AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_null_data FROM archive_null_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- name properties #-- name properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_name_data FROM archive_name_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND property_id != 20 AND property_id != 20
AND _iversion = IVersion; AND _iversion = IVersion;
...@@ -185,115 +236,129 @@ retrieveEntityPropertiesBody: BEGIN ...@@ -185,115 +236,129 @@ retrieveEntityPropertiesBody: BEGIN
#-- double properties #-- double properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM double_data FROM double_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- integer properties #-- integer properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM integer_data FROM integer_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- date properties #-- date properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, '.NULL.NULL') AS PropertyValue, CONCAT(value, '.NULL.NULL') AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM date_data FROM date_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- datetime properties #-- datetime properties
SELECT SELECT
property_id AS PropertyID, 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)) CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns))
AS PropertyValue, AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM datetime_data FROM datetime_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- text properties #-- text properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM text_data FROM text_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- enum properties #-- enum properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM enum_data FROM enum_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- reference properties #-- reference properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
IF(value_iversion IS NULL, value, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, "@", _get_version(value, value_iversion))) IF(value_iversion IS NULL,
IF(status = "REPLACEMENT",
CONCAT("$", value),
( SELECT id FROM entity_ids WHERE internal_id = value )),
-- make it "value@version" if necessary
CONCAT(
( SELECT id FROM entity_ids WHERE internal_id = value ),
"@", _get_version(value, value_iversion)))
AS PropertyValue, AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM reference_data FROM reference_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- null properties #-- null properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
NULL AS PropertyValue, NULL AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM null_data FROM null_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- name properties #-- name properties
SELECT SELECT
property_id AS PropertyID, CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM name_data FROM name_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND property_id != 20; AND property_id != 20;
END; END;
// //
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
Drop Procedure if exists db_5_0.retrieveGroup;