MySql_Function.sql
8.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/**
* @filesource MySQL_Function.sql
*
* @category freeSN
* @copyright Copyright by mensch.coop e.G. 2009
* @mailto dev [at] mensch.coop
* @version 0.4.200901
* @link http://mensch.coop
*/
\. RightManagement/MySql_RMFunction.sql
DROP PROCEDURE IF EXISTS getMultimediaAuthorisationListID;
DELIMITER '$';
CREATE PROCEDURE getMultimediaAuthorisationListID(IN var_MTextID int, OUT var_ReadAuthorisation int, OUT var_WriteAuthorisation int)
BEGIN
select AuthReadListID, AuthWriteListID into var_ReadAuthorisation, var_WriteAuthorisation
from losp_BasisElement where ID=var_MTextID;
END;
$
DELIMITER ;
-- --------------------------------------------------------
select 'CREATE FUNCTION confirmWriteRightAspirantTo(...)';
DROP FUNCTION IF EXISTS confirmWriteRightAspirantTo;
DELIMITER '$';
CREATE FUNCTION confirmWriteRightAspirantTo(param_PartOfID int, param_AspirantProfileID int, param_RequestProfileID int, param_State varchar(128))
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE var_AuthWriteListID INT;
IF (select removeMTextFromClipboard(param_RequestProfileID, param_PartOfID, param_AspirantProfileID, 'AspirantWriteRight', param_State)) THEN
set var_AuthWriteListID=(select ListID from losp_BasisElement_writeauthorisation
where ListID=(select AuthWriteListID from losp_BasisElement
where ID=param_PartOfID) limit 1);
IF var_AuthWriteListID!=0 THEN
insert into losp_BasisElement_writeauthorisation (ListID, ProfileID) values(var_AuthWriteListID, param_AspirantProfileID);
return 1;
END IF;
return 0;
END IF;
return 0;
END;
$
DELIMITER ;
select 'MultimediaText_delete';
DROP FUNCTION IF EXISTS MultimediaText_delete;
DELIMITER '$';
CREATE FUNCTION MultimediaText_delete(param_MTextID int, param_RequestProfileID int)
RETURNS INT
DETERMINISTIC
BEGIN
call checkBEAuth(param_MTextID, param_RequestProfileID, @r, @tmp_w);
IF (@tmp_w) THEN
DELETE FROM losp_BasisElement WHERE ID=param_MTextID;
return 1;
END IF;
return NULL;
END;
$
DELIMITER ;
select 'Profile_delete';
DROP FUNCTION IF EXISTS Profile_delete;
DELIMITER '$';
CREATE FUNCTION Profile_delete(param_ProfileID int, param_RequestProfileID int)
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE var_MTextID INT DEFAULT 0;
DECLARE var_tmp_MTextID INT DEFAULT 0;
DECLARE var_tmp_Return INT DEFAULT 0;
DECLARE cur1 CURSOR FOR SELECT ID from losp_BasisElement where Author_ProfileID=param_ProfileID;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
select MTextID into var_MTextID from losp_BE_profile where MTextID=param_ProfileID;
call checkBEAuth(var_MTextID, param_RequestProfileID, @r, @tmp_w);
IF (@tmp_w) THEN
OPEN cur1;
REPEAT
FETCH cur1 INTO var_tmp_MTextID;
IF NOT done THEN
select MultimediaText_delete(var_tmp_MTextID, param_RequestProfileID) into var_tmp_Return;
IF (var_tmp_Return=NULL) THEN
return 0;
END IF;
END IF;
UNTIL done END REPEAT;
CLOSE cur1;
DELETE FROM losp_BE_profile WHERE MTextID=param_ProfileID;
return 1;
END IF;
return NULL;
END;
$
DELIMITER ;
select 'Account_delete';
DROP FUNCTION IF EXISTS Account_delete;
DELIMITER '$';
CREATE FUNCTION Account_delete(param_AccountID int, param_egal int)
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE var_ProfileID INT DEFAULT 0;
DECLARE var_tmp_Return INT DEFAULT 0;
select ProfileID into var_ProfileID from losp_be_account where ID=param_AccountID;
IF (var_ProfileID) THEN
select Profile_delete(var_ProfileID, var_ProfileID) into var_tmp_Return;
IF (var_tmp_Return=NULL) THEN
return 0;
END IF;
END IF;
DELETE FROM losp_be_account WHERE ID=param_AccountID;
return 1;
END;
$
DELIMITER ;
-- @new 100408 @f
select 'CREATE FUNCTION insertMTextIntoClipboard(...) RETURNS INT';
DROP FUNCTION IF EXISTS insertMTextIntoClipboard;
DELIMITER '$';
CREATE FUNCTION insertMTextIntoClipboard(param_RequestProfileID int, param_PartOfID int, param_AttachID int, param_PartOfObjVar varchar(128), param_PartOfObjVarCategory varchar(128), param_State varchar(128))
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE var_StateID INT;
DECLARE var_CategoryID INT;
DECLARE var_PartOfObjVarID INT;
DECLARE var_DOOBLE_AttachID INT;
set var_StateID=(select StateID from losp_BasisClipboard_state where State=param_State);
set var_PartOfObjVarID=(select PartOfObjVarID from losp_BasisClipboard_objvar where PartOfObjVar=param_PartOfObjVar);
set var_CategoryID=(select CategoryID from losp_BasisClipboard_category where CategoryName=param_PartOfObjVarCategory);
set var_DOOBLE_AttachID=(select AttachID from losp_BasisClipboard where PartOfID=param_PartOfID and PartOfObjVarID=var_PartOfObjVarID and CategoryID=var_CategoryID and AttachID=param_AttachID);
IF var_DOOBLE_AttachID THEN
RETURN -1;
ELSE
call checkBEAuth(param_AttachID, param_RequestProfileID,@tmp_r,@w);
IF (@tmp_r) THEN
INSERT INTO losp_BasisClipboard (PartOfID, AttachID, AttachStateID, PartOfObjVarID, LinkerProfileID, CategoryID)
VALUES (param_PartOfID, param_AttachID, var_StateID, var_PartOfObjVarID, param_RequestProfileID, var_CategoryID);
return 1;
END IF;
RETURN -2 ;
END IF;
RETURN -3 ;
END;
$
DELIMITER ;
-- @old 100408 @f
-- select 'CREATE FUNCTION insertMTextIntoClipboard(...) RETURNS INT';
-- DROP FUNCTION IF EXISTS insertMTextIntoClipboard;
-- DELIMITER '$';
-- CREATE FUNCTION insertMTextIntoClipboard(param_RequestProfileID int, param_PartOfID int, param_AttachID int, param_PartOfObjVar varchar(128), param_PartOfObjVarCategory varchar(128), param_State varchar(128))
-- RETURNS INT
-- DETERMINISTIC
-- BEGIN
-- DECLARE var_StateID INT;
-- DECLARE var_CategoryID INT;
-- DECLARE var_PartOfObjVarID INT;
-- DECLARE var_BCWriteRight CHAR(1);
-- DECLARE var_BOOL BOOLEAN DEFAULT 0;
--
-- set var_StateID=(select StateID from losp_BasisClipboard_state where State=param_State);
-- set var_PartOfObjVarID=(select PartOfObjVarID from losp_BasisClipboard_objvar where PartOfObjVar=param_PartOfObjVar);
-- set var_CategoryID=(select CategoryID from losp_BasisClipboard_category where CategoryName=param_PartOfObjVarCategory);
--
-- call checkBEAuth(param_AttachID, param_RequestProfileID,@tmp_r,@w);
-- set var_BCWriteRight=(select WriteAuthorisaton from losp_BEBasisClipboardsRightManagement where PartOfID=param_PartOfID and PartOfObjVarID=var_PartOfObjVarID and CategoryID=var_CategoryID);
--
-- IF ((var_BCWriteRight='a') OR (var_BCWriteRight='u' and param_RequestProfileID>0)) THEN
-- set var_BOOL=true;
-- ELSEIF (var_BCWriteRight='r') THEN
-- call checkBEAuth(param_PartOfID, param_RequestProfileID,@r,@tmp_w);
-- IF (@tmp_w) THEN
-- set var_BOOL=true;
-- END IF;
-- END IF;
--
-- IF (var_BOOL=true) THEN
-- INSERT INTO losp_BasisClipboard (PartOfID, AttachID, AttachStateID, PartOfObjVarID, LinkerProfileID, CategoryID)
-- VALUES (param_PartOfID, param_AttachID, var_StateID, var_PartOfObjVarID, param_RequestProfileID, var_CategoryID);
-- return 1;
-- END IF;
--
-- RETURN 0 ;
-- END;
-- $
-- DELIMITER ;
-- @new
select 'CREATE FUNCTION removeMTextFromClipboard(...)';
DROP FUNCTION IF EXISTS removeMTextFromClipboard;
DELIMITER '$';
CREATE FUNCTION removeMTextFromClipboard(param_RequestProfileID int, param_PartOfID int, param_AttachID int, param_PartOfObjVar varchar(128), param_CategoryName varchar(128))
RETURNS INT
DETERMINISTIC
BEGIN
-- DECLARE var_StateID INT;
DECLARE var_PartOfObjVarID INT;
DECLARE var_tmp_ID INT;
DECLARE var_CategoryID INT;
-- set var_StateID=(select StateID from losp_BasisClipboard_state where State=param_State);
set var_PartOfObjVarID=(select PartOfObjVarID from losp_BasisClipboard_objvar where PartOfObjVar=param_PartOfObjVar);
set var_CategoryID=(select CategoryID from losp_BasisClipboard_category where CategoryName=param_CategoryName);
call checkBEAuth(param_PartOfID,param_RequestProfileID,@r,@var_Profile_PartOf_w);
call checkBEAuth(param_AttachID,param_RequestProfileID,@r,@var_Profile_Attach_w);
IF (@var_Profile_PartOf_w || @var_Profile_Attach_w) THEN
set var_tmp_ID=(select PartOfID from losp_BasisClipboard WHERE PartOfID=param_PartOfID and AttachID=param_AttachID and PartOfObjVarID=var_PartOfObjVarID and CategoryID=var_CategoryID);
IF (var_tmp_ID>=0) THEN
DELETE FROM losp_BasisClipboard
WHERE PartOfID=param_PartOfID
and AttachID=param_AttachID
and CategoryID=var_CategoryID
and PartOfObjVarID=var_PartOfObjVarID;
return 1;
END IF;
END IF;
return 0;
END;
$
DELIMITER ;