Skip to content

Commit 4e43937

Browse files
authored
Update README.md
1 parent 3dc2cb8 commit 4e43937

File tree

1 file changed

+173
-3
lines changed

1 file changed

+173
-3
lines changed

README.md

Lines changed: 173 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,59 +269,229 @@ COMMIT;
269269
<br>
270270
<br>
271271

272-
# THIS MARK THE CONCLUSION OF OUR PROJECT
272+
# **Phase 7: Advanced Database Programming and Auditing**
273+
274+
This phase focuses on implementing advanced PL/SQL techniques to enhance the **Course Management System (CMS)**. These features aim to ensure system efficiency, maintain data integrity, and establish robust auditing for improved functionality and security.
275+
276+
277+
## **Problem Statement**
278+
279+
The CMS requires advanced programming techniques to address the following challenges:
280+
1. Enforcing business rules and automating workflows using **triggers**.
281+
2. Efficient row-by-row data processing with **cursors**.
282+
3. Improving modularity and reusability with **packages**.
283+
4. Monitoring and restricting access to sensitive data using **auditing mechanisms**.
284+
285+
286+
### **a) BEFORE Trigger**
287+
This trigger enforces validation for attendance status before data is inserted into the `ATTENDANCE` table.
288+
289+
CREATE OR REPLACE TRIGGER before_attendance_insert
290+
BEFORE INSERT ON ATTENDANCE
291+
FOR EACH ROW
292+
BEGIN
293+
IF :NEW.Status NOT IN ('Present', 'Absent') THEN
294+
RAISE_APPLICATION_ERROR(-20001, 'Invalid status. Must be Present or Absent.');
295+
END IF;
296+
END;
297+
/
298+
299+
### **b) Compound Trigger**
300+
This trigger ensures assignment submission deadlines are respected. It also validates that the assignment ID exists.
301+
302+
CREATE OR REPLACE TRIGGER submission_deadline
303+
BEFORE INSERT OR UPDATE ON SUBMISSION
304+
FOR EACH ROW
305+
DECLARE
306+
due_date ASSIGNMENT.Due_Date%TYPE;
307+
BEGIN
308+
SELECT Due_Date
309+
INTO due_date
310+
FROM ASSIGNMENT
311+
WHERE Assignment_ID = :NEW.Assignment_ID;
312+
313+
IF :NEW.Submission_Date > due_date THEN
314+
RAISE_APPLICATION_ERROR(-20002, 'Submission past the due date.');
315+
END IF;
316+
EXCEPTION
317+
WHEN NO_DATA_FOUND THEN
318+
RAISE_APPLICATION_ERROR(-20003, 'Assignment ID not found.');
319+
END;
320+
/
321+
322+
## **2. Cursor Usage**
323+
324+
This implementation calculates the average grade for each student using explicit cursors.
325+
326+
DECLARE
327+
CURSOR student_grades IS
328+
SELECT g.Student_ID, s.Name, AVG(g.Grade_Value) AS Avg_Grade
329+
FROM GRADE g
330+
JOIN STUDENT s ON g.Student_ID = s.Student_ID
331+
GROUP BY g.Student_ID, s.Name;
332+
333+
v_student_id STUDENT.Student_ID%TYPE;
334+
v_student_name STUDENT.Name%TYPE;
335+
v_avg_grade NUMBER;
336+
BEGIN
337+
OPEN student_grades;
338+
LOOP
339+
FETCH student_grades INTO v_student_id, v_student_name, v_avg_grade;
340+
EXIT WHEN student_grades%NOTFOUND;
341+
DBMS_OUTPUT.PUT_LINE('Student ID: ' || v_student_id || ' | Name: ' || v_student_name || ' | Average Grade: ' || v_avg_grade);
342+
END LOOP;
343+
CLOSE student_grades;
344+
END;
345+
/
346+
## **3. Attributes (%TYPE and %ROWTYPE)**
347+
348+
This step demonstrates the use of `%TYPE` and `%ROWTYPE` to improve efficiency and reusability in PL/SQL code.
349+
350+
DECLARE
351+
v_student_rec STUDENT%ROWTYPE;
352+
BEGIN
353+
SELECT * INTO v_student_rec FROM STUDENT WHERE Student_ID = 1;
354+
DBMS_OUTPUT.PUT_LINE('Student Name: ' || v_student_rec.Name);
355+
END;
356+
/
357+
358+
359+
## **4. Package Development**
360+
361+
### **a) Package Specification**
362+
363+
The package specification defines reusable procedures for logging audits and updating course capacities.
364+
365+
CREATE OR REPLACE PACKAGE cms_package AS
366+
PROCEDURE log_audit(p_table_name VARCHAR2, p_action_type VARCHAR2);
367+
PROCEDURE update_course_capacity(p_course_id INT);
368+
END cms_package;
369+
/
370+
371+
### **b) Package Body**
372+
373+
The package body implements the procedures defined in the specification.
374+
375+
CREATE OR REPLACE PACKAGE BODY cms_package AS
376+
PROCEDURE log_audit(p_table_name VARCHAR2, p_action_type VARCHAR2) IS
377+
BEGIN
378+
INSERT INTO AUDIT_LOG (Table_Name, Action_Type, Changed_By, Change_Date)
379+
VALUES (p_table_name, p_action_type, USER, SYSDATE);
380+
END log_audit;
381+
382+
PROCEDURE update_course_capacity(p_course_id INT) IS
383+
BEGIN
384+
UPDATE COURSE
385+
SET Seats_Available = Seats_Available - 1
386+
WHERE Course_ID = p_course_id;
387+
END update_course_capacity;
388+
END cms_package;
389+
/
390+
391+
## **5. Auditing and Restrictions**
392+
393+
### **a) Auditing Example**
394+
This trigger logs updates and deletions of sensitive student data into an audit log.
395+
396+
CREATE OR REPLACE TRIGGER audit_sensitive_data
397+
AFTER UPDATE OR DELETE ON STUDENT
398+
FOR EACH ROW
399+
DECLARE
400+
v_action_type VARCHAR2(10);
401+
BEGIN
402+
IF DELETING THEN
403+
v_action_type := 'DELETE';
404+
ELSIF UPDATING THEN
405+
v_action_type := 'UPDATE';
406+
END IF;
407+
408+
INSERT INTO AUDIT_LOG (Table_Name, Action_Type, Changed_By, Change_Date)
409+
VALUES ('STUDENT', v_action_type, USER, SYSDATE);
410+
END;
411+
/
412+
413+
### **b) Restriction Example**
414+
This procedure prevents unauthorized access to sensitive data based on the user's role.
415+
416+
BEGIN
417+
IF SYS_CONTEXT('USERENV', 'SESSION_USER') != 'ADMIN_ROLE' THEN
418+
RAISE_APPLICATION_ERROR(-20003, 'Unauthorized access.');
419+
END IF;
420+
END;
421+
/
422+
423+
### **Scope**
424+
- **Triggers**: Enforce data integrity and automate workflows.
425+
- **Cursors**: Enable efficient row-by-row data processing.
426+
- **Packages**: Group related procedures for better organization and reusability.
427+
- **Auditing**: Improve security and accountability by logging changes to sensitive data.
428+
273429

