-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataBaseControl.py
46 lines (37 loc) · 1.49 KB
/
DataBaseControl.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
# Author: Emsii
# Date: 01.03.2024
# https://github.com/EmsiiDiss
##InProgrogress!!!
import sqlite3
def connectBase(path, file):
connect = sqlite3.connect(str(path) + str(file))
return connect
def create_table(cursor, table_name, columns):
column_definitions = ', '.join([f"{col} VARCHAR(250) NOT NULL" for col in columns])
create_table_query = f"CREATE TABLE IF NOT EXISTS {table_name} (id INTEGER PRIMARY KEY ASC, {column_definitions})"
cursor.execute(create_table_query)
def collect(connect, tab, id, column):
cur = connect.cursor()
cur.execute('SELECT * FROM %s WHERE id=?;' % tab, (str(id)))
for row in cur.fetchall():
return row[column]
def table_maker(connect, columns, table_name):
cur = connect.cursor()
create_table(cur, table_name, columns)
close_Base(connect, "yes")
def update_Base(connect, table_name, data_list, place):
cursor = connect.cursor()
update_query = f"UPDATE {table_name} SET {place} = ? WHERE id = ?"
for data_tuple in data_list:
cursor.execute(update_query, data_tuple)
def insert_Base(connect, table_name, data_list, place):
cursor = connect.cursor()
num_columns = len(data_list[0])
placeholders = ', '.join(['?' for _ in range(num_columns)])
insert_query = f"INSERT INTO {table_name} VALUES ({place}{placeholders})"
for data_tuple in data_list:
cursor.execute(insert_query, data_tuple)
def close_Base(connect, save):
if save == "yes":
connect.commit()
connect.close()