Qwael 3.9.8__tar.gz → 3.9.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {qwael-3.9.8 → qwael-3.9.9}/PKG-INFO +1 -1
- qwael-3.9.9/Qwael/Multidata.py +116 -0
- {qwael-3.9.8 → qwael-3.9.9}/Qwael/__init__.py +2 -1
- {qwael-3.9.8 → qwael-3.9.9}/Qwael.egg-info/PKG-INFO +1 -1
- {qwael-3.9.8 → qwael-3.9.9}/Qwael.egg-info/SOURCES.txt +1 -0
- {qwael-3.9.8 → qwael-3.9.9}/setup.py +1 -1
- {qwael-3.9.8 → qwael-3.9.9}/LICENSE +0 -0
- {qwael-3.9.8 → qwael-3.9.9}/Qwael/DR/304/260VE.py" +0 -0
- {qwael-3.9.8 → qwael-3.9.9}/Qwael/DoIP.py +0 -0
- {qwael-3.9.8 → qwael-3.9.9}/Qwael/MultiDB.py +0 -0
- {qwael-3.9.8 → qwael-3.9.9}/Qwael/filesz.py +0 -0
- {qwael-3.9.8 → qwael-3.9.9}/Qwael.egg-info/dependency_links.txt +0 -0
- {qwael-3.9.8 → qwael-3.9.9}/Qwael.egg-info/requires.txt +0 -0
- {qwael-3.9.8 → qwael-3.9.9}/Qwael.egg-info/top_level.txt +0 -0
- {qwael-3.9.8 → qwael-3.9.9}/README.md +0 -0
- {qwael-3.9.8 → qwael-3.9.9}/setup.cfg +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import mysql.connector
|
|
2
|
+
|
|
3
|
+
class Admin:
|
|
4
|
+
def __init__(self, IP, name, password, file_name, port=3306):
|
|
5
|
+
self.host = IP
|
|
6
|
+
self.user = name
|
|
7
|
+
self.password = password
|
|
8
|
+
self.database = file_name
|
|
9
|
+
self.port = port
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
self.conn = mysql.connector.connect(
|
|
13
|
+
host=self.host,
|
|
14
|
+
user=self.user,
|
|
15
|
+
password=self.password,
|
|
16
|
+
database=self.database,
|
|
17
|
+
port=self.port
|
|
18
|
+
)
|
|
19
|
+
self.cursor = self.conn.cursor(dictionary=True)
|
|
20
|
+
print("Database connected!")
|
|
21
|
+
except mysql.connector.Error as e:
|
|
22
|
+
print("Connection Error:", e)
|
|
23
|
+
|
|
24
|
+
# ------------------------------------------------------
|
|
25
|
+
# INSERT (db.add)
|
|
26
|
+
# ------------------------------------------------------
|
|
27
|
+
def add(self, table, **kwargs):
|
|
28
|
+
keys = ", ".join(kwargs.keys())
|
|
29
|
+
values = ", ".join(["%s"] * len(kwargs))
|
|
30
|
+
sql = f"INSERT INTO {table} ({keys}) VALUES ({values})"
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
self.cursor.execute(sql, tuple(kwargs.values()))
|
|
34
|
+
self.conn.commit()
|
|
35
|
+
print("Added!")
|
|
36
|
+
except mysql.connector.Error as e:
|
|
37
|
+
print("Insert Error:", e)
|
|
38
|
+
|
|
39
|
+
# ------------------------------------------------------
|
|
40
|
+
# UPDATE (db.update("users", {"ID": 3}, {"name": "Ali"}))
|
|
41
|
+
# ------------------------------------------------------
|
|
42
|
+
def update(self, table, where: dict, data: dict):
|
|
43
|
+
set_clause = ", ".join([f"{k}=%s" for k in data])
|
|
44
|
+
where_clause = " AND ".join([f"{k}=%s" for k in where])
|
|
45
|
+
|
|
46
|
+
values = list(data.values()) + list(where.values())
|
|
47
|
+
sql = f"UPDATE {table} SET {set_clause} WHERE {where_clause}"
|
|
48
|
+
|
|
49
|
+
try:
|
|
50
|
+
self.cursor.execute(sql, values)
|
|
51
|
+
self.conn.commit()
|
|
52
|
+
print("Updated!")
|
|
53
|
+
except mysql.connector.Error as e:
|
|
54
|
+
print("Update Error:", e)
|
|
55
|
+
|
|
56
|
+
# ------------------------------------------------------
|
|
57
|
+
# DELETE (db.delete("users", ID=3))
|
|
58
|
+
# ------------------------------------------------------
|
|
59
|
+
def delete(self, table, **kwargs):
|
|
60
|
+
where_clause = " AND ".join([f"{k}=%s" for k in kwargs])
|
|
61
|
+
sql = f"DELETE FROM {table} WHERE {where_clause}"
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
self.cursor.execute(sql, tuple(kwargs.values()))
|
|
65
|
+
self.conn.commit()
|
|
66
|
+
print("Deleted!")
|
|
67
|
+
except mysql.connector.Error as e:
|
|
68
|
+
print("Delete Error:", e)
|
|
69
|
+
|
|
70
|
+
# ------------------------------------------------------
|
|
71
|
+
# GET (tek veri) — db.get("users", ID=3, Variable=veri)
|
|
72
|
+
# ------------------------------------------------------
|
|
73
|
+
def get(self, table, **kwargs):
|
|
74
|
+
external_var = None
|
|
75
|
+
|
|
76
|
+
# Variable parametresini dışarı al
|
|
77
|
+
if "Variable" in kwargs:
|
|
78
|
+
external_var = kwargs["Variable"]
|
|
79
|
+
kwargs.pop("Variable") # filtrelerden çıkar
|
|
80
|
+
|
|
81
|
+
# WHERE oluştur
|
|
82
|
+
where_clause = " AND ".join([f"{k}=%s" for k in kwargs])
|
|
83
|
+
sql = f"SELECT * FROM {table} WHERE {where_clause} LIMIT 1"
|
|
84
|
+
|
|
85
|
+
try:
|
|
86
|
+
self.cursor.execute(sql, tuple(kwargs.values()))
|
|
87
|
+
row = self.cursor.fetchone()
|
|
88
|
+
|
|
89
|
+
if row:
|
|
90
|
+
# Variable={} gönderilmişse doldur
|
|
91
|
+
if external_var is not None:
|
|
92
|
+
external_var.clear()
|
|
93
|
+
external_var.update(row)
|
|
94
|
+
|
|
95
|
+
print("Data found:", row)
|
|
96
|
+
return row
|
|
97
|
+
|
|
98
|
+
print("No data found.")
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
except mysql.connector.Error as e:
|
|
102
|
+
print("Get Error:", e)
|
|
103
|
+
|
|
104
|
+
# ------------------------------------------------------
|
|
105
|
+
# GET ALL (db.get_all("users"))
|
|
106
|
+
# ------------------------------------------------------
|
|
107
|
+
def get_all(self, table):
|
|
108
|
+
sql = f"SELECT * FROM {table}"
|
|
109
|
+
|
|
110
|
+
try:
|
|
111
|
+
self.cursor.execute(sql)
|
|
112
|
+
rows = self.cursor.fetchall()
|
|
113
|
+
return rows
|
|
114
|
+
except mysql.connector.Error as e:
|
|
115
|
+
print("Get All Error:", e)
|
|
116
|
+
return []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|