24 lines
715 B
Python
24 lines
715 B
Python
import sqlite3
|
|
|
|
class Database:
|
|
def __init__(self, database_file):
|
|
self.db = sqlite3.connect(database_file)
|
|
|
|
def select(self, index):
|
|
# Query the database for the specified index
|
|
cursor = self.db.cursor()
|
|
query = "SELECT name, address FROM people WHERE id = ?"
|
|
cursor.execute(query, (index,))
|
|
result = cursor.fetchone()
|
|
if result:
|
|
return result
|
|
else:
|
|
return None
|
|
|
|
def insert(self, name, address):
|
|
# Insert new entry into the database
|
|
cursor = self.db.cursor()
|
|
query = "INSERT INTO people (name, address) VALUES (?, ?)"
|
|
cursor.execute(query, (name, address))
|
|
self.db.commit()
|