-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite.py
57 lines (50 loc) · 2.3 KB
/
sqlite.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
import sqlite3
baglanti = sqlite3.connect("rent-a.db")
cursor = baglanti.cursor()
# Müşteri tablosu
cursor.execute('''
CREATE TABLE IF NOT EXISTS musteri (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ad_soyad TEXT
)
''')
# Araba tablosu
cursor.execute('''
CREATE TABLE IF NOT EXISTS arabalar (
id INTEGER PRIMARY KEY AUTOINCREMENT,
marka TEXT,
model TEXT,
yil INTEGER,
tip TEXT,
durumu TEXT DEFAULT 'müsait',
kilometre INTEGER DEFAULT 0
)
''')
# Kiralama tablosu
cursor.execute('''
CREATE TABLE IF NOT EXISTS kiralama (
musteri_id INTEGER,
araba_id INTEGER,
kiralama_tipi TEXT,
sure INTEGER,
ucret INTEGER,
durumu TEXT DEFAULT 'kiralandı',
FOREIGN KEY (araba_id) REFERENCES arabalar (id),
FOREIGN KEY (musteri_id) REFERENCES musteri(id)
)
''')
# Elektrikli Arabalar
cursor.execute("INSERT INTO arabalar (marka, model, yil, tip, kilometre) VALUES ('Tesla', 'Model S', 2023, 'Elektrikli', 500)")
cursor.execute("INSERT INTO arabalar (marka, model, yil, tip, kilometre) VALUES ('Porsche', 'Taycan', 2023, 'Elektrikli', 20000)")
cursor.execute("INSERT INTO arabalar (marka, model, yil, tip, kilometre) VALUES ('Audi', 'e-tron', 2023, 'Elektrikli', 3000)")
cursor.execute("INSERT INTO arabalar (marka, model, yil, tip, kilometre) VALUES ('Mercedes-Benz', 'EQC', 2023, 'Elektrikli', 0)")
cursor.execute("INSERT INTO arabalar (marka, model, yil, tip, kilometre) VALUES ('Jaguar', 'I-PACE', 2023, 'Elektrikli', 15000)")
# Benzinli Arabalar
cursor.execute("INSERT INTO arabalar (marka, model, yil, tip, kilometre) VALUES ('Mercedes-Benz', 'S-Class', 2023, 'Benzinli', 1500)")
cursor.execute("INSERT INTO arabalar (marka, model, yil, tip, kilometre) VALUES ('BMW', '7 Series', 2023, 'Benzinli', 32100)")
cursor.execute("INSERT INTO arabalar (marka, model, yil, tip, kilometre) VALUES ('Lexus', 'LS', 2023, 'Benzinli', 48000)")
cursor.execute("INSERT INTO arabalar (marka, model, yil, tip, kilometre) VALUES ('Audi', 'A8', 2023, 'Benzinli', 0)")
cursor.execute("INSERT INTO arabalar (marka, model, yil, tip, kilometre) VALUES ('Porsche', 'Panamera', 2023, 'Benzinli', 0)")
baglanti.commit()
# Veritabanı bağlantısını kapat
baglanti.close()