1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-12 11:02:21 -05:00

Small SQL syntax fix

This commit is contained in:
echel0n 2014-12-17 02:23:48 -08:00
parent 27ce22839c
commit d26576122e
2 changed files with 6 additions and 16 deletions

View File

@ -36,6 +36,7 @@ from sickbeard import clients
from name_parser.parser import NameParser, InvalidNameException, InvalidShowException from name_parser.parser import NameParser, InvalidNameException, InvalidShowException
from sickbeard import encodingKludge as ek from sickbeard import encodingKludge as ek
class CacheDBConnection(db.DBConnection): class CacheDBConnection(db.DBConnection):
def __init__(self, providerName): def __init__(self, providerName):
db.DBConnection.__init__(self, "cache.db") db.DBConnection.__init__(self, "cache.db")
@ -47,7 +48,7 @@ class CacheDBConnection(db.DBConnection):
"CREATE TABLE [" + providerName + "] (name TEXT, season NUMERIC, episodes TEXT, indexerid NUMERIC, url TEXT, time NUMERIC, quality TEXT, release_group TEXT)") "CREATE TABLE [" + providerName + "] (name TEXT, season NUMERIC, episodes TEXT, indexerid NUMERIC, url TEXT, time NUMERIC, quality TEXT, release_group TEXT)")
else: else:
sqlResults = self.select( sqlResults = self.select(
"SELECT url, COUNT(url) as count FROM [" + providerName + "] GROUP BY url HAVING count > 1") "SELECT url, COUNT(url) AS count FROM [" + providerName + "] GROUP BY url HAVING count > 1")
for cur_dupe in sqlResults: for cur_dupe in sqlResults:
self.action("DELETE FROM [" + providerName + "] WHERE url = ?", [cur_dupe["url"]]) self.action("DELETE FROM [" + providerName + "] WHERE url = ?", [cur_dupe["url"]])
@ -75,6 +76,7 @@ class CacheDBConnection(db.DBConnection):
if str(e) != "table lastUpdate already exists": if str(e) != "table lastUpdate already exists":
raise raise
class TVCache(): class TVCache():
def __init__(self, provider): def __init__(self, provider):
@ -233,7 +235,7 @@ class TVCache():
if not parse_result: if not parse_result:
# create showObj from indexer_id if available # create showObj from indexer_id if available
showObj=None showObj = None
if indexer_id: if indexer_id:
showObj = helpers.findCertainShow(sickbeard.showList, indexer_id) showObj = helpers.findCertainShow(sickbeard.showList, indexer_id)
@ -305,8 +307,8 @@ class TVCache():
else: else:
for epObj in episode: for epObj in episode:
cl.append([ cl.append([
"SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ? " "SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ? AND quality IN (" + ",".join(
"AND quality IN (" + ",".join([str(x) for x in epObj.wantedQuality]) + ")", [str(x) for x in epObj.wantedQuality]) + ")",
[epObj.show.indexerid, epObj.season, "%|" + str(epObj.episode) + "|%"]]) [epObj.show.indexerid, epObj.season, "%|" + str(epObj.episode) + "|%"]])
sqlResults = myDB.mass_action(cl, fetchall=True) sqlResults = myDB.mass_action(cl, fetchall=True)

View File

@ -28,20 +28,8 @@ class EncodingTests(unittest.TestCase):
if not sickbeard.SYS_ENCODING or sickbeard.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'): if not sickbeard.SYS_ENCODING or sickbeard.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
sickbeard.SYS_ENCODING = 'UTF-8' sickbeard.SYS_ENCODING = 'UTF-8'
if not hasattr(sys, "setdefaultencoding"):
reload(sys)
try:
# pylint: disable=E1101
# On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError
sys.setdefaultencoding(sickbeard.SYS_ENCODING)
except:
sys.exit("Sorry, you MUST add the SickRage folder to the PYTHONPATH environment variable\n" +
"or find another way to force Python to use " + sickbeard.SYS_ENCODING + " for string encoding.")
for s in strings: for s in strings:
try: try:
show_name = s.decode(sickbeard.SYS_ENCODING, 'xmlcharrefreplace')
show_dir = ek.ek(os.path.join, rootDir, sanitizeFileName(s)) show_dir = ek.ek(os.path.join, rootDir, sanitizeFileName(s))
self.assertTrue(isinstance(show_dir, unicode)) self.assertTrue(isinstance(show_dir, unicode))
except Exception, e: except Exception, e: