main
Michael Kowalczyk 12 months ago
parent a01ed53b6d
commit 15db656fc3

@ -11,7 +11,7 @@ Some SQLite specific commands
.open CampusVisit.db .open CampusVisit.db
.tables .tables
PRAGMA table_info(TableName); 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( CREATE TABLE Users(
UserID INTEGER PRIMARY KEY, UserID INTEGER PRIMARY KEY,
@ -62,7 +62,9 @@ Login screen:
SELECT COUNT() FROM Users WHERE Email='mkowalcz@nmu.edu' AND PasswordHash='secret'; SELECT COUNT() FROM Users WHERE Email='mkowalcz@nmu.edu' AND PasswordHash='secret';
Visits tab: Visits tab:
Create new visit 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 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; SELECT Visits.VisitID,Visits.StudentInfo,Users.name FROM Visits LEFT JOIN Users ON Visits.UserID=Users.UserID;
Delete a visit Delete a visit
@ -72,16 +74,21 @@ Visit detail window:
Get committment levels for all faculty for a given visit 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; 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 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 Set email frequency for a particular visit
UPDATE Visits SET NotificationFrequency=4 WHERE VisitID=2; UPDATE Visits SET NotificationFrequency=4 WHERE VisitID=2;
Set committment level for a given faculty member Set committment level for a given faculty member
INSERT INTO Visits_Users VALUES (1,1,'prefer not'); 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 Claim a visit and a time
UPDATE Visits SET DecidedTime=4, Status='assigned' WHERE VisitID=1 AND Status='proposed'; 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)=(1,1); 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 visit details
UPDATE Visits SET UserID=1 WHERE VisitID=3; UPDATE Visits SET UserID=1 WHERE VisitID=2;
User tab: User tab:
Get list of users, including faculty availability Get list of users, including faculty availability
SELECT * FROM Users; SELECT * FROM Users;
@ -91,7 +98,7 @@ User tab:
Update user attributes Update user attributes
UPDATE Users SET PasswordHash='secret',IsAdmin=TRUE WHERE Name='DrKow'; UPDATE Users SET PasswordHash='secret',IsAdmin=TRUE WHERE Name='DrKow';
Update faculty availability 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 user
DELETE FROM Users WHERE UserID=2; DELETE FROM Users WHERE UserID=2;
Update global settings Update global settings

@ -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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lab 1: Basic SQL Commands</title>
<link rel="stylesheet" href="../labGuide.css">
<style>
img {
border: 1px solid black;
}
</style>
</head>
<body>
<div id="page">
<h1>Lab 1: Basic SQL Commands</h1>
<p>In this lab you get experience using basic SQL commands, using SQLite.</p>
<h2>Setting up</h2>
<p>
Open a text document and <a href="https://sql.js.org/examples/GUI/">this SQL interpreter</a> (clear out the default SQL supplied).
Throughout this exercise, test your SQL commands in the interpreter, but <strong>keep a copy of all of your working commands</strong> in your text document.
</p>
<h2>Create tables</h2>
<p>
<img src="class diagram.png" width="350"><br>
Use the <code>CREATE TABLE</code> command to match the structure given in the diagram above. Here is the first one to get you started:
</p>
<pre><code>CREATE TABLE Customers(
CustomerID INTEGER PRIMARY KEY,
Name TEXT NOT NULL
);</code></pre>
<p>
Remember to name the primary key similarly to the table (e.g. <code>CustomerID</code> in the <code>Customers</code> table). The other two tables each have a foreign key (e.g. the <code>Orders</code> table will have a <code>CustomerID</code> column). Feel free to use the lecture notes as a guide. In SQLite, the <code>Date</code> can be stored as a <code>VARCHAR(10)</code> of the form <code>YYYY-MM-DD</code>. 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).
</p>
<h2>Insert</h2>
<p>
Next, we will populate the tables using the INSERT command. For the customers table, use either
<code>INSERT INTO Customers (Name) VALUES('DrKow');</code> or <code>INSERT INTO Customers VALUES(NULL, 'DrKow');</code> for the first customer. Fill in two more customers: 'Plato' and 'Socrates'. You can view your progress by using <code>SELECT * FROM Customers;</code> or another similar SELECT command.
</p>
<p>
Fill in the Orders and LineItems tables to reflect the following orders.
<ul>
<li>On 2024-10-01, Plato ordered an NMU laptop for $165 and two power supplies for $22.95 each.</li>
<li>On 2024-10-10, DrKow ordered an optical mouse for $12.99 and an HDMI to USB-C adapter for $10.99.</li>
<li>On 2024-10-16, DrKow ordered an power supply for $22.95.</li>
</ul>
</p>
<h2>Select</h2>
<p>
Now time for some <code>SELECT</code> commands. Write the following 5 queries:
<ul>
<li>Show all data pertaining to all line items for Plato's order (you can use OrderID in the <code>WHERE</code> clause).</li>
<li>Get the total for Plato's order by changing the <code>*</code> in your previous command to <code>SUM(Price)</code> instead. This is known as an <em>aggregate function</em>.</li>
<li>Show the dates for all of DrKow's orders.</li>
<li>Show the customer name and date for all orders (you will need a JOIN).</li>
<li>Show the customer name and date for all orders, but still show the customers that never ordered anything (you will need a LEFT JOIN).</li>
</ul>
</p>
<h2>Update</h2>
<p>
Using an UPDATE command, change the price of the USB-C adapter to $8.99 in the 2nd order.
</p>
<h2>Delete</h2>
<p>
Using a DELETE command, delete the 2nd power supply from the first order.
</p>
<hr>
<p>When you are done, show me your work to get credit for it.</p>
<hr>
</div>
</body>
</html>

@ -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%;
}
Loading…
Cancel
Save