-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
42 lines (36 loc) · 1012 Bytes
/
database.py
File metadata and controls
42 lines (36 loc) · 1012 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sqlite3
import os
class Database:
def __init__(self):
self.conn = None
self.cursor = None
def connect(self):
if not os.path.exists('./db'):
os.makedirs('./db')
self.conn = sqlite3.connect("./db/db.sqlite")
self.cursor = self.conn.cursor()
self.create_table()
def create_table(self):
self.cursor.execute("DROP TABLE IF EXISTS csv_import")
self.cursor.execute("""
CREATE TABLE csv_import (
Id INTEGER PRIMARY KEY,
Name TEXT,
Surname TEXT,
Initials TEXT,
Age INTEGER,
DateOfBirth TEXT
)""")
self.conn.commit()
def insert(self, values):
self.cursor.execute("""INSERT INTO csv_import
(Id,
Name,
Surname,
Initials,
Age,
DateOfBirth)
VALUES {}""".format(','.join(values)))
self.conn.commit()
def close(self):
self.conn.close()