274-
# _**CREDITS**_ :
275430

276-
_credit of this project goes to every member of the group that worked relentlessly and hard for this to happen :_
277431

278432

433+
<br>
434+
<br>
435+
436+
# **THIS MARKS THE CONCLUSION OF OUR PROJECT**
437+
438+
# _**CREDITS**_ :
279439

440+
_credit of this project goes to every member of the group that worked relentlessly and hard for this to happen:_
280441

281442
1. **MUGISHA Julien**
282443
- Business Process Modeling
283444
- Lecturer Table Creation
284445
- Repository Creation
446+
- Advanced Database Programming
285447

286448
2. **IRADUKUNDA Delphine**
287449
- Business Process Modeling
288450
- Course Table Creation
289451
- Repository Creation
452+
- Advanced Database Programming
290453

291454
3. **SHEJA N M Yves**
292455
- Logical Modeling
293456
- Database Creation
294457
- Transaction Operation Creation
458+
- Advanced Database Programming
295459

296460
4. **ISHIMWE Mireille**
297461
- Business Process Modeling
298462
- Department Table Creation
299463
- View Creation
464+
- Advanced Database Programming
300465

301466
5. **INEZA HABAMENSHI Darryl**
302467
- Logical Modeling
303468
- Submission Table Creation
304469
- View Creation
470+
- Advanced Database Programming
305471

306472
6. **UWAYO Olga**
307473
- Business Process Modeling
308474
- Attendance Table Creation
309475
- View Creation
476+
- Advanced Database Programming
310477

311478
7. **KAMALI MUSASIRA Philbert**
312479
- Logical Modeling
313480
- Grade Table Creation
314481
- Transaction Operation Creation
482+
- Advanced Database Programming
315483

316484
8. **IRAKOZE Arlaine Peace**
317485
- Logical Modeling
318486
- Assignment Table Creation
319487
- Repository Creation
488+
- Advanced Database Programming
320489

321490
9. **ISHEMA NGABO Ange**
322491
- Business Process Modeling
323492
- Students Table Creation
324493
- View Creation
494+
- Advanced Database Programming
325495

326496

327497

0 commit comments

Comments
 (0)