-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from romfabbro/com_ERD_eColl
Com erd ecoll
- Loading branch information
Showing
10 changed files
with
812 additions
and
17 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
Back/database/Pipe/DB_Mother/090_Correction_protocol_Entomo.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
DELETE v | ||
FROM ObservationDynPropValue v | ||
JOIN ObservationDynProp dp ON dp.ID = v.FK_ObservationDynProp | ||
JOIN Observation o on o.ID = v.FK_Observation and o.FK_ProtocoleType = 231 | ||
WHERE dp.Name = 'Identificateur' | ||
|
||
|
||
UPDATE ObservationDynProp SET Name = 'Identified_on' | ||
WHERE Name = 'Identification_on' | ||
|
||
-- SELECT * | ||
-- FROM ProtocoleType_ObservationDynProp l | ||
-- JOIN ObservationDynProp dp ON dp.ID = l.FK_ObservationDynProp ---and dp.Name = 'validator' | ||
-- JOIN ProtocoleType pt on pt.ID = l.FK_ProtocoleType | ||
--WHERE FK_ProtocoleType = 231 | ||
|
||
/**** SET DynProp Conf ****/ | ||
INSERT INTO ObservationDynProp (Name,TypeProp) | ||
VALUES ('Identified_by','String') | ||
|
||
INSERT INTO ProtocoleType_ObservationDynProp (Required,FK_ObservationDynProp,FK_ProtocoleType) | ||
VALUES (0,(SELECT ID FROM ObservationDynProp WHERE Name = 'Identified_by'),231) | ||
|
||
|
||
UPDATE V SET FK_ObservationDynProp = (SELECT ID FROM ObservationDynProp WHERE Name = 'Identified_by') | ||
FROM ObservationDynPropValue v | ||
JOIN ObservationDynProp dp ON dp.ID = v.FK_ObservationDynProp and dp.Name = 'validator' | ||
JOIN Observation o on o.ID = v.FK_Observation and o.FK_ProtocoleType = 231 | ||
|
||
DELETE l | ||
FROM ProtocoleType_ObservationDynProp l | ||
JOIN ObservationDynProp dp ON dp.ID = l.FK_ObservationDynProp and dp.Name in ( 'validator','Identificateur') | ||
JOIN ProtocoleType pt on pt.ID = l.FK_ProtocoleType | ||
WHERE FK_ProtocoleType = 231 | ||
|
||
|
||
/******* SET Form Conf ******/ | ||
UPDATE ModuleForms SET Name = 'Identified_by', Label = 'Identified by' | ||
WHERE TypeObj = 231 and module_id = 1 and Name = 'validator' | ||
|
||
DELETE ModuleForms | ||
WHERE TypeObj = 231 and module_id = 1 and Name = 'Identificateur' | ||
|
||
INSERT INTO ModuleForms | ||
SELECT [module_id] | ||
,[TypeObj] | ||
,'Identified_on' | ||
,'Identified on' | ||
,[Required] | ||
,5 | ||
,5 | ||
,'Text' | ||
,[editorClass] | ||
,[FormRender] | ||
,10 | ||
,[Legend] | ||
,NULL | ||
,[Validators] | ||
,[displayClass] | ||
,[EditClass] | ||
,[Status] | ||
,[Locked] | ||
,[DefaultValue] | ||
,[Rules] | ||
FROM ModuleForms | ||
WHERE TypeObj = 231 and module_id = 1 and Name = 'Identified_by' | ||
|
||
GO | ||
|
||
|
||
|
||
INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('90_Correction_protocol_Entomo',GETDATE(),(SELECT db_name())) | ||
|
||
|
||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
|
||
SET ANSI_NULLS ON | ||
GO | ||
|
||
SET QUOTED_IDENTIFIER ON | ||
GO | ||
|
||
|
||
|
||
ALTER PROCEDURE [dbo].[MessageSendDataToDest] | ||
AS | ||
BEGIN | ||
DECLARE @DestDB VARCHAR(250) | ||
,@MessageToSendConf BIGINT | ||
,@SQLText NVARCHAR(4000) | ||
|
||
DECLARE c_destination CURSOR FOR | ||
SELECT DISTINCT C.DestDatabase FROM TMessageSend M JOIN TMessageToSendConf C ON M.ObjectType = C.ObjectType AND M.Operation = C.Operation | ||
WHERE NOT EXISTS (SELECT * FROM TMessageTransfertLog L WHERE L.fk_ConfDest = C.pk_MessageToSendConf and L.fk_MessageSend = pk_MessageSend) | ||
|
||
IF OBJECT_ID('tempdb..#MessageToSend') IS NOT NULL | ||
DROP TABLE #MessageToSend | ||
|
||
IF OBJECT_ID('tempdb..#MessageDetailToSend') IS NOT NULL | ||
DROP TABLE #MessageDetailToSend | ||
|
||
-- GET ALL MESSAGE FOR ALL DEST | ||
|
||
SELECT M.*,C.DestDatabase,C.pk_MessageToSendConf into #MessageToSend | ||
FROM TMessageSend M JOIN TMessageToSendConf C ON M.ObjectType = C.ObjectType AND M.Operation = C.Operation | ||
WHERE M.SendDate IS NULL AND NOT EXISTS (SELECT * FROM TMessageTransfertLog L WHERE L.fk_ConfDest = C.pk_MessageToSendConf and L.fk_MessageSend = pk_MessageSend) | ||
|
||
-- GET ALL ASSOCIATED DETAILS | ||
|
||
SELECT D.*,M.DestDatabase INTO #MessageDetailToSend | ||
FROM dbo.TMessageSendDetail D JOIN #MessageToSend M ON M.pk_MessageSend = D.fk_MessageSend | ||
|
||
|
||
print 'BEGIN TRAN' | ||
OPEN c_destination | ||
|
||
BEGIN TRY | ||
|
||
|
||
FETCH NEXT FROM c_destination | ||
INTO @DestDB | ||
|
||
|
||
|
||
WHILE @@FETCH_STATUS = 0 | ||
BEGIN | ||
|
||
|
||
SET @SQLText = ' DELETE D FROM ' + @DestDB + '.TMessageReceivedDetail D WHERE exists (select * from ' + @DestDB + '.TMessageReceived M where M.isMessageComplete = 0 and M.Provenance =''' + dbo.GetProvenance() + ''' and D.fk_MessageReceived = M.pk_MessageReceived and d.Provenance = m.Provenance)' | ||
print @SQLText | ||
|
||
EXEC(@SQLText) | ||
|
||
SET @SQLText = ' DELETE M FROM ' + @DestDB + '.TMessageReceived M WHERE M.isMessageComplete = 0 and Provenance =''' + dbo.GetProvenance() + '''' | ||
print @SQLText | ||
|
||
EXEC(@SQLText) | ||
|
||
|
||
|
||
-- INSERTING DATE IN DEST TMessageReceived | ||
|
||
SET @SQLText = ' INSERT INTO ' + @DestDB + '.TMessageReceived (pk_MessageReceived,Provenance,ObjectType,ObjectId,ObjectOriginalID,Operation,CreationDate,ImportDate,Comment,isMessageComplete)' | ||
SET @SQLText = @SQLText + ' SELECT pk_MessageSend,''' + dbo.GetProvenance() + ''', M.ObjectType,M.ObjectId,M.ObjectOriginalID,M.Operation,GetDate(),NULL,NULL,0 ' | ||
SET @SQLText = @SQLText + ' FROM #MessageToSend M WHERE M.DestDatabase = ''' + @DestDB + '''' | ||
print @SQLText | ||
|
||
EXEC(@SQLText) | ||
|
||
-- INSERTING DATE IN DEST TMessageReceivedDetail | ||
|
||
SET @SQLText = ' INSERT INTO ' + @DestDB + '.TMessageReceivedDetail (pk_MessageReceivedDetail,fk_MessageReceived,Provenance,PropName,PropValue,Parametre)' | ||
SET @SQLText = @SQLText + ' SELECT D.pk_MessageSendDetail,D.fk_MessageSend,''' + dbo.GetProvenance() + ''', D.PropName,D.PropValue,D.Parametre ' | ||
SET @SQLText = @SQLText + ' FROM #MessageDetailToSend D WHERE D.DestDatabase = ''' + @DestDB + '''' | ||
|
||
print @SQLText | ||
EXEC(@SQLText) | ||
|
||
|
||
|
||
|
||
SET @SQLText = ' UPDATE R SET isMessageComplete=1 FROM ' + @DestDB + '.TMessageReceived R' | ||
SET @SQLText += ' JOIN #MessageToSend S ON R.pk_MessageReceived = S.pk_MessageSend AND R.Provenance = ''' + dbo.GetProvenance() + ''' AND S.DestDatabase = ''' + @DestDB + '''' | ||
|
||
print @SQLText | ||
EXEC(@SQLText) | ||
|
||
|
||
INSERT INTO [TMessageTransfertLog] | ||
([fk_MessageSend] | ||
,[fk_ConfDest] | ||
,[Statut] | ||
,[SendMessage]) | ||
SELECT pk_MessageSend,pk_MessageToSendConf,0,NULL | ||
FROM #MessageToSend M WHERE M.DestDatabase = @DestDB | ||
|
||
FETCH NEXT FROM c_destination | ||
INTO @DestDB | ||
|
||
END | ||
CLOSE c_destination; | ||
DEALLOCATE c_destination; | ||
|
||
UPDATE TMessageSend SET SendDate=GETDATE() | ||
WHERE pk_MessageSend in (select pk_MessageSend from #MessageToSend) | ||
|
||
|
||
|
||
print 'COMMIT TRAN' | ||
END TRY | ||
BEGIN CATCH | ||
print 'CATCH' | ||
CLOSE c_destination; | ||
DEALLOCATE c_destination; | ||
|
||
|
||
DECLARE @ErrorMessage NVARCHAR(4000); | ||
DECLARE @ErrorSeverity INT; | ||
DECLARE @ErrorState INT; | ||
|
||
SELECT | ||
@ErrorMessage = ERROR_MESSAGE(), | ||
@ErrorSeverity = ERROR_SEVERITY(), | ||
@ErrorState = ERROR_STATE(); | ||
|
||
|
||
DELETE FROM [TMessageTransfertLog] WHERE [fk_MessageSend] IN (select pk_MessageSend from #MessageToSend) | ||
|
||
RAISERROR (@ErrorMessage, -- Message text. | ||
@ErrorSeverity, -- Severity. | ||
@ErrorState -- State. | ||
); | ||
END CATCH | ||
|
||
END | ||
|
||
GO | ||
|
||
|
||
|
||
|
||
|
||
INSERT INTO [dbo].[TVersion] (TVer_FileName,TVer_Date,TVer_DbName) VALUES ('91_ERD_SP_SendData',GETDATE(),(SELECT db_name())) | ||
|
||
|
||
GO |
Oops, something went wrong.