X-Git-Url: https://git.rvb.name/openlib.git/blobdiff_plain/5361042232c8aa9f86c46f8533ef9637dcd2904d..6b3a07a008979ee27733a2deae2ff4fc42f4a535:/db.py?ds=inline diff --git a/db.py b/db.py index a39c160..d3a4912 100644 --- a/db.py +++ b/db.py @@ -6,7 +6,7 @@ import ConfigParser def SortName(name): if database: c = database.cursor() - c.execute('SELECT metadata.SortStr(%s)', (name)) + c.execute('SELECT metadata.SortStr(%s)', [name]) return c.fetchone()[0] else: print "No connection to DB" @@ -15,7 +15,7 @@ def SortName(name): def SortAuthorName(name): if database: c = database.cursor() - c.execute('SELECT metadata.SortAuthor(%s)', (name)) + c.execute('SELECT metadata.SortAuthor(%s)', [name]) return c.fetchone()[0] else: print "No connection to DB" @@ -24,7 +24,7 @@ def SortAuthorName(name): def GetOrCreateAuthor(name): if database: c = database.cursor() - c.execute('SELECT metadata.GetOrCreateAuthor(%s)', (name)) + c.execute('SELECT metadata.GetOrCreateAuthor(%s)', [name]) return c.fetchone()[0] else: print "No connection to DB" @@ -33,7 +33,7 @@ def GetOrCreateAuthor(name): def GetOrCreateLang(name): if database: c = database.cursor() - c.execute('SELECT metadata.GetOrCreateLang(%s)', (name)) + c.execute('SELECT metadata.GetOrCreateLang(%s)', [name]) return c.fetchone()[0] else: print "No connection to DB" @@ -42,7 +42,7 @@ def GetOrCreateLang(name): def GetOrCreatePublisher(name): if database: c = database.cursor() - c.execute('SELECT metadata.GetOrCreatePublisher(%s)', (name)) + c.execute('SELECT metadata.GetOrCreatePublisher(%s)', [name]) return c.fetchone()[0] else: print "No connection to DB" @@ -51,7 +51,7 @@ def GetOrCreatePublisher(name): def GetOrCreateSeries(name): if database: c = database.cursor() - c.execute('SELECT metadata.GetOrCreateSeries(%s)', (name)) + c.execute('SELECT metadata.GetOrCreateSeries(%s)', [name]) return c.fetchone()[0] else: print "No connection to DB" @@ -60,7 +60,7 @@ def GetOrCreateSeries(name): def GetOrCreateTag(name): if database: c = database.cursor() - c.execute('SELECT metadata.GetOrCreateTag(%s)', (name)) + c.execute('SELECT metadata.GetOrCreateTag(%s)', [name]) return c.fetchone()[0] else: print "No connection to DB" @@ -69,7 +69,7 @@ def GetOrCreateTag(name): def CreateBook(title,pubdate,series_index,isbn): if database: c = database.cursor() - c.execute('SELECT metadata.CreateBook(%s,%s,%s,%s)', (title,pubdate,series_index,isbn)) + c.execute('SELECT metadata.CreateBook(%s,%s,%s,%s)', [title,pubdate,series_index,isbn]) return c.fetchone()[0] else: print "No connection to DB" @@ -79,7 +79,7 @@ def LinkBookToAuthors(book_id,author_ids): if database: c = database.cursor() for author_id in author_ids: - c.execute('INSERT INTO metadata.books_authors_link(book,author) VALUES (%s,%s)', (book_id,author_id)) + c.execute('INSERT INTO metadata.books_authors_link(book,author) VALUES (%s,%s)', [book_id,author_id]) else: print "No connection to DB" exit() @@ -90,7 +90,7 @@ def LinkBookToLangs(book_id,lang_ids): io = 0 for lang_id in lang_ids: io = io + 1 - c.execute('INSERT INTO metadata.books_languages_link(book,lang_code,item_order) VALUES (%s,%s,%s)', (book_id,lang_id,io)) + c.execute('INSERT INTO metadata.books_languages_link(book,lang_code,item_order) VALUES (%s,%s,%s)', [book_id,lang_id,io]) else: print "No connection to DB" exit() @@ -98,7 +98,7 @@ def LinkBookToLangs(book_id,lang_ids): def LinkBookToPublishers(book_id,pub_id): if database: c = database.cursor() - c.execute('INSERT INTO metadata.books_publishers_link(book,publisher) VALUES (%s,%s)', (book_id,pub_id)) + c.execute('INSERT INTO metadata.books_publishers_link(book,publisher) VALUES (%s,%s)', [book_id,pub_id]) else: print "No connection to DB" exit() @@ -106,7 +106,7 @@ def LinkBookToPublishers(book_id,pub_id): def LinkBookToSeries(book_id,ser_id): if database: c = database.cursor() - c.execute('INSERT INTO metadata.books_series_link(book,series) VALUES (%s,%s)', (book_id,ser_id)) + c.execute('INSERT INTO metadata.books_series_link(book,series) VALUES (%s,%s)', [book_id,ser_id]) else: print "No connection to DB" exit() @@ -115,7 +115,7 @@ def LinkBookToTags(book_id,tag_ids): if database: c = database.cursor() for tag_id in tag_ids: - c.execute('INSERT INTO metadata.books_tags_link(book,tag) VALUES (%s,%s)', (book_id,tag_id)) + c.execute('INSERT INTO metadata.books_tags_link(book,tag) VALUES (%s,%s)', [book_id,tag_id]) else: print "No connection to DB" exit() @@ -123,8 +123,8 @@ def LinkBookToTags(book_id,tag_ids): def SetPath(book_id,path,dataname,filesize,cover): if database: c = database.cursor() - c.execute('UPDATE metadata.books SET path=%s, has_cover=%s WHERE id=%s', (path,cover,book_id)) - c.execute('INSERT INTO metadata.data(book,format,uncompressed_size,name) values (%s,%s,%s,%s)',(book_id,'FB2',filesize,dataname)) + c.execute('UPDATE metadata.books SET path=%s, has_cover=%s WHERE id=%s', [path,cover,book_id]) + c.execute('INSERT INTO metadata.data(book,format,uncompressed_size,name) values (%s,%s,%s,%s)',[book_id,'FB2',filesize,dataname]) else: print "No connection to DB" exit() @@ -132,7 +132,7 @@ def SetPath(book_id,path,dataname,filesize,cover): def StoreComment(book_id,comment): if database: c = database.cursor() - c.execute('INSERT INTO metadata.comments(book,text) values (%s,%s)',(book_id,comment)) + c.execute('INSERT INTO metadata.comments(book,text) values (%s,%s)',[book_id,comment]) else: print "No connection to DB" exit() @@ -140,7 +140,7 @@ def StoreComment(book_id,comment): def PathByID(book_id): if database: c = database.cursor() - c.execute('SELECT path FROM metadata.books WHERE id=%s',(book_id)) + c.execute('SELECT path FROM metadata.books WHERE id=%s',[book_id]) return c.fetchone()[0] else: print "No connection to DB" @@ -149,7 +149,7 @@ def PathByID(book_id): def DataByID(book_id,format): if database: c = database.cursor() - c.execute('SELECT name FROM metadata.data WHERE book=%s and format=%s',(book_id,format)) + c.execute('SELECT name FROM metadata.data WHERE book=%s and format=%s',[book_id,format]) return c.fetchone()[0]+'.'+format.lower() else: print "No connection to DB" @@ -158,7 +158,7 @@ def DataByID(book_id,format): def DelBook(book_id): if database: c = database.cursor() - c.execute('DELETE FROM metadata.books WHERE id=%s',(book_id)) + c.execute('DELETE FROM metadata.books WHERE id=%s',[book_id]) else: print "No connection to DB" exit() @@ -166,7 +166,7 @@ def DelBook(book_id): def ChangeBookFormat(book_id,old_format,new_format): if database: c = database.cursor() - c.execute('UPDATE metadata.data SET format=%s WHERE book=%s and format=%s',(new_format,book_id,old_format)) + c.execute('UPDATE metadata.data SET format=%s WHERE book=%s and format=%s',[new_format,book_id,old_format]) else: print "No connection to DB" exit() @@ -174,7 +174,7 @@ def ChangeBookFormat(book_id,old_format,new_format): def TestArchive(name): if database: c = database.cursor() - c.execute('SELECT count(*) from metadata.processed_archives WHERE filename=%s',(name)) + c.execute('SELECT count(*) from metadata.processed_archives WHERE filename=%s',[name]) return c.fetchone()[0] else: print "No connection to DB" @@ -183,7 +183,7 @@ def TestArchive(name): def MarkArchive(name): if database: c = database.cursor() - c.execute('insert into metadata.processed_archives(filename) values (%s)',(name)) + c.execute('insert into metadata.processed_archives(filename) values (%s)',[name]) else: print "No connection to DB" exit() @@ -191,7 +191,7 @@ def MarkArchive(name): def ListByFormat(format,limit=100): if database: c = database.cursor() - c.execute('SELECT DISTINCT book FROM metadata.data WHERE format=%s ORDER BY book LIMIT 0,%s',(format,limit)) + c.execute('SELECT DISTINCT book FROM metadata.data WHERE format=%s ORDER BY book LIMIT 0,%s',[format,limit]) return c.fetchall() else: print "No connection to DB" @@ -200,7 +200,7 @@ def ListByFormat(format,limit=100): def ListDups(limit=100): if database: c = database.cursor() - c.execute('SELECT b.title,l.author,max(b.id) id FROM metadata.books b,metadata.books_authors_link l where b.id=l.book group by b.title,l.author having count(*)>%s',(limit)) + c.execute('SELECT b.title,l.author,max(b.id) id FROM metadata.books b,metadata.books_authors_link l where b.id=l.book group by b.title,l.author having count(*)>%s',[limit]) return c.fetchall() else: print "No connection to DB" @@ -209,7 +209,7 @@ def ListDups(limit=100): def ListByTitleAndAuthor(title,author,id=0): if database: c = database.cursor() - c.execute('SELECT b.id FROM metadata.books b,metadata.books_authors_link l where b.id=l.book and b.title=%s and l.author=%s and b.id<>%s',(title,author,id)) + c.execute('SELECT b.id FROM metadata.books b,metadata.books_authors_link l where b.id=l.book and b.title=%s and l.author=%s and b.id<>%s',[title,author,id]) return c.fetchall() else: print "No connection to DB"