Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mustafamuratcoskun
GitHub Repository: mustafamuratcoskun/Sifirdan-Ileri-Seviyeye-Python-Programlama
Path: blob/master/Sqlite Veritabanı/Kodlama Egzersizleri/kütüphane.py
765 views
1
import sqlite3
2
3
import time
4
5
class Kitap():
6
7
def __init__(self,isim,yazar,yayınevi,tür,baskı):
8
9
self.isim = isim
10
self.yazar = yazar
11
self.yayınevi = yayınevi
12
self.tür = tür
13
self.baskı = baskı
14
15
def __str__(self):
16
17
return "Kitap İsmi: {}\nYazar: {}\nYayınevi: {}\nTür: {}\nBaskı: {}\n".format(self.isim,self.yazar,self.yayınevi,self.tür,self.baskı)
18
19
20
class Kütüphane():
21
22
def __init__(self):
23
24
self.baglanti_olustur()
25
26
def baglanti_olustur(self):
27
28
self.baglanti = sqlite3.connect("kütüphane.db")
29
30
self.cursor = self.baglanti.cursor()
31
32
sorgu = "Create Table If not exists kitaplar (isim TEXT,yazar TEXT,yayınevi TEXT,tür TEXT,baskı INT)"
33
34
self.cursor.execute(sorgu)
35
36
self.baglanti.commit()
37
def baglantiyi_kes(self):
38
self.baglanti.close()
39
40
def kitapları_goster(self):
41
42
sorgu = "Select * From kitaplar"
43
44
self.cursor.execute(sorgu)
45
46
kitaplar = self.cursor.fetchall()
47
48
if (len(kitaplar) == 0):
49
print("Kütüphanede kitap bulunmuyor...")
50
else:
51
for i in kitaplar:
52
53
kitap = Kitap(i[0],i[1],i[2],i[3],i[4])
54
print(kitap)
55
56
def kitap_sorgula(self,isim):
57
58
sorgu = "Select * From kitaplar where isim = ?"
59
60
self.cursor.execute(sorgu,(isim,))
61
62
kitaplar = self.cursor.fetchall()
63
64
if (len(kitaplar) == 0):
65
print("Böyle bir kitap bulunmuyor.....")
66
else:
67
kitap = Kitap(kitaplar[0][0],kitaplar[0][1],kitaplar[0][2],kitaplar[0][3],kitaplar[0][4])
68
69
print(kitap)
70
def kitap_ekle(self,kitap):
71
72
sorgu = "Insert into kitaplar Values(?,?,?,?,?)"
73
74
self.cursor.execute(sorgu,(kitap.isim,kitap.yazar,kitap.yayınevi,kitap.tür,kitap.baskı))
75
76
self.baglanti.commit()
77
78
def kitap_sil(self,isim):
79
80
sorgu = "Delete From kitaplar where isim = ?"
81
82
self.cursor.execute(sorgu,(isim,))
83
84
self.baglanti.commit()
85
86
def baskı_yükselt(self,isim):
87
88
sorgu = "Select * From kitaplar where isim = ?"
89
90
self.cursor.execute(sorgu,(isim,))
91
92
93
kitaplar = self.cursor.fetchall()
94
95
if (len(kitaplar) == 0):
96
print("Böyle bir kitap bulunmuyor...")
97
else:
98
baskı = kitaplar[0][4]
99
100
baskı += 1
101
102
sorgu2 = "Update kitaplar set baskı = ? where isim = ?"
103
104
self.cursor.execute(sorgu2,(baskı,isim))
105
106
self.baglanti.commit()
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141