Start id numbering with 0, not 1

This commit is contained in:
croneter 2018-03-02 07:48:38 +01:00
parent 688023c906
commit 22ddd28f0b
2 changed files with 23 additions and 22 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),0) from movie") kodicursor.execute("SELECT COALESCE(MAX(idMovie),-1) FROM movie")
movieid = kodicursor.fetchone()[0] + 1 movieid = kodicursor.fetchone()[0] + 1
else: else:
@ -544,7 +544,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),0) from tvshow") kodicursor.execute("SELECT COALESCE(MAX(idShow),-1) from tvshow")
showid = kodicursor.fetchone()[0] + 1 showid = kodicursor.fetchone()[0] + 1
else: else:
@ -825,7 +825,8 @@ class TVShows(Items):
except TypeError: except TypeError:
update_item = False update_item = False
# episodeid # episodeid
kodicursor.execute("select coalesce(max(idEpisode),0) from episode") query = 'SELECT COALESCE(MAX(idEpisode),-1) 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
@ -1581,7 +1582,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),0) from song") kodicursor.execute("SELECT COALESCE(MAX(idSong),-1) FROM song")
songid = kodicursor.fetchone()[0] + 1 songid = kodicursor.fetchone()[0] + 1
# The song details ##### # The song details #####
@ -1734,7 +1735,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),0) from album") "SELECT COALESCE(MAX(idAlbum),-1) 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),0) from path") self.cursor.execute("SELECT COALESCE(MAX(idPath),-1) 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),0) from path") self.cursor.execute("SELECT COALESCE(MAX(idPath),-1) 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),0) from path") self.cursor.execute("SELECT COALESCE(MAX(idPath),-1) 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),0) from path") self.cursor.execute("SELECT COALESCE(MAX(idPath),-1) 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),0) from files") self.cursor.execute("SELECT COALESCE(MAX(idFile),-1) FROM files")
fileid = self.cursor.fetchone()[0] + 1 fileid = self.cursor.fetchone()[0] + 1
query = ( query = (
''' '''
@ -707,7 +707,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),0) from bookmark') 'SELECT COALESCE(MAX(idBookmark),-1) FROM bookmark')
bookmark_id = self.cursor.fetchone()[0] + 1 bookmark_id = self.cursor.fetchone()[0] + 1
query = ''' query = '''
INSERT INTO bookmark( INSERT INTO bookmark(
@ -744,7 +744,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),0) from tag") self.cursor.execute("SELECT COALESCE(MAX(tag_id),-1) 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(?, ?)"
@ -795,7 +795,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),0) from sets") self.cursor.execute("SELECT COALESCE(MAX(idSet),-1) 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(?, ?)"
@ -859,9 +859,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),0) from seasons") self.cursor.execute("SELECT COALESCE(MAX(idSeason),-1) 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
@ -897,10 +897,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),0) from artist") "SELECT COALESCE(MAX(idArtist),-1) FROM artist")
artistid = self.cursor.fetchone()[0] + 1 artistid = self.cursor.fetchone()[0] + 1
query = ( query = (
''' '''
@ -930,7 +930,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),0) from album") self.cursor.execute("SELECT COALESCE(MAX(idAlbum),-1) FROM album")
albumid = self.cursor.fetchone()[0] + 1 albumid = self.cursor.fetchone()[0] + 1
query = ( query = (
''' '''
@ -967,7 +967,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),0) from genre") self.cursor.execute("SELECT COALESCE(MAX(idGenre),-1) 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))
@ -998,7 +998,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),0) from genre") self.cursor.execute("SELECT COALESCE(MAX(idGenre),-1) 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))
@ -1047,7 +1047,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),0) FROM uniqueid') 'SELECT COALESCE(MAX(uniqueid_id),-1) FROM uniqueid')
uniqueid = self.cursor.fetchone()[0] + 1 uniqueid = self.cursor.fetchone()[0] + 1
return uniqueid return uniqueid
@ -1078,7 +1078,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),0) FROM rating') self.cursor.execute('SELECT COALESCE(MAX(rating_id),-1) FROM rating')
ratingid = self.cursor.fetchone()[0] + 1 ratingid = self.cursor.fetchone()[0] + 1
return ratingid return ratingid