Change how next ids are generated in extract.py, correct for names with

apostrophes in them
This commit is contained in:
bjschuma 2010-01-02 00:01:13 -05:00
parent cbdf7d9dba
commit 947aa73411
4 changed files with 35 additions and 30 deletions

View File

@ -52,16 +52,4 @@ def run(args=None):
l = len(args)
if args[0] == "library":
library(args[1:])
#name = "Default"
#root = ""
#if l >= 2:
# name = args[1]
#if l >= 3:
# space = ' '
# root = expandPath( space.join(args[2:]) )
#database.open()
#database.insert('library',(name,root) )
#database.close()
#if not root=="":
# manager.run("scan",[root])

View File

@ -59,6 +59,14 @@ def close():
pass
def findId(table,name):
result = database.select("id",table,"name=\'"+name.replace("\'","\'\'")+"\'").fetchone()
if result == None:
return database.count(table),False
return result[0],True
# Called when the plugin needs to perform some action
def run(file=None):
if file == None:
@ -73,24 +81,21 @@ def run(file=None):
except:
return
artists = settings.get("artists")
# Find artist information
artist = t.artist
artist = t.artist#.replace("\'","\'\'")
if artist == "":
artist = "Unknown Artist"
# If artist does not exist yet, insert into database
if (artist in artists.keys())==False:
arid = database.count("artist")
arid,inserted = findId("artist",artist)
if inserted == False:
database.insert("artist", (arid, artist) )
artists[artist] = arid
else:
arid = artists[artist]
album = t.album
album = t.album#.replace("\'","\'\'")
if album == "":
album = "Unknown Album"
alid = database.count("album")
database.insert("album", (alid, album) )
#alid = database.count("album")
alid,inserted = findId("album",album)
if inserted == False:
database.insert("album", (alid, album) )
#database.commit()

View File

@ -54,13 +54,14 @@ def run(args=None):
space = ' '
path = expandPath( space.join(args) )
settings.set("artists",dict())
database.open()
scan(path)
#count = str(database.count("files"))
count = str(database.count("artist"))
write("Library contains "+count+" files.")
write("Library contains "+count+" artists.")
count = str(database.count("album"))
write("Library contains "+count+" albums.")
database.close()

View File

@ -56,7 +56,7 @@ def create():
CREATE TABLE library
(
libid INTEGER PRIMARY KEY AUTOINCREMENT,
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
path TEXT UNIQUE
);
@ -85,6 +85,13 @@ def close():
conn = None
def commit():
global conn
if conn == None:
return
conn.commit()
def init():
global db
db = join(settings.get("ocarina"),"ocarina.db")
@ -119,6 +126,10 @@ def select(select,table,where=None):
statement = 'select '+select+' from '+table
if not (where==None):
statement += ' where '+where
print statement
result = execute(statement)
return result
#print statement
try:
result = execute(statement)
return result
except:
print statement
return None