-
Notifications
You must be signed in to change notification settings - Fork 1
/
LocalSQLConnection.py
52 lines (39 loc) · 991 Bytes
/
LocalSQLConnection.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
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by the db_file
:param db_file: database file
:return: Connection object or None
"""
conn = None
try:
conn = sqlite3.connect(db_file)
print(sqlite3.version)
except Error as e:
print(e)
return conn
def select_all_tasks(conn):
"""
Query all rows in the tasks table
:param conn: the Connection object
:return:
"""
cur = conn.cursor()
query1 = """
SELECT *
FROM FACILITIES
"""
cur.execute(query1)
rows = cur.fetchall()
for row in rows:
print(row)
def main():
database = "sqlite_db_pythonsqlite.db"
# create a database connection
conn = create_connection(database)
with conn:
print("2. Query all tasks")
select_all_tasks(conn)
if __name__ == '__main__':
main()