-
Notifications
You must be signed in to change notification settings - Fork 23
/
database_process.py
37 lines (31 loc) · 1001 Bytes
/
database_process.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
# Arda Mavi
import os
import sqlite3
def set_sql_connect(database_name):
return sqlite3.connect(database_name)
def set_sql_cursor(database_connect):
return database_connect.cursor()
def close_connect(vt):
if vt:
vt.commit()
vt.close
def set_connect_and_cursor(path='Data/DataBase/database.sqlite'):
if not os.path.exists('Data/DataBase'):
os.makedirs('Data/DataBase')
vt = set_sql_connect(path)
db = set_sql_cursor(vt)
return vt, db
def create_table(table_name, columns):
vt, db = set_connect_and_cursor()
db.execute("CREATE TABLE IF NOT EXISTS {0} ({1})".format(table_name, columns))
close_connect(vt)
def get_data(sql_command):
vt, db = set_connect_and_cursor()
db.execute(sql_command)
gelen_veri = db.fetchall()
close_connect(vt)
return gelen_veri
def add_data(table, adding):
vt, db = set_connect_and_cursor()
db.execute("INSERT INTO '{0}' VALUES ({1})".format(table, adding))
close_connect(vt)