mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-08 02:53:38 +00:00
Fix SQL statements that have dynamic table names to use proper syntax.
This commit is contained in:
parent
3648e55c46
commit
aa9346222e
3 changed files with 18 additions and 17 deletions
|
@ -25,6 +25,7 @@
|
||||||
* Overhaul all Add Show pages
|
* Overhaul all Add Show pages
|
||||||
* Fix Display Show next/previous when show list is split
|
* Fix Display Show next/previous when show list is split
|
||||||
* Change Display Show next/previous when show list is not split to loop around
|
* Change Display Show next/previous when show list is not split to loop around
|
||||||
|
* Fix SQL statements that have dynamic table names to use proper syntax
|
||||||
|
|
||||||
[develop changelog]
|
[develop changelog]
|
||||||
* Add TVRage network name standardization
|
* Add TVRage network name standardization
|
||||||
|
|
|
@ -98,7 +98,7 @@ class BlackAndWhiteList(object):
|
||||||
def _add_keywords(self, table, range, values):
|
def _add_keywords(self, table, range, values):
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
for value in values:
|
for value in values:
|
||||||
myDB.action("INSERT INTO " + table + " (show_id, range , keyword) VALUES (?,?,?)", [self.show_id, range, value])
|
myDB.action("INSERT INTO [" + table + "] (show_id, range , keyword) VALUES (?,?,?)", [self.show_id, range, value])
|
||||||
|
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
|
@ -117,18 +117,18 @@ class BlackAndWhiteList(object):
|
||||||
def _del_all_keywords(self, table):
|
def _del_all_keywords(self, table):
|
||||||
logger.log(u"Deleting all " + table + " keywords for " + str(self.show_id), logger.DEBUG)
|
logger.log(u"Deleting all " + table + " keywords for " + str(self.show_id), logger.DEBUG)
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
myDB.action("DELETE FROM " + table + " WHERE show_id = ?", [self.show_id])
|
myDB.action("DELETE FROM [" + table + "] WHERE show_id = ?", [self.show_id])
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def _del_all_keywords_for(self, table, range):
|
def _del_all_keywords_for(self, table, range):
|
||||||
logger.log(u"Deleting all " + range + " " + table + " keywords for " + str(self.show_id), logger.DEBUG)
|
logger.log(u"Deleting all " + range + " " + table + " keywords for " + str(self.show_id), logger.DEBUG)
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
myDB.action("DELETE FROM " + table + " WHERE show_id = ? and range = ?", [self.show_id, range])
|
myDB.action("DELETE FROM [" + table + "] WHERE show_id = ? and range = ?", [self.show_id, range])
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def _load_list(self, table):
|
def _load_list(self, table):
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
sqlResults = myDB.select("SELECT range,keyword FROM " + table + " WHERE show_id = ? ", [self.show_id])
|
sqlResults = myDB.select("SELECT range,keyword FROM [" + table + "] WHERE show_id = ? ", [self.show_id])
|
||||||
if not sqlResults or not len(sqlResults):
|
if not sqlResults or not len(sqlResults):
|
||||||
return ([], {})
|
return ([], {})
|
||||||
|
|
||||||
|
|
|
@ -229,20 +229,20 @@ class DBConnection(object):
|
||||||
|
|
||||||
genParams = lambda myDict: [x + " = ?" for x in myDict.keys()]
|
genParams = lambda myDict: [x + " = ?" for x in myDict.keys()]
|
||||||
|
|
||||||
query = "UPDATE " + tableName + " SET " + ", ".join(genParams(valueDict)) + " WHERE " + " AND ".join(
|
query = "UPDATE [" + tableName + "] SET " + ", ".join(genParams(valueDict)) + " WHERE " + " AND ".join(
|
||||||
genParams(keyDict))
|
genParams(keyDict))
|
||||||
|
|
||||||
self.action(query, valueDict.values() + keyDict.values())
|
self.action(query, valueDict.values() + keyDict.values())
|
||||||
|
|
||||||
if self.connection.total_changes == changesBefore:
|
if self.connection.total_changes == changesBefore:
|
||||||
query = "INSERT INTO " + tableName + " (" + ", ".join(valueDict.keys() + keyDict.keys()) + ")" + \
|
query = "INSERT INTO [" + tableName + "] (" + ", ".join(valueDict.keys() + keyDict.keys()) + ")" + \
|
||||||
" VALUES (" + ", ".join(["?"] * len(valueDict.keys() + keyDict.keys())) + ")"
|
" VALUES (" + ", ".join(["?"] * len(valueDict.keys() + keyDict.keys())) + ")"
|
||||||
self.action(query, valueDict.values() + keyDict.values())
|
self.action(query, valueDict.values() + keyDict.values())
|
||||||
|
|
||||||
def tableInfo(self, tableName):
|
def tableInfo(self, tableName):
|
||||||
|
|
||||||
# FIXME ? binding is not supported here, but I cannot find a way to escape a string manually
|
# FIXME ? binding is not supported here, but I cannot find a way to escape a string manually
|
||||||
sqlResult = self.select("PRAGMA table_info(%s)" % tableName)
|
sqlResult = self.select("PRAGMA table_info([%s])" % tableName)
|
||||||
columns = {}
|
columns = {}
|
||||||
for column in sqlResult:
|
for column in sqlResult:
|
||||||
columns[column['name']] = {'type': column['type']}
|
columns[column['name']] = {'type': column['type']}
|
||||||
|
@ -262,8 +262,8 @@ class DBConnection(object):
|
||||||
return column in self.tableInfo(tableName)
|
return column in self.tableInfo(tableName)
|
||||||
|
|
||||||
def addColumn(self, table, column, type="NUMERIC", default=0):
|
def addColumn(self, table, column, type="NUMERIC", default=0):
|
||||||
self.action("ALTER TABLE %s ADD %s %s" % (table, column, type))
|
self.action("ALTER TABLE [%s] ADD %s %s" % (table, column, type))
|
||||||
self.action("UPDATE %s SET %s = ?" % (table, column), (default,))
|
self.action("UPDATE [%s] SET %s = ?" % (table, column), (default,))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Close database connection"""
|
"""Close database connection"""
|
||||||
|
@ -353,12 +353,12 @@ class SchemaUpgrade(object):
|
||||||
return column in self.connection.tableInfo(tableName)
|
return column in self.connection.tableInfo(tableName)
|
||||||
|
|
||||||
def addColumn(self, table, column, type="NUMERIC", default=0):
|
def addColumn(self, table, column, type="NUMERIC", default=0):
|
||||||
self.connection.action("ALTER TABLE %s ADD %s %s" % (table, column, type))
|
self.connection.action("ALTER TABLE [%s] ADD %s %s" % (table, column, type))
|
||||||
self.connection.action("UPDATE %s SET %s = ?" % (table, column), (default,))
|
self.connection.action("UPDATE [%s] SET %s = ?" % (table, column), (default,))
|
||||||
|
|
||||||
def dropColumn(self, table, column):
|
def dropColumn(self, table, column):
|
||||||
# get old table columns and store the ones we want to keep
|
# get old table columns and store the ones we want to keep
|
||||||
result = self.connection.select('pragma table_info(%s)' % table)
|
result = self.connection.select('pragma table_info([%s])' % table)
|
||||||
keptColumns = [c for c in result if c['name'] != column]
|
keptColumns = [c for c in result if c['name'] != column]
|
||||||
|
|
||||||
keptColumnsNames = []
|
keptColumnsNames = []
|
||||||
|
@ -395,21 +395,21 @@ class SchemaUpgrade(object):
|
||||||
|
|
||||||
# generate sql for the new table creation
|
# generate sql for the new table creation
|
||||||
if len(pk) == 0:
|
if len(pk) == 0:
|
||||||
sql = 'CREATE TABLE %s_new (%s)' % (table, final)
|
sql = 'CREATE TABLE [%s_new] (%s)' % (table, final)
|
||||||
else:
|
else:
|
||||||
pk = ', '.join(pk)
|
pk = ', '.join(pk)
|
||||||
sql = 'CREATE TABLE %s_new (%s, PRIMARY KEY(%s))' % (table, final, pk)
|
sql = 'CREATE TABLE [%s_new] (%s, PRIMARY KEY(%s))' % (table, final, pk)
|
||||||
|
|
||||||
# create new temporary table and copy the old table data across, barring the removed column
|
# create new temporary table and copy the old table data across, barring the removed column
|
||||||
self.connection.action(sql)
|
self.connection.action(sql)
|
||||||
self.connection.action('INSERT INTO %s_new SELECT %s FROM %s' % (table, keptColumnsNames, table))
|
self.connection.action('INSERT INTO [%s_new] SELECT %s FROM [%s]' % (table, keptColumnsNames, table))
|
||||||
|
|
||||||
# copy the old indexes from the old table
|
# copy the old indexes from the old table
|
||||||
result = self.connection.select('SELECT sql FROM sqlite_master WHERE tbl_name=? and type="index"', [table])
|
result = self.connection.select('SELECT sql FROM sqlite_master WHERE tbl_name=? and type="index"', [table])
|
||||||
|
|
||||||
# remove the old table and rename the new table to take it's place
|
# remove the old table and rename the new table to take it's place
|
||||||
self.connection.action('DROP TABLE %s' % table)
|
self.connection.action('DROP TABLE [%s]' % table)
|
||||||
self.connection.action('ALTER TABLE %s_new RENAME TO %s' % (table, table))
|
self.connection.action('ALTER TABLE [%s_new] RENAME TO [%s]' % (table, table))
|
||||||
|
|
||||||
# write any indexes to the new table
|
# write any indexes to the new table
|
||||||
if len(result) > 0:
|
if len(result) > 0:
|
||||||
|
|
Loading…
Reference in a new issue