Revert "Start id numbering with 0, not 1"

This reverts commit 22ddd28f0b.
This commit is contained in:
croneter 2018-03-04 13:39:40 +01:00
parent 8272a67b5f
commit 275283616e
2 changed files with 22 additions and 23 deletions

View file

@ -207,7 +207,7 @@ class Movies(Items):
except TypeError: except TypeError:
# movieid # movieid
update_item = False update_item = False
kodicursor.execute("SELECT COALESCE(MAX(idMovie),-1) FROM movie") kodicursor.execute("select coalesce(max(idMovie),0) from movie")
movieid = kodicursor.fetchone()[0] + 1 movieid = kodicursor.fetchone()[0] + 1
else: else:
@ -547,7 +547,7 @@ class TVShows(Items):
pathid = plex_dbitem[2] pathid = plex_dbitem[2]
except TypeError: except TypeError:
update_item = False update_item = False
kodicursor.execute("SELECT COALESCE(MAX(idShow),-1) from tvshow") kodicursor.execute("select coalesce(max(idShow),0) from tvshow")
showid = kodicursor.fetchone()[0] + 1 showid = kodicursor.fetchone()[0] + 1
else: else:
@ -834,8 +834,7 @@ class TVShows(Items):
except TypeError: except TypeError:
update_item = False update_item = False
# episodeid # episodeid
query = 'SELECT COALESCE(MAX(idEpisode),-1) FROM episode' kodicursor.execute("select coalesce(max(idEpisode),0) from episode")
kodicursor.execute(query)
episodeid = kodicursor.fetchone()[0] + 1 episodeid = kodicursor.fetchone()[0] + 1
else: else:
# Verification the item is still in Kodi # Verification the item is still in Kodi
@ -1594,7 +1593,7 @@ class Music(Items):
except TypeError: except TypeError:
# Songid not found # Songid not found
update_item = False update_item = False
kodicursor.execute("SELECT COALESCE(MAX(idSong),-1) FROM song") kodicursor.execute("select coalesce(max(idSong),0) from song")
songid = kodicursor.fetchone()[0] + 1 songid = kodicursor.fetchone()[0] + 1
# The song details ##### # The song details #####
@ -1747,7 +1746,7 @@ class Music(Items):
# No album found, create a single's album # No album found, create a single's album
LOG.info("Failed to add album. Creating singles.") LOG.info("Failed to add album. Creating singles.")
kodicursor.execute( kodicursor.execute(
"SELECT COALESCE(MAX(idAlbum),-1) FROM album") "select coalesce(max(idAlbum),0) from album")
albumid = kodicursor.fetchone()[0] + 1 albumid = kodicursor.fetchone()[0] + 1
if v.KODIVERSION >= 16: if v.KODIVERSION >= 16:
# Kodi Jarvis # Kodi Jarvis

View file

