File notes/fig/rel_mod/RECORD.tex added (mode: 100644) (index 0000000..7a61541) |
|
1 |
|
\documentclass[border=20pt]{standalone} |
|
2 |
|
\input{template.def} |
|
3 |
|
|
|
4 |
|
% RELEASED(Label (PK, FK to LABEL.Name), Recording (PK, FK to RECORDING.Title), Date) |
|
5 |
|
% EXCLUSITIVY(Recording (PK, FK to RECORDING.Title), Shop (FK to SHOP.Name)) |
|
6 |
|
% RECORDING(Name (PK)) |
|
7 |
|
% SHOP(Name (PK), StreetName, Citiy, Zip) |
|
8 |
|
% LABEL(Name (PK), Phone, LogoName, LogoColor) |
|
9 |
|
% SELL(Recording (FK, PK to RECORDING.Title), Shop (PK, FK to SHOP.Name), NumberOfCopies) |
|
10 |
|
% LABELGENRE(Label (PK, FK to LABEL.Name), Genre (PK)) |
|
11 |
|
|
|
12 |
|
\Frame(0,0){1}[RELEASE]{ |
|
13 |
|
Label/PK, |
|
14 |
|
Recording/PK, |
|
15 |
|
Date/A}; |
|
16 |
|
|
|
17 |
|
\Frame(0,-2.5){2}[EXCLUSITIVY]{ |
|
18 |
|
Recording/PK, |
|
19 |
|
Shop/A}; |
|
20 |
|
|
|
21 |
|
\Frame(6,0){3}[RECORDING]{ |
|
22 |
|
Title/PK}; |
|
23 |
|
|
|
24 |
|
\Frame(6,-2.5){4}[SHOP]{ |
|
25 |
|
Name/PK, |
|
26 |
|
StreetName/A, |
|
27 |
|
City/A, |
|
28 |
|
Zip/A}; |
|
29 |
|
|
|
30 |
|
\Frame(6,-5){5}[LABEL]{ |
|
31 |
|
Name/PK, |
|
32 |
|
Phone/A, |
|
33 |
|
LogoName/A, |
|
34 |
|
LogoColor/A}; |
|
35 |
|
|
|
36 |
|
\Frame(12,0){6}[SELL]{ |
|
37 |
|
Recording/PK, |
|
38 |
|
Shop/PK, |
|
39 |
|
NumberOfCopies/A}; |
|
40 |
|
|
|
41 |
|
|
|
42 |
|
\Frame(12,-5){7}[LABELGENRE]{ |
|
43 |
|
Label/PK, |
|
44 |
|
Genre/PK}; |
|
45 |
|
|
|
46 |
|
\draw[FK] % From Label1 to Name3⁵ |
|
47 |
|
(Name5)++(0.1,0) -- ++(0,-.55) -- ++(-7,0) |
|
48 |
|
-- ++(0,5) coordinate (inter) |
|
49 |
|
-- ++(0.87,0) coordinate (inter) |
|
50 |
|
-- (Label1); |
|
51 |
|
|
|
52 |
|
\draw[FK] % From Recording1 to Title3 |
|
53 |
|
(Title3)++(-0.3,0) -- ++(0,-.55) coordinate (inter) |
|
54 |
|
-- (Recording1|- inter) --++(0,0.55); |
|
55 |
|
|
|
56 |
|
\draw[FK] % From Recording2 to Title3 |
|
57 |
|
(Title3)++(0,0) -- ++(0,-.75) -- ++(-3,0) - ++(0,-2.3)coordinate (inter) |
|
58 |
|
-- (Recording2|- inter) --++(0,0.55); |
|
59 |
|
|
|
60 |
|
\draw[FK] % From Shop2 to Name4 |
|
61 |
|
(Name4)++(-0.1,0) -- ++(0,-.75) -- ++(-3,0) coordinate (inter) |
|
62 |
|
-- (Shop2|- inter) --++(0,0.85); |
|
63 |
|
|
|
64 |
|
\draw[FK] % From Recording6 to Title3 |
|
65 |
|
(Title3)++(0.3,0) -- ++(0,-.55) coordinate (inter) |
|
66 |
|
-- (Recording6|- inter) --++(0,0.55); |
|
67 |
|
|
|
68 |
|
\draw[FK] % From Shop6 to Name4 |
|
69 |
|
(Name4)++(0.3,0) -- ++(0,-.55) coordinate (inter) |
|
70 |
|
-- (Shop6|- inter) --++(0,3.05); |
|
71 |
|
|
|
72 |
|
\draw[FK] % From Label7 to Name53 |
|
73 |
|
(Name5)++(0.3,0) -- ++(0,-.55) coordinate (inter) |
|
74 |
|
-- (Label7|- inter) --++(0,0.55); |
|
75 |
|
|
|
76 |
|
|
|
77 |
|
% |
|
78 |
|
%\draw[FK] % From Quest5 to Name4 |
|
79 |
|
%(Name4)++(-0.1,0) -- ++(0,-.7) -- ++(2.6,0) coordinate (inter) |
|
80 |
|
%-- (Quest5 -| inter) -- ++(0,-0.4) coordinate (inter) |
|
81 |
|
%-- (Quest5 |- inter) --++(0,0.4); |
|
82 |
|
% |
|
83 |
|
%\draw[FK] % From Quest6 to Name4 |
|
84 |
|
%(Name4)++(0.1,0) -- ++(0,-.55) -- ++(2.6,0) coordinate (inter) |
|
85 |
|
%-- (Quest6 -| inter) -- ++(0,-0.2) coordinate (inter) |
|
86 |
|
%-- (Quest6 |- inter) --++(0,0.3); |
|
87 |
|
|
|
88 |
|
\end{tikzpicture} |
|
89 |
|
\end{document} |
File notes/lectures_notes.md changed (mode: 100644) (index 45aaa70..b89b2eb) |
... |
... |
We could also have used a combination of both! |
5657 |
5657 |
|
|
5658 |
5658 |
--- |
--- |
5659 |
5659 |
|
|
|
5660 |
|
Solution to [%D %n (%T)](#problem:ERtoRELRecord) |
|
5661 |
|
~ |
|
5662 |
|
"Is it true that …" |
|
5663 |
|
|
|
5664 |
|
<!-- bug with table --> |
|
5665 |
|
| Yes | No | |
|
5666 |
|
------------ | --- | --- | |
|
5667 |
|
a label can have multiple logos? | | ✔ | |
|
5668 |
|
a recording can be released by multiple labels, at different dates? | ✔ | | |
|
5669 |
|
a record shop can have multiple exclusivities? | ✔ | | |
|
5670 |
|
two record shops can have the same address? | ✔ | | |
|
5671 |
|
two logos can have the same name? | ✔ | | |
|
5672 |
|
two recordings can have the same title? | | ✔ | |
|
5673 |
|
a record shop must sell at least one recording? | ✔ | | |
|
5674 |
|
|
|
5675 |
|
For the $1:M$ relationship `IS_AN_EXCLUSIVITY_OF`, we can chose between the foreign key and the cross-reference approaches. |
|
5676 |
|
For the $1:1$ relationship `USES`, we can use any approach we want (foreign key, merged relation or cross-reference). |
|
5677 |
|
We chose to merge the two relations `LABEL` and `LOGO`, and to have a look-up table for the `IS_AN_EXCLUSIVITY_OF` relation, and we obtain: |
|
5678 |
|
|
|
5679 |
|
![ |
|
5680 |
|
RELEASED(Label (PK, FK to LABEL.Name), Recording (PK, FK to RECORDING.Title), Date) |
|
5681 |
|
EXCLUSITIVY(Recording (PK, FK to RECORDING.Title), Shop (FK to SHOP.Name)) |
|
5682 |
|
RECORDING(Name (PK)) |
|
5683 |
|
SHOP(Name (PK), StreetName, Citiy, Zip) |
|
5684 |
|
LABEL(Name (PK), Phone, LogoName, LogoColor) |
|
5685 |
|
SELL(Recording (FK, PK to RECORDING.Title), Shop (PK, FK to SHOP.Name), NumberOfCopies) |
|
5686 |
|
LABELGENRE(Label (PK, FK to LABEL.Name), Genre (PK)) |
|
5687 |
|
](fig/rel_mod/RECORD)\ |
|
5688 |
|
|
|
5689 |
|
--- |
|
5690 |
|
|
5660 |
5691 |
Solution to [%D %n (%T)](#problem:carsale) |
Solution to [%D %n (%T)](#problem:carsale) |
5661 |
5692 |
~ |
~ |
5662 |
5693 |
|
|
|
... |
... |
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/HW_DB |
6046 |
6077 |
|
|
6047 |
6078 |
### Creating a table |
### Creating a table |
6048 |
6079 |
|
|
6049 |
|
Use `stmt.execute` and a create statement. |
|
6050 |
|
You can use the `getMetaData()` of the `DatabaseMetaData` to obtain information about the tables. |
|
|
6080 |
|
We can create a table with the method `stmt.execute`. |
|
6081 |
|
We can use the `getMetaData()` of the `DatabaseMetaData` to obtain information about the tables. |
6051 |
6082 |
|
|
6052 |
6083 |
### Inserting values |
### Inserting values |
6053 |
6084 |
|
|
6054 |
|
Use `stmt.executeUpdate` (multiple insertion possible if `allowMultiQueries` was set to true). |
|
|
6085 |
|
Use `stmt.executeUpdate` (multiple insertion possible if `allowMultiQueries` was set to true, cf. <https://stackoverflow.com/a/10804730/>). |
6055 |
6086 |
Another way of batch processing statements: |
Another way of batch processing statements: |
6056 |
6087 |
|
|
6057 |
6088 |
~~~{.java} |
~~~{.java} |
|
... |
... |
Exercise +.# |
6083 |
6114 |
|
|
6084 |
6115 |
Exercise +.# |
Exercise +.# |
6085 |
6116 |
|
|
|
6117 |
|
: Name three classes in the sql API of java. |
|
6118 |
|
|
|
6119 |
|
Exercise +.# |
|
6120 |
|
|
6086 |
6121 |
: What JDBC method do you call to get a connection to a database? |
: What JDBC method do you call to get a connection to a database? |
6087 |
6122 |
|
|
6088 |
6123 |
Exercise +.# |
Exercise +.# |
|
... |
... |
Exercise +.# |
6114 |
6149 |
|
|
6115 |
6150 |
: In what class is the `getColumnName` method? |
: In what class is the `getColumnName` method? |
6116 |
6151 |
|
|
|
6152 |
|
|
|
6153 |
|
Exercise +.# |
|
6154 |
|
~ |
|
6155 |
|
|
|
6156 |
|
Assuming `stmt`{.java} is a `Statement`{.java} object, in the statement |
|
6157 |
|
|
|
6158 |
|
~~~{.java} |
|
6159 |
|
modif = stmt.executeUpdate(strC); |
|
6160 |
|
~~~ |
|
6161 |
|
what is |
|
6162 |
|
|
|
6163 |
|
#. the datatype of `modif`{.java}? |
|
6164 |
|
#. the datatype of `strC`{.java}? |
|
6165 |
|
#. a(n example of a) possible value for `strC`{.java}? |
|
6166 |
|
|
|
6167 |
|
|
6117 |
6168 |
Exercise +.# |
Exercise +.# |
6118 |
6169 |
|
|
6119 |
6170 |
: What is a prepared statement? |
: What is a prepared statement? |
6120 |
6171 |
|
|
|
6172 |
|
|
|
6173 |
|
Exercise +.# |
|
6174 |
|
|
|
6175 |
|
: Assuming `ps` is the prepared statement `INSERT INTO EXAM VALUES (?, ?)`{.sqlmysql}, write the three statements needed to allocate "Quiz" and "5" to the two slots, and then to execute the prepared statement on the database. |
|
6176 |
|
|
6121 |
6177 |
Exercise +.#ErrorsInCode |
Exercise +.#ErrorsInCode |
6122 |
6178 |
~ |
~ |
6123 |
6179 |
|
|
|
... |
... |
Solution +.# |
6140 |
6196 |
|
|
6141 |
6197 |
Solution +.# |
Solution +.# |
6142 |
6198 |
|
|
|
6199 |
|
: You can find them listed at <https://docs.oracle.com/javase/7/docs/api/java/sql/package-summary.html>. We used `Connection`, `DatabaseMetaData`, `ResultSetMetaData`, `PreparedStatement`, `Statement`, ... |
|
6200 |
|
|
|
6201 |
|
Solution +.# |
|
6202 |
|
|
6143 |
6203 |
: DriverManager.getConnection() |
: DriverManager.getConnection() |
6144 |
6204 |
|
|
6145 |
6205 |
Solution +.# |
Solution +.# |
|
... |
... |
Solution +.# |
6163 |
6223 |
|
|
6164 |
6224 |
: Connect to `localhost:3306` and create a new database if needed, and use secure connection. |
: Connect to `localhost:3306` and create a new database if needed, and use secure connection. |
6165 |
6225 |
|
|
|
6226 |
|
|
|
6227 |
|
Solution +.# |
|
6228 |
|
|
|
6229 |
|
: In `modif = stmt.executeUpdate(strC);`{.java}, `modif` is an integer (the number of rows modified by the query), `strC` is a `String` (a SQL command), and an example of value is `DELETE FROM BOOKS Where Price > 0.5`{.sqlmysql}. |
|
6230 |
|
|
6166 |
6231 |
Solution +.# |
Solution +.# |
6167 |
6232 |
|
|
6168 |
6233 |
: `ResultSetMetaData` |
: `ResultSetMetaData` |
|
... |
... |
Solution +.# |
6171 |
6236 |
|
|
6172 |
6237 |
: A prepared statement is a feature used to execute the same (or similar) SQL statements repeatedly with high efficiency. |
: A prepared statement is a feature used to execute the same (or similar) SQL statements repeatedly with high efficiency. |
6173 |
6238 |
|
|
|
6239 |
|
Solution +.# |
|
6240 |
|
~ |
|
6241 |
|
|
|
6242 |
|
~~~{.java} |
|
6243 |
|
ps.setString(1, "Quiz"); |
|
6244 |
|
ps.setInt(2, 5); |
|
6245 |
|
ps.execute(); |
|
6246 |
|
~~~ |
|
6247 |
|
|
6174 |
6248 |
Solution +.# |
Solution +.# |
6175 |
6249 |
~ |
~ |
6176 |
6250 |
|
|