-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
44 lines (37 loc) · 1.23 KB
/
database.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
import sqlite3
con = sqlite3.connect('database.db')
cur = con.cursor()
cur.execute('''create table if not EXISTS waifus (
id INTEGER,
code Varchar(110) UNIQUE NOT NULL,
name varchar(50),
anime varchar(50),
PRIMARY KEY(id));
''')
def insert_row(code, name, anime):
exist = cur.execute("SELECT * FROM waifus WHERE code=?", (str(code),)).fetchone()
if exist:
if bool(exist[3]): # antes se usaba REPLACE INTO
cur.execute("""
UPDATE waifus
SET code=?,
name=?
WHERE
id=?""", (str(code), str(name), exist[0]))
else:
cur.execute("""
UPDATE waifus
SET code = ?,
name = ?,
anime = ?
WHERE
id = ?""", (str(code), str(name), str(anime), exist[0]))
else:
cur.execute("INSERT INTO waifus (code,name,anime) VALUES(?,?,?)", (str(code), str(name), str(anime)))
con.commit()
def get_name(code):
name = cur.execute("SELECT name FROM waifus WHERE code=?", (str(code),)).fetchone()
if name:
return name[0]
else:
return False