-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_db.py
115 lines (104 loc) · 2.7 KB
/
create_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import sqlite3
connection = sqlite3.connect("app.db")
cursor = connection.cursor()
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS caracteristique (
id INTEGER PRIMARY KEY,
num_accident INTEGER NOT NULL UNIQUE,
jour INTEGER NOT NULL,
mois INTEGER NOT NULL,
an INTEGER NOT NULL,
hrmn DATETIME NOT NULL,
lum INTEGER NOT NULL,
dep INTEGER NOT NULL,
com INTEGER NOT NULL,
agg INTEGER NOT NULL,
inter INTEGER NOT NULL,
atm INTEGER NOT NULL,
lat DECIMAL NOT NULL,
long DECIMAL NOT NULL
)
"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS vehicule (
id INTEGER PRIMARY KEY,
num_accident INTEGER NOT NULL,
id_veh INTEGER NOT NULL,
catv INTEGER NOT NULL,
obs INTEGER NOT NULL,
obsm INTEGER NOT NULL,
choc DATETIME NOT NULL,
manv INTEGER NOT NULL,
motor INTEGER NOT NULL,
FOREIGN KEY (num_accident) REFERENCES caracteristique (num_accident)
)
"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS type_motor (
id INTEGER PRIMARY KEY,
motor INTEGER NOT NULL UNIQUE,
type TEXT NOT NULL,
FOREIGN KEY (motor) REFERENCES vehicule (motor)
)
"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS luminosite (
id INTEGER PRIMARY KEY,
lum INTEGER NOT NULL UNIQUE,
cond TEXT NOT NULL,
FOREIGN KEY (lum) REFERENCES caracteristique (lum)
)
"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS agglomeration (
id INTEGER PRIMARY KEY,
agg INTEGER NOT NULL UNIQUE,
cond TEXT NOT NULL,
FOREIGN KEY (agg) REFERENCES caracteristique (agg)
)
"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS atmospherique (
id INTEGER PRIMARY KEY,
atm INTEGER NOT NULL UNIQUE,
cond TEXT NOT NULL,
FOREIGN KEY (atm) REFERENCES caracteristique (atm)
)
"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS usager (
id INTEGER PRIMARY KEY,
num_accident INTEGER NOT NULL,
id_veh INTEGER NOT NULL,
grav INTEGER NOT NULL,
sexe INTEGER NOT NULL,
an_nais INTEGER NOT NULL,
trajet DATETIME NOT NULL,
FOREIGN KEY (num_accident) REFERENCES caracteristique (num_accident)
)
"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS gravite (
id INTEGER PRIMARY KEY,
grav INTEGER NOT NULL UNIQUE,
cond TEXT NOT NULL,
FOREIGN KEY (grav) REFERENCES usager (grav)
)
"""
)
connection.commit()