-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrigger_Check.sql
206 lines (148 loc) · 4.4 KB
/
Trigger_Check.sql
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
DELIMITER //
CREATE TRIGGER user_password_before_ınsert
BEFORE INSERT
ON user FOR EACH ROW
BEGIN
IF length(new.password)<6
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='SIFRE 6 KARAKTERDEN AZ OLAMAZ';
END IF;
END; //
DELIMITER ;
DELIMITER //
CREATE TRIGGER user_password_before_update
BEFORE UPDATE
ON user FOR EACH ROW
BEGIN
IF length(new.password)<6
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='SIFRE 6 KARAKTERDEN AZ OLAMAZ';
END IF;
END; //
DELIMITER ;
DELIMITER //
CREATE TRIGGER profile_date_control_before_ınsert
BEFORE INSERT
ON profile FOR EACH ROW
BEGIN
IF NEW.Date_of_Birth > NEW.Begin_Organization
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='Dogum tarihi, Ise giris tarihinden sonra olamaz !';
END IF;
END; //
DELIMITER ;
DELIMITER //
CREATE TRIGGER profile_date_control_before_update
BEFORE UPDATE
ON profile FOR EACH ROW
BEGIN
IF NEW.Date_of_Birth > NEW.Begin_Organization
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='Dogum tarihi, Ise giris tarihinden sonra olamaz !';
END IF;
END; //
DELIMITER ;
DELIMITER //
CREATE TRIGGER event_date_constraint_before_insert
BEFORE INSERT
ON Event FOR EACH ROW
BEGIN
IF NEW.Start_Date>NEW.Finish_Date
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='Etkinligin baslama tarihi bitis tarihinden sonra olamaz. !';
END IF;
END; //
DELIMITER ;
#----ÖNEMLİ-------Programda zaten kullanıcı kendine baglantı isteginde bulunamaz...!!!
DELIMITER //
CREATE TRIGGER connection_control_before_ınsert
BEFORE INSERT
ON connection FOR EACH ROW
BEGIN
IF NEW.From_ID = NEW.To_ID
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='Kisi Kendini Ekleyemez !';
END IF;
END; //
DELIMITER ;
DELIMITER //
CREATE TRIGGER connection_control_before_update
BEFORE UPDATE
ON connection FOR EACH ROW
BEGIN
IF NEW.From_ID = NEW.To_ID
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='Kisi Kendini Ekleyemez !';
END IF;
END; //
DELIMITER ;
DELIMITER //
CREATE TRIGGER CV_section_id_before_insert
BEFORE INSERT
ON cv_section FOR EACH ROW
BEGIN
IF NEW.CV_Section_ID>10 OR NEW.CV_Section_ID<1
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='Section Numarasi 1 ile 9 arasında olmalıdır.!';
END IF;
END; //
DELIMITER ;
#----ÖNEMLİ------Programda zaten arkadaşı olmayan kişi listede olmayacağından chat yapılamaz.
# Örnek olarak yazıldı.
DELIMITER //
CREATE TRIGGER group_chat_constraint_before_insert
BEFORE INSERT
ON group_chat FOR EACH ROW
BEGIN
IF NOT EXISTS(SELECT * FROM CONNECTION_RELATION WHERE NEW.Sender_ID=User AND NEW.Receiver_ID=Connection)
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='ARKADAS OLMAYAN KISILER CHAT YAPAMAZ';
END IF ;
END; //
DELIMITER ;
DELIMITER //
CREATE TRIGGER ref_cv_section_connection_control_before_insert
BEFORE INSERT
ON Ref_CV_Section FOR EACH ROW
BEGIN
IF NOT EXISTS(SELECT *
FROM CONNECTION_RELATION
WHERE NEW.Ref_User_ID= Connection AND User IN (SELECT CV.User_ID
FROM CV
WHERE NEW.CV_ID=CV.CV_ID))
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='BAGLANTILI OLMAYAN KISILER BIRBIRLERINE REFERANS OLAMAZ!';
ELSE IF NOT EXISTS(SELECT *
FROM CV,CV_SECTION
WHERE CV.CV_ID=NEW.CV_ID AND CV.Privacy!=3 AND NEW.CV_ID=CV_SECTION.CV_ID AND CV_SECTION.CV_Section_ID=NEW.CV_Section_ID AND CV_SECTION.Privacy!=3)
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='Gorunurlugu kapali CVye REFERANS olunamaz!';
END IF;
END IF ;
END ; //
DELIMITER ;
DELIMITER //
CREATE TRIGGER recommendation_control_before_insert
BEFORE INSERT
ON recommendation FOR EACH ROW
BEGIN
IF NOT EXISTS( SELECT *
FROM CONNECTION_RELATION
WHERE NEW.From_ID= Connection AND NEW.To_ID= User)
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT='BAGLANTILI OLUNMAYAN KISI ICIN TAVSIYE METNI YAZILAMAZ!';
END IF ;
END ; //
DELIMITER ;