Skip to content

Commit 85290a5

Browse files
committed
Adding ability to store 4 character course numbers (eg. PHYS-211A)
Works swell everywhere except in schedule creation
1 parent a464953 commit 85290a5

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
-- -------------------------------------------------------------------------
2+
-- Migration Script for f_4charcourses
3+
--
4+
-- @author Benjamin Russell ([email protected])
5+
-- @descrip Migration script to implement the changes for f_4charcourses.
6+
-- basically sets the course number field to a varchar(4) to enable
7+
-- courses that have letters in their number (eg. PHYS-211A)
8+
-- -------------------------------------------------------------------------
9+
10+
ALTER TABLE `courses`
11+
CHANGE `course` `course` VARCHAR(4) NOT NULL;
12+
13+
delimiter //
14+
DROP PROCEDURE IF EXISTS InsertOrUpdateCourse//
15+
CREATE PROCEDURE InsertOrUpdateCourse(
16+
IN p_quarter INT,
17+
IN p_department_num INT,
18+
IN p_department_code VARCHAR(4),
19+
IN p_course VARCHAR(4),
20+
IN p_credits INT,
21+
IN p_title VARCHAR(50),
22+
IN p_description TEXT
23+
)
24+
BEGIN
25+
-- Determine if the course already exists
26+
DECLARE recordFound INT(1);
27+
DECLARE v_department INT(10);
28+
29+
-- Select the department ID for the course
30+
IF p_quarter > 20130 THEN
31+
-- NOTE: This LIMIT 1 looks jank as fuck. Here's why it's important: There are some
32+
-- departments under semesters that condensed multiple departments from quarters
33+
-- (eg: CSCI is made from 4003 and 4005). That's ok. Problems arose because when deciding
34+
-- which department record would own a course under semesters, this query would return
35+
-- multiple records. Limiting it to one seems like a cop-out since (eg here) what if
36+
-- a CSCI course belongs to 4003?? The truth: It doesn't matter. By limiting it to one, we
37+
-- are storing all semester courses under the same department record (a "random" CSCI
38+
-- one not the 4003 CSCI or the 4005 CSCI). Ordering it will guarantee it's the same one each time.
39+
SET v_department = (SELECT d.id FROM departments AS d WHERE d.code = p_department_code ORDER BY d.number LIMIT 1);
40+
ELSE
41+
SET v_department = (SELECT d.id FROM departments AS d WHERE d.number = p_department_num);
42+
END IF;
43+
44+
-- Does the record exist?
45+
SET recordFound = (
46+
SELECT COUNT(*)
47+
FROM courses AS c
48+
WHERE c.department = v_department
49+
AND c.course = p_course
50+
AND c.quarter = p_quarter
51+
);
52+
IF recordFound > 0 THEN
53+
-- Course exists, so update it
54+
UPDATE courses AS c
55+
SET c.title = p_title, c.description = p_description, c.credits = p_credits
56+
WHERE c.department = v_department AND course = p_course AND quarter = p_quarter;
57+
SELECT "updated" AS action;
58+
ELSE
59+
-- Course doesn't exist, so insert it
60+
INSERT INTO courses (quarter, department, course, title, description, credits)
61+
VALUES(p_quarter, v_department, p_course, p_title, p_description, p_credits);
62+
SELECT "inserted" AS action;
63+
END IF;
64+
65+
-- Return the id of the course
66+
SELECT c.id FROM courses AS c WHERE c.department = v_department AND c.course = p_course AND c.quarter = p_quarter;
67+
END//

schema/procedures/InsertOrUpdateCourse.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CREATE PROCEDURE InsertOrUpdateCourse(
44
IN p_quarter INT,
55
IN p_department_num INT,
66
IN p_department_code VARCHAR(4),
7-
IN p_course INT,
7+
IN p_course VARCHAR(4),
88
IN p_credits INT,
99
IN p_title VARCHAR(50),
1010
IN p_description TEXT
@@ -52,4 +52,4 @@ BEGIN
5252

5353
-- Return the id of the course
5454
SELECT c.id FROM courses AS c WHERE c.department = v_department AND c.course = p_course AND c.quarter = p_quarter;
55-
END//
55+
END

tools/processDump.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function halt($messages) {
9393
function insertOrUpdateCourse($quarter, $departNum, $departCode, $course, $credits, $title, $description) {
9494
global $dbConn, $coursesUpdated, $coursesAdded;
9595
// Call the stored proc
96-
$query = "CALL InsertOrUpdateCourse({$quarter}, {$departNum}, '{$departCode}', {$course}, {$credits}, '{$title}', '{$description}')";
96+
$query = "CALL InsertOrUpdateCourse({$quarter}, {$departNum}, '{$departCode}', '{$course}', {$credits}, '{$title}', '{$description}')";
9797
$success = mysqli_multi_query($dbConn, $query);
9898

9999
// Catch errors or return the id
@@ -302,7 +302,7 @@ function fileToTempTable($tableName, $file, $fields, $fileSize, $procFunc=NULL)
302302
`session_code` int(1) UNSIGNED NOT NULL,
303303
`class_section` varchar(4) NOT NULL,
304304
`subject` int(4) UNSIGNED ZEROFILL NOT NULL,
305-
`catalog_nbr` int(3) UNSIGNED ZEROFILL NOT NULL,
305+
`catalog_nbr` VARCHAR(4) NOT NULL,
306306
`descr` text NOT NULL,
307307
`topic` text NOT NULL,
308308
`class_nbr` int(5) UNSIGNED NOT NULL,
@@ -331,7 +331,8 @@ function fileToTempTable($tableName, $file, $fields, $fileSize, $procFunc=NULL)
331331

332332
// Process the class file
333333
function procClassArray($lineSplit) {
334-
// Escape class title and description (respectively)
334+
// Escape class title, description, and course number (since it needs to be trimmed)
335+
$lineSplit[6] = mysql_real_escape_string(trim($lineSplit[6]));
335336
$lineSplit[7] = mysql_real_escape_string($lineSplit[7]);
336337
$lineSplit[8] = mysql_real_escape_string(trim($lineSplit[8]));
337338
$lineSplit[23] = mysql_real_escape_string($lineSplit[23]);

0 commit comments

Comments
 (0)