Skip to content

Commit

Permalink
updating
Browse files Browse the repository at this point in the history
  • Loading branch information
fzerman committed Jun 18, 2020
1 parent 98552ed commit 7008c2f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
14 changes: 10 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
db.insert('zerman',['a','b'])
db.delete('zerman',db.where('isim','ahmet'))
db.update('zerman','isim','a',db.where('yazar','v'))
"""
a = 'a'
db.delete('denemetable',db.where('isim',a))


info = db.selectAll('denemetable')
print(info)
info = db.selectAll('zerman')
info = db.select('zerman',"isim",db.sort('id',-1))
print(info)
info = db.select('zerman',"*")
info = db.filter(info,"avr","id","zerman")
print(info)
"""
info = db.select('zerman',"*")
info = db.filter(info,"avr","id","zerman")
print(info)
52 changes: 47 additions & 5 deletions db_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def __init__(self):
self.connect(DB)
self.i = 0
self.s = list()

def connect(self,DB):
self.baglanti = sqlite3.connect(DB)
self.cursor = self.baglanti.cursor()
Expand Down Expand Up @@ -43,8 +44,11 @@ def selectAll(self,name):
return False

def select(self,name,thing,func = []):
sorgu = "Select " + thing + " From " + name + " " + func[0]
if len(func) > 0:
sorgu = "Select " + thing + " From " + name + " " + func[0]
else:
sorgu = "Select " + thing + " From " + name
if len(func) > 1:
self.cursor.execute(sorgu,(func[1],))
results = self.cursor.fetchall()
else:
Expand Down Expand Up @@ -75,8 +79,7 @@ def delete(self,name,func = []):
result = self.select(name,'*',func)
if result:
sorgu = "Delete From " + name + " " +func[0]
print(sorgu)
if len(func) > 0:
if len(func) > 1:
self.cursor.execute(sorgu,(func[1],))
else:
self.cursor.execute(sorgu)
Expand All @@ -87,10 +90,49 @@ def delete(self,name,func = []):

def update(self,name,thing,value,func=[]):
sorgu = "Update " + name + " set " + thing + " = ? " + func[0]
print(sorgu)
if len(func) > 0:
if len(func) > 1:
self.cursor.execute(sorgu,(value,func[1]))
else:
self.cursor.execute(sorgu)
self.baglanti.commit()
print("başarıyla güncellendi.")

def sort(self,column,state = 1):
if(type(state) == int):
if(state == 1 ):
sorgu = "ORDER BY " + column + " ASC"
elif(state == -1):
sorgu = "ORDER BY " + column + " DESC"
return [sorgu]
else:
print("ERROR")

def getDBinfo(self,name):
info = []
sorgu = "PRAGMA table_info("+name+")"
self.cursor.execute(sorgu)
results = self.cursor.fetchall()
if results:
for result in results:
info.append(result[1])
return info

def filter(self,data,_filter,state,table):
if data:
if _filter == "avr":
list_column = self.getDBinfo(table)
index = -1
averange = 0
for column in list_column:
index += 1
if state == column:
for i in data:
averange += int(i[index])
return averange / len(data)

#elif _filter == "grt":

else:
print("Filter Error: '" + _filter + "' not supported.")
else:
print("Data Error: Data cannot be founded.")
Binary file modified kütüphane.db
Binary file not shown.

0 comments on commit 7008c2f

Please sign in to comment.