Skip to content

Instantly share code, notes, and snippets.

@fragmuffin
Created May 22, 2020 03:11
Show Gist options
  • Save fragmuffin/e9bdf4d7e102ed7d45b730316b54856a to your computer and use it in GitHub Desktop.
Save fragmuffin/e9bdf4d7e102ed7d45b730316b54856a to your computer and use it in GitHub Desktop.
This one's for Rob
#!/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)
@fragmuffin
Copy link
Author

fragmuffin commented May 22, 2020

@carryonrewardless
Using Chinook_Sqlite.sqlite as input, this outputs:

('Kiss',)

@carryonrewardless
Copy link

Works! Three extra lines. Some research for me to do on what those changes do in the script. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment