-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdb.py
56 lines (44 loc) · 1.95 KB
/
db.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
47
48
49
50
51
52
53
54
55
56
# Database file for the nixheads-mud codebase
# Written by Dragonkeeper
# Edited by Lunacorn to fit into the list of
# variables needed to be saved.
# Dec 25th-26th, 2018
# Import the sqlite3 library
import sqlite3
# connect to the database
def connect():
db = sqlite3.connect('database')
init_db(db)
return db
# Initiate the database or create one
# if it does not exist.
def init_db(db):
cursor = db.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS player(name, room, password, email, user, race, job, coin, ujob, exp, ujoblevel, status)')
# Execute 'save' command
def save_name(db, name, room, password, email, user, race, job, coin, ujob, exp, ujoblevel, status):
cursor = db.cursor()
cursor.execute('INSERT INTO player(name, room, password, email, user, race, job, coin, ujob, exp, ujoblevel, status) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)',
(name, room, password, email, user, race, job, coin, ujob, exp, ujoblevel, status))
db.commit()
return
# Not sure how to add the other features yet
def update_name(db, name, room, password, email, user, race, job, coin, ujob, exp, ujoblevel, status):
cursor = db.cursor()
cursor.execute("UPDATE player SET room = ?, password = ?, email = ?, user = ?, race = ?, job = ?, coin = ?, ujob = ?, exp = ?, ujoblevel = ?, status = ? WHERE name = ?",(room, password, email, user, race, job, coin, ujob, exp, ujoblevel,status, name))
db.commit()
return
# A way to delete players from database
def delete_name(db, name):
cursor = db.cursor()
cursor.execute('DELETE from player WHERE name = ?', (name,))
db.commit()
return
#
def get_name(db, name):
'''Returns a list of rows representing "player"'''
cursor = db.cursor()
rows = cursor.execute('SELECT name, room, password, email, user, race, job, coin, ujob, exp, ujoblevel, status FROM player').fetchall()
player = [row for row in rows if name in row[0]]
# delete_player(db, name)
return player