Skip to content

Instantly share code, notes, and snippets.

@hgfernan
Created May 15, 2017 01:33
Show Gist options
  • Save hgfernan/fbf3835eb163eb80f3850828495400e2 to your computer and use it in GitHub Desktop.
Save hgfernan/fbf3835eb163eb80f3850828495400e2 to your computer and use it in GitHub Desktop.
A tiny test of sqlite3 in Python
"""
A example from Cinique LeNoir at Quora's question
https://codepad.co/snippet/XGfrziiE
Using the database schema
CREATE TABLE user_cats (save_directory VARCHAR(20), uploader VARCHAR(20), playlists VARCHAR(20));
"""
import sqlite3
sqlite_file = "[database.sqlite]"
conn = sqlite3.connect (sqlite_file)
c = conn.cursor()
def save_dir (uploader, playlist):
sql = 'SELECT {sd} FROM {tn} WHERE uploader="{ul}" AND playlists LIKE "%{pl}%"'.\
format (sd='save_directory', tn='user_cats', ul=uploader, pl=playlist)
print (sql)
c.execute (sql)
all_rows = c.fetchall ()
print('1):', all_rows)
save_dir ('IGN', 'Daily Fix')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment