diff --git a/Day 24-27 (database)/CampusVisits.db b/Day 24-27 (database)/CampusVisits.db index d7ddbb4..1b90b83 100644 Binary files a/Day 24-27 (database)/CampusVisits.db and b/Day 24-27 (database)/CampusVisits.db differ diff --git a/Day 24-27 (database)/Joining_Data_in_SQL_2.pdf b/Day 24-27 (database)/Joining_Data_in_SQL_2.pdf new file mode 100644 index 0000000..b01bac0 Binary files /dev/null and b/Day 24-27 (database)/Joining_Data_in_SQL_2.pdf differ diff --git a/Day 24-27 (database)/notes.txt b/Day 24-27 (database)/notes.txt index 93c553c..c4f1c8a 100644 --- a/Day 24-27 (database)/notes.txt +++ b/Day 24-27 (database)/notes.txt @@ -11,7 +11,7 @@ Some SQLite specific commands .open CampusVisit.db .tables PRAGMA table_info(TableName); - PRAGMA foreign_keys = ON; /* Need this one to define foreign key contraints. */ + PRAGMA foreign_keys = ON; /* Need this one to define and use foreign key contraints. */ CREATE TABLE Users( UserID INTEGER PRIMARY KEY, @@ -62,7 +62,9 @@ Login screen: SELECT COUNT() FROM Users WHERE Email='mkowalcz@nmu.edu' AND PasswordHash='secret'; Visits tab: Create new visit - INSERT INTO Visits (StudentInfo,Day) VALUES ('Joe Bloggs, Major: CS', '2025-04-15'); + INSERT INTO Visits (StudentInfo,Day,Availability) VALUES ('Sam Bloggs, Major: CS', '2025-04-15',-9223372036854775808); + INSERT INTO Visits (StudentInfo,Day,Availability) VALUES ('Joe Bloggs, Major: CS', '2025-04-16', 28); + INSERT INTO Visits (StudentInfo,Day,Availability) VALUES ('Mary Bloggs, Major: CS', '2025-04-17', 256); Get list of all visits, joined with faculty guides SELECT Visits.VisitID,Visits.StudentInfo,Users.name FROM Visits LEFT JOIN Users ON Visits.UserID=Users.UserID; Delete a visit @@ -72,16 +74,21 @@ Visit detail window: Get committment levels for all faculty for a given visit SELECT VisitID, Users.UserID, Name, Email FROM Visits_Users INNER JOIN Users ON Visits_Users.UserID=Users.UserID WHERE VisitID=2; Find intersection of visit availability with each faculty availability - SELECT Users.UserID, Name, Visits.Availability & Users.Availability FROM Visits INNER JOIN Users WHERE VisitID=1; /* Note that this is using the bitwise and operator "&" because of the way we are storing availability. */ + SELECT Visits.VisitID, Users.UserID, Name, Visits.Availability & Users.Availability FROM Visits INNER JOIN Users WHERE VisitID=1; /* Note that this is using the bitwise and operator "&" because of the way we are storing availability. */ Set email frequency for a particular visit UPDATE Visits SET NotificationFrequency=4 WHERE VisitID=2; Set committment level for a given faculty member INSERT INTO Visits_Users VALUES (1,1,'prefer not'); + INSERT INTO Visits_Users VALUES (1,2,'can do'); + INSERT INTO Visits_Users VALUES (2,1,'can do'); + INSERT INTO Visits_Users VALUES (2,2,'prefer not'); + INSERT INTO Visits_Users VALUES (3,1,'can do'); + INSERT INTO Visits_Users VALUES (3,2,'cannot'); Claim a visit and a time - UPDATE Visits SET DecidedTime=4, Status='assigned' WHERE VisitID=1 AND Status='proposed'; - INSERT INTO Visits_Users VALUES (1,1,'can do') ON CONFLICT (VisitID,UserID) DO UPDATE SET Willingness='can do' WHERE (VisitID,UserID)=(1,1); + UPDATE Visits SET DecidedTime=4, Status='assigned', UserId=1 WHERE VisitID=2 AND Status='proposed'; + INSERT INTO Visits_Users VALUES (1,1,'can do') ON CONFLICT (VisitID,UserID) DO UPDATE SET Willingness='can do' WHERE (VisitID,UserID)=(2,1); Update visit details - UPDATE Visits SET UserID=1 WHERE VisitID=3; + UPDATE Visits SET UserID=1 WHERE VisitID=2; User tab: Get list of users, including faculty availability SELECT * FROM Users; @@ -91,7 +98,7 @@ User tab: Update user attributes UPDATE Users SET PasswordHash='secret',IsAdmin=TRUE WHERE Name='DrKow'; Update faculty availability - UPDATE Users SET Availability=-9223372036854775801 WHERE Email='rappleto@nmu.edu'; + UPDATE Users SET Availability=-9223372036854775808 WHERE Email='rappleto@nmu.edu'; Delete user DELETE FROM Users WHERE UserID=2; Update global settings diff --git a/Day 24-27 (database)/sprint.txt b/Day 24-27 (database)/sprint.txt new file mode 100644 index 0000000..6560251 --- /dev/null +++ b/Day 24-27 (database)/sprint.txt @@ -0,0 +1,3 @@ + +Sprint planning: + Determine tasks to be completed this week, with quick difficulty estimates. Tasks should be relatively small, specific, completable pieces of work. Plan how it's going to get done. Use the kanban in Gitea to populate it. Spring ends with next Monday's class meeting. diff --git a/Labs/01/class diagram.png b/Labs/01/class diagram.png new file mode 100644 index 0000000..5f378cc Binary files /dev/null and b/Labs/01/class diagram.png differ diff --git a/Labs/01/index.html b/Labs/01/index.html new file mode 100644 index 0000000..1102acc --- /dev/null +++ b/Labs/01/index.html @@ -0,0 +1,85 @@ + + + + + + + + Lab 1: Basic SQL Commands + + + + + +
+

Lab 1: Basic SQL Commands

+

In this lab you get experience using basic SQL commands, using SQLite.

+ +

Setting up

+

+ Open a text document and this SQL interpreter (clear out the default SQL supplied). + Throughout this exercise, test your SQL commands in the interpreter, but keep a copy of all of your working commands in your text document. +

+ +

Create tables

+

+
+ Use the CREATE TABLE command to match the structure given in the diagram above. Here is the first one to get you started: +

+ +
CREATE TABLE Customers(
+	CustomerID INTEGER PRIMARY KEY,
+	Name TEXT NOT NULL
+);
+ +

+ Remember to name the primary key similarly to the table (e.g. CustomerID in the Customers table). The other two tables each have a foreign key (e.g. the Orders table will have a CustomerID column). Feel free to use the lecture notes as a guide. In SQLite, the Date can be stored as a VARCHAR(10) of the form YYYY-MM-DD. For price we will use the INTEGER type and store the number of cents, because floating points are prone to roundoff error hence should not be used for currency (other DBMS's support specific currency types). +

+

Insert

+

+ Next, we will populate the tables using the INSERT command. For the customers table, use either + INSERT INTO Customers (Name) VALUES('DrKow'); or INSERT INTO Customers VALUES(NULL, 'DrKow'); for the first customer. Fill in two more customers: 'Plato' and 'Socrates'. You can view your progress by using SELECT * FROM Customers; or another similar SELECT command. +

+

+ Fill in the Orders and LineItems tables to reflect the following orders. +

+

+

Select

+

+ Now time for some SELECT commands. Write the following 5 queries: +

+

+

Update

+

+ Using an UPDATE command, change the price of the USB-C adapter to $8.99 in the 2nd order. +

+

Delete

+

+ Using a DELETE command, delete the 2nd power supply from the first order. +

+ +
+ +

When you are done, show me your work to get credit for it.

+ +
+
+ + + + + \ No newline at end of file diff --git a/Labs/labGuide.css b/Labs/labGuide.css new file mode 100644 index 0000000..427979d --- /dev/null +++ b/Labs/labGuide.css @@ -0,0 +1,65 @@ +.tab { + padding-left: 15px; +} + +body { + background-color: #ffffb0; + margin: 0; + padding: 0; +} + +#page { + margin-left: 30px; + margin-right: 30px; + margin-top: 10px; + margin-bottom: 10px; + background-color: #fffff0; + padding: 7px; + border-style: double; + border-color: #000000; + border-width: 3px; +} + +.underline { + text-decoration: underline; +} + +img { + max-width: 100%; + height: auto; + border: 1px solid black; +} + +/* This is so code samples look reasonable */ +pre { + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; + overflow-x: auto; + border-width: 1px; + border-color: black; + border-style: solid; + background-color: white; + padding: 4px; +} + +blockquote { + border-width: 1px; + border-color: black; + border-style: solid; + background-color: white; + padding: 4px; +} + +.output { + border-width: 3px; + border-style: double; + border-color: white; + background-color: #000000; + color: #ffffff; + padding: 3px; +} + +img { + max-width: 100%; +} \ No newline at end of file