Created
May 22, 2020 03:11
-
-
Save fragmuffin/e9bdf4d7e102ed7d45b730316b54856a to your computer and use it in GitHub Desktop.
This one's for Rob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sqlite3 | |
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 | |
""" | |
database = 'Chinook_Sqlite.sqlite' # /config/home-assistant_v2.db | |
conn = None | |
try: | |
conn = sqlite3.connect(database) | |
except Exception as e: | |
print(e) | |
raise | |
return conn | |
def select_all_tasks(conn): | |
""" | |
Query all rows in the tasks table | |
:param conn: the Connection object | |
:return: | |
""" | |
cur = conn.cursor() | |
cur.execute("SELECT Name from Artist where ArtistId = 52;") | |
rows = cur.fetchall() | |
for row in rows: | |
print(row) | |
c = create_connection(None) | |
select_all_tasks(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works! Three extra lines. Some research for me to do on what those changes do in the script. :-)