-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinvdb.py
54 lines (43 loc) · 2.4 KB
/
invdb.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
# 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('invdb')
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, slota, slotb, slotc, slotd, slote, slotf, slotg, sloth, head, body, hands, legs, feet, weapon, offhand, ear, neck, waist, ringl, ringr, back, bag)')
# Execute 'save' command
def save_name(db, name, slota, slotb, slotc, slotd, slote, slotf, slotg, sloth, head, body, hands, legs, feet, weapon, offhand, ear, neck, waist, ringl, ringr, back, bag):
cursor = db.cursor()
cursor.execute('INSERT INTO player(name, slota, slotb, slotc, slotd, slote, slotf, slotg, sloth, head, body, hands, legs, feet, weapon, offhand, ear, neck, waist, ringl, ringr, back, bag) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(name, slota, slotb, slotc, slotd, slote, slotf, slotg, sloth, head, body, hands, legs, feet, weapon, offhand, ear, neck, waist, ringl, ringr, back, bag))
db.commit()
return
# Not sure how to add the other features yet
def update_name(db, name, slota, slotb, slotc, slotd, slote, slotf, slotg, sloth, head, body, hands, legs, feet, weapon, offhand, ear, neck, waist, ringl, ringr, back, bag):
cursor = db.cursor()
cursor.execute("UPDATE player SET slota = ?, slotb = ?, slotc = ?, slotd = ?, slote = ?, slotf = ?, slotg = ?, sloth = ?, head = ?, body = ?, hands = ?, legs = ?, feet = ?, weapon = ?, offhand = ?, ear = ?, neck = ?, waist = ?, ringl = ?, ringr = ?, back = ?, bag = ? WHERE name = ?",(slota, slotb, slotc, slotd, slote, slotf, slotg, sloth, head, body, hands, legs, feet, weapon, offhand, ear, neck, waist, ringl, ringr, back, bag, 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 * FROM player').fetchall()
player = [row for row in rows if name in row[0]]
# delete_player(db, name)
return player