I'm trying to store a playlist in an sqlite table. To save on storage space I want to keep song artists and titles in a table and use both table's rowids to store the plays.
The structure of the database looks like this:
conn = sqlite3.connect('playlist.db')
c = conn.cursor()
sqlcommand= 'CREATE TABLE if not EXISTS artists(artist text PRIMARY KEY)'
c.execute(sqlcommand)
sqlcommand= 'CREATE TABLE if not EXISTS titles(title text PRIMARY KEY)'
c.execute(sqlcommand)
sqlcommand= 'CREATE TABLE if not EXISTS plays(PlayDate date, PlayTime datetime, ArtistID integer, TitleID integer )'
c.execute(sqlcommand)
Each song play event is stored like this
sqlcommand= 'INSERT or IGNORE INTO artists VALUES ("' + FoundArtist + '")'
c.execute(sqlcommand)
sqlcommand= 'INSERT or IGNORE INTO titles VALUES ("' + FoundTitle + '")'
c.execute(sqlcommand)
sqlcommand= 'SELECT ROWID from artists where artist = "'+FoundArtist+'"'
c.execute(sqlcommand)
ArtistID = str(c.fetchone()[0])
sqlcommand= 'SELECT ROWID from titles where title = "'+FoundTitle+'"'
c.execute(sqlcommand)
TitleID = str(c.fetchone()[0])
sqlcommand= 'INSERT or IGNORE INTO plays VALUES ("' + FoundPlayDate + '",' + \
'"'+ FoundPlayTime + '",' + \
ArtistID + ',' + \
TitleID + ')'
c.execute(sqlcommand)
This works, but is rather slow.
How can I combine the two select and the last insert command so that they run at the same time?
I'm running Python 2.7.6 on a raspberry pi (with Raspian/Debian wheezy)