@ -62,7 +62,7 @@ class KodiDBMethods(object):
""" """
path_id = self.getPath('plugin://%s.movies/' % v.ADDON_ID) path_id = self.getPath('plugin://%s.movies/' % v.ADDON_ID)
if path_id is None: if path_id is None:
self.cursor.execute("SELECT COALESCE(MAX(idPath),-1) FROM path") self.cursor.execute("select coalesce(max(idPath),0) from path")
path_id = self.cursor.fetchone()[0] + 1 path_id = self.cursor.fetchone()[0] + 1
query = ''' query = '''
INSERT INTO path(idPath, INSERT INTO path(idPath,
@ -82,7 +82,7 @@ class KodiDBMethods(object):
# And TV shows # And TV shows
path_id = self.getPath('plugin://%s.tvshows/' % v.ADDON_ID) path_id = self.getPath('plugin://%s.tvshows/' % v.ADDON_ID)
if path_id is None: if path_id is None:
self.cursor.execute("SELECT COALESCE(MAX(idPath),-1) FROM path") self.cursor.execute("select coalesce(max(idPath),0) from path")
path_id = self.cursor.fetchone()[0] + 1 path_id = self.cursor.fetchone()[0] + 1
query = ''' query = '''
INSERT INTO path(idPath, INSERT INTO path(idPath,
@ -113,7 +113,7 @@ class KodiDBMethods(object):
parentpath = "%s/" % dirname(dirname(path)) parentpath = "%s/" % dirname(dirname(path))
pathid = self.getPath(parentpath) pathid = self.getPath(parentpath)
if pathid is None: if pathid is None:
self.cursor.execute("SELECT COALESCE(MAX(idPath),-1) FROM path") self.cursor.execute("select coalesce(max(idPath),0) from path")
pathid = self.cursor.fetchone()[0] + 1 pathid = self.cursor.fetchone()[0] + 1
query = ' '.join(( query = ' '.join((
"INSERT INTO path(idPath, strPath)", "INSERT INTO path(idPath, strPath)",
@ -143,7 +143,7 @@ class KodiDBMethods(object):
try: try:
pathid = self.cursor.fetchone()[0] pathid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute("SELECT COALESCE(MAX(idPath),-1) FROM path") self.cursor.execute("select coalesce(max(idPath),0) from path")
pathid = self.cursor.fetchone()[0] + 1 pathid = self.cursor.fetchone()[0] + 1
if strHash is None: if strHash is None:
query = ( query = (
@ -197,7 +197,7 @@ class KodiDBMethods(object):
try: try:
fileid = self.cursor.fetchone()[0] fileid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute("SELECT COALESCE(MAX(idFile),-1) FROM files") self.cursor.execute("select coalesce(max(idFile),0) from files")
fileid = self.cursor.fetchone()[0] + 1 fileid = self.cursor.fetchone()[0] + 1
query = ( query = (
''' '''
@ -684,7 +684,7 @@ class KodiDBMethods(object):
# Set the resume bookmark # Set the resume bookmark
if resume_seconds: if resume_seconds:
self.cursor.execute( self.cursor.execute(
'SELECT COALESCE(MAX(idBookmark),-1) FROM bookmark') 'select coalesce(max(idBookmark),0) from bookmark')
bookmark_id = self.cursor.fetchone()[0] + 1 bookmark_id = self.cursor.fetchone()[0] + 1
query = ''' query = '''
INSERT INTO bookmark( INSERT INTO bookmark(
@ -721,7 +721,7 @@ class KodiDBMethods(object):
tag_id = self.cursor.fetchone()[0] tag_id = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute("SELECT COALESCE(MAX(tag_id),-1) FROM tag") self.cursor.execute("select coalesce(max(tag_id),0) from tag")
tag_id = self.cursor.fetchone()[0] + 1 tag_id = self.cursor.fetchone()[0] + 1
query = "INSERT INTO tag(tag_id, name) values(?, ?)" query = "INSERT INTO tag(tag_id, name) values(?, ?)"
@ -772,7 +772,7 @@ class KodiDBMethods(object):
setid = self.cursor.fetchone()[0] setid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute("SELECT COALESCE(MAX(idSet),-1) FROM sets") self.cursor.execute("select coalesce(max(idSet),0) from sets")
setid = self.cursor.fetchone()[0] + 1 setid = self.cursor.fetchone()[0] + 1
query = "INSERT INTO sets(idSet, strSet) values(?, ?)" query = "INSERT INTO sets(idSet, strSet) values(?, ?)"
@ -836,9 +836,9 @@ class KodiDBMethods(object):
try: try:
seasonid = self.cursor.fetchone()[0] seasonid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute("SELECT COALESCE(MAX(idSeason),-1) FROM seasons") self.cursor.execute("select coalesce(max(idSeason),0) from seasons")
seasonid = self.cursor.fetchone()[0] + 1 seasonid = self.cursor.fetchone()[0] + 1
query = "INSERT INTO seasons(idSeason, idShow, season) VALUES(?, ?, ?)" query = "INSERT INTO seasons(idSeason, idShow, season) values(?, ?, ?)"
self.cursor.execute(query, (seasonid, showid, seasonnumber)) self.cursor.execute(query, (seasonid, showid, seasonnumber))
return seasonid return seasonid
@ -874,10 +874,10 @@ class KodiDBMethods(object):
# [Missing Tag] strMusicBrainzArtistID: Artist Tag Missing # [Missing Tag] strMusicBrainzArtistID: Artist Tag Missing
if v.KODIVERSION >= 17: if v.KODIVERSION >= 17:
self.cursor.execute( self.cursor.execute(
"SELECT COALESCE(MAX(idArtist),1) FROM artist") "select coalesce(max(idArtist),1) from artist")
else: else:
self.cursor.execute( self.cursor.execute(
"SELECT COALESCE(MAX(idArtist),-1) FROM artist") "select coalesce(max(idArtist),0) from artist")
artistid = self.cursor.fetchone()[0] + 1 artistid = self.cursor.fetchone()[0] + 1
query = ( query = (
''' '''
@ -907,7 +907,7 @@ class KodiDBMethods(object):
albumid = self.cursor.fetchone()[0] albumid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
# Create the album # Create the album
self.cursor.execute("SELECT COALESCE(MAX(idAlbum),-1) FROM album") self.cursor.execute("select coalesce(max(idAlbum),0) from album")
albumid = self.cursor.fetchone()[0] + 1 albumid = self.cursor.fetchone()[0] + 1
query = ( query = (
''' '''
@ -944,7 +944,7 @@ class KodiDBMethods(object):
genreid = self.cursor.fetchone()[0] genreid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
# Create the genre # Create the genre
self.cursor.execute("SELECT COALESCE(MAX(idGenre),-1) FROM genre") self.cursor.execute("select coalesce(max(idGenre),0) from genre")
genreid = self.cursor.fetchone()[0] + 1 genreid = self.cursor.fetchone()[0] + 1
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)" query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
self.cursor.execute(query, (genreid, genre)) self.cursor.execute(query, (genreid, genre))
@ -975,7 +975,7 @@ class KodiDBMethods(object):
genreid = self.cursor.fetchone()[0] genreid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
# Create the genre # Create the genre
self.cursor.execute("SELECT COALESCE(MAX(idGenre),-1) FROM genre") self.cursor.execute("select coalesce(max(idGenre),0) from genre")
genreid = self.cursor.fetchone()[0] + 1 genreid = self.cursor.fetchone()[0] + 1
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)" query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
self.cursor.execute(query, (genreid, genre)) self.cursor.execute(query, (genreid, genre))
@ -1024,7 +1024,7 @@ class KodiDBMethods(object):
uniqueid = self.cursor.fetchone()[0] uniqueid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute( self.cursor.execute(
'SELECT COALESCE(MAX(uniqueid_id),-1) FROM uniqueid') 'SELECT COALESCE(MAX(uniqueid_id),0) FROM uniqueid')
uniqueid = self.cursor.fetchone()[0] + 1 uniqueid = self.cursor.fetchone()[0] + 1
return uniqueid return uniqueid
@ -1055,7 +1055,7 @@ class KodiDBMethods(object):
try: try:
ratingid = self.cursor.fetchone()[0] ratingid = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute('SELECT COALESCE(MAX(rating_id),-1) FROM rating') self.cursor.execute('SELECT COALESCE(MAX(rating_id),0) FROM rating')
ratingid = self.cursor.fetchone()[0] + 1 ratingid = self.cursor.fetchone()[0] + 1
return ratingid return ratingid