-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB.py
More file actions
26 lines (21 loc) · 860 Bytes
/
DB.py
File metadata and controls
26 lines (21 loc) · 860 Bytes
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
import sqlite3
import os
class DB:
def __init__(self):
self.createDB()
self.connection = sqlite3.connect("pythonDices.db")
self.cursor = self.connection.cursor()
def createDB(self):
if not os.path.exists("pythonDices.db"):
print("Datenbank pythonDices.db nicht vorhanden - Datenbank wird anglegt...")
self.connection = sqlite3.connect("pythonDices.db")
self.cursor = self.connection.cursor()
sql = "CREATE TABLE tosses(dice1,dice2)"
self.cursor.execute(sql)
print("Datenbank pythonDices.db angelegt.")
def insertToss(self, dice1, dice2):
sql = "INSERT INTO tosses VALUES(" + str(dice1) + "," + str(dice2) + ")"
self.cursor.execute(sql)
def __del__(self):
self.connection.commit()
self.connection.close()