-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_manager.py
More file actions
32 lines (25 loc) · 1.23 KB
/
data_manager.py
File metadata and controls
32 lines (25 loc) · 1.23 KB
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
import sqlite3
import os
import game_info
import error_codes as ec
con = sqlite3.connect('playerinfo.db')
cur = con.cursor()
def get_player_info(player_name):
try:
cur.execute("SELECT * FROM playerinfo WHERE name=?", (player_name,)) # Add a comma to make it a tuple
info = cur.fetchall()
return info # Optionally return the fetched data
except sqlite3.Error as er:
print("SQLite error:", er.sqlite_errorcode)
print("No character Found")
return er.sqlite_errorcode
def insert_character_data(player_name, character_data):
try:
cur.execute("INSERT INTO playerinfo (name, class,attack,defense) VALUES (?,?,?,?)", (player_name, character_data["name"], character_data["stats"]["attack"], character_data["stats"]["defense"]))
data = cur.fetchone()
con.commit()
return ec.error_codes_create_character["0"]["message"]
except sqlite3.Error as er:
if er.sqlite_errorcode == 2067:
return ec.error_codes_create_character["1"]["message"]
print("SQLite error:", er.sqlite_errorcode)