generated from spseol/flask-start-onefile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysqlite.py
32 lines (30 loc) · 852 Bytes
/
mysqlite.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
import sqlite3
class SQLite():
def __init__(self, file='db.sqlite3'):
self.file=file
def __enter__(self):
self.conn = sqlite3.connect(self.file)
self.conn.row_factory = sqlite3.Row
return self.conn.cursor()
def __exit__(self, type, value, traceback):
self.conn.commit()
self.conn.close()
if __name__ == "__main__":
with SQLite("data.db") as cur:
sql = """
CREATE TABLE "adresy" (
"zkratka" TEXT NOT NULL,
"adresa" TEXT NOT NULL,
"user" TEXT,
PRIMARY KEY("zkratka")
)
"""
cur.execute(sql)
sql = """
CREATE TABLE "user"(
"login" TEXT,
"passwd" TEXT,
PRIMARY KEY("login")
)
"""
cur.execute(sql)