'Creates SQL queue for this episode if any of its data has been changed since the last save.
forceSave: If True it will create SQL queue even if no data has been changed since the
last save (aka if the record is not dirty).'

def get_sql(self, forceSave=False):

    try:
        if ((not self.dirty) and (not forceSave)):
            logger.log((str(self.show.indexerid) + u':    Not    creating    SQL    queue    -    record    is    not    dirty'), logger.DEBUG)
            return
        main_db_con = db.DBConnection()
        rows = main_db_con.select(u'SELECT    episode_id,    subtitles    FROM    tv_episodes    WHERE    showid    =    ?    AND    season    =    ?    AND    episode    =    ?', [self.show.indexerid, self.season, self.episode])
        epID = None
        if rows:
            epID = int(rows[0]['episode_id'])
        if epID:
            if (sickbeard.SUBTITLES_MULTI or (not rows[0]['subtitles']) or (not self.subtitles)):
                return [u'UPDATE    tv_episodes    SET    indexerid    =    ?,    indexer    =    ?,    name    =    ?,    description    =    ?,    subtitles    =    ?,    subtitles_searchcount    =    ?,    subtitles_lastsearch    =    ?,    airdate    =    ?,    hasnfo    =    ?,    hastbn    =    ?,    status    =    ?,    location    =    ?,    file_size    =    ?,    release_name    =    ?,    is_proper    =    ?,    showid    =    ?,    season    =    ?,    episode    =    ?,    absolute_number    =    ?,    version    =    ?,    release_group    =    ?    WHERE    episode_id    =    ?', [self.indexerid, self.indexer, self.name, self.description, u','.join(self.subtitles), self.subtitles_searchcount, self.subtitles_lastsearch, self.airdate.toordinal(), self.hasnfo, self.hastbn, self.status, self.location, self.file_size, self.release_name, self.is_proper, self.show.indexerid, self.season, self.episode, self.absolute_number, self.version, self.release_group, epID]]
            else:
                return [u'UPDATE    tv_episodes    SET    indexerid    =    ?,    indexer    =    ?,    name    =    ?,    description    =    ?,    subtitles_searchcount    =    ?,    subtitles_lastsearch    =    ?,    airdate    =    ?,    hasnfo    =    ?,    hastbn    =    ?,    status    =    ?,    location    =    ?,    file_size    =    ?,    release_name    =    ?,    is_proper    =    ?,    showid    =    ?,    season    =    ?,    episode    =    ?,    absolute_number    =    ?,    version    =    ?,    release_group    =    ?    WHERE    episode_id    =    ?', [self.indexerid, self.indexer, self.name, self.description, self.subtitles_searchcount, self.subtitles_lastsearch, self.airdate.toordinal(), self.hasnfo, self.hastbn, self.status, self.location, self.file_size, self.release_name, self.is_proper, self.show.indexerid, self.season, self.episode, self.absolute_number, self.version, self.release_group, epID]]
        else:
            return [u'INSERT    OR    IGNORE    INTO    tv_episodes    (episode_id,    indexerid,    indexer,    name,    description,    subtitles,    subtitles_searchcount,    subtitles_lastsearch,    airdate,    hasnfo,    hastbn,    status,    location,    file_size,    release_name,    is_proper,    showid,    season,    episode,    absolute_number,    version,    release_group)    VALUES    ((SELECT    episode_id    FROM    tv_episodes    WHERE    showid    =    ?    AND    season    =    ?    AND    episode    =    ?),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);', [self.show.indexerid, self.season, self.episode, self.indexerid, self.indexer, self.name, self.description, u','.join(self.subtitles), self.subtitles_searchcount, self.subtitles_lastsearch, self.airdate.toordinal(), self.hasnfo, self.hastbn, self.status, self.location, self.file_size, self.release_name, self.is_proper, self.show.indexerid, self.season, self.episode, self.absolute_number, self.version, self.release_group]]
    except Exception as error:
        logger.log(u'Error    while    updating    database:    {0}'.format(error), logger.ERROR)
