Exemplo n.º 1
0
 def set_stream_continuity(self, profile_guid, videoid, value):
     """Update or insert a stream continuity value to current profile"""
     # Update or insert approach, if there is no updated row then insert new one
     value = common.convert_to_string(value)
     date_last_modified = common.convert_to_string(datetime.now())
     if self.is_mysql_database:
         query = db_utils.mysql_insert_or_update(
             'stream_continuity', ['ProfileGuid', 'VideoID'],
             ['Value', 'DateLastModified'])
         self._execute_non_query(
             query, (profile_guid, videoid, value, date_last_modified),
             multi=True)
     else:
         update_query = ('UPDATE stream_continuity '
                         'SET Value = ?, DateLastModified = ? '
                         'WHERE ProfileGuid = ? AND VideoID = ?')
         cur = self._execute_query(
             update_query,
             (value, date_last_modified, profile_guid, videoid))
         if cur.rowcount == 0:
             insert_query = (
                 'INSERT INTO stream_continuity '
                 '(ProfileGuid, VideoID, Value, DateLastModified) '
                 'VALUES (?, ?, ?, ?)')
             self._execute_non_query(
                 insert_query,
                 (profile_guid, videoid, value, date_last_modified))
Exemplo n.º 2
0
 def set_values(self, dict_values, table=db_utils.TABLE_APP_CONF):
     """
     Store multiple values to database
     :param dict_values: The key/value to store
     :param table: Table map
     """
     table_name = table[0]
     table_columns = table[1]
     # Doing many sqlite operations at the same makes the performance much worse (especially on Kodi 18)
     # The use of 'executemany' and 'transaction' can improve performance up to about 75% !!
     if common.CmpVersion(sql.sqlite_version) < '3.24.0':
         query = f'INSERT OR REPLACE INTO {table_name} ({table_columns[0]}, {table_columns[1]}) VALUES (?, ?)'
         records_values = [(key, common.convert_to_string(value))
                           for key, value in dict_values.items()]
     else:
         # sqlite UPSERT clause exists only on sqlite >= 3.24.0
         query = (
             f'INSERT INTO {table_name} ({table_columns[0]}, {table_columns[1]}) VALUES (?, ?) '
             f'ON CONFLICT({table_columns[0]}) DO UPDATE SET {table_columns[1]} = ? '
             f'WHERE {table_columns[0]} = ?')
         records_values = []
         for key, value in dict_values.items():
             value_str = common.convert_to_string(value)
             records_values.append((key, value_str, value_str, key))
     cur = self.get_cursor()
     cur.execute("BEGIN TRANSACTION;")
     self._executemany_non_query(query, records_values, cur)
     cur.execute("COMMIT;")
Exemplo n.º 3
0
 def insert_search_item(self, search_type, value, parameters=None):
     """Insert a new search item and return the ID of the new entry"""
     insert_query = ('INSERT INTO search (Guid, Type, Value, Parameters, LastAccess) '
                     'VALUES (?, ?, ?, ?, ?)')
     if parameters:
         parameters = common.convert_to_string(parameters)
     guid = self.get_active_profile_guid()
     date_last_access = common.convert_to_string(datetime.now())
     cur = self.get_cursor()
     self._execute_non_query(insert_query, (guid, search_type, value, parameters, date_last_access), cur)
     return str(cur.lastrowid)
 def set_profile_config(self, key, value, guid=None):
     """Store a value to a profile, if guid is not specified, is stored to active profile"""
     # Update or insert approach, if there is no updated row then insert new one (no id changes)
     if not guid:
         guid = self._get_active_guid_profile()
     update_query = 'UPDATE profiles_config SET Value = ? WHERE Guid = ? AND Name = ?'
     value = common.convert_to_string(value)
     cur = self._execute_query(update_query, (value, guid, key))
     if cur.rowcount == 0:
         insert_query = 'INSERT INTO profiles_config (Guid, Name, Value) VALUES (?, ?, ?)'
         self._execute_non_query(insert_query, (guid, key, value))
 def set_value(self, key, value, table=db_utils.TABLE_SHARED_APP_CONF):
     """
     Store a single value to database
     :param key: The key to store the value
     :param value: Value to save
     :param table: Table map
     """
     table_name = table[0]
     table_columns = table[1]
     # Update or insert approach, if there is no updated row then insert new one (no id changes)
     query = db_utils.mysql_insert_or_update(table_name, [table_columns[0]], [table_columns[1]])
     value = common.convert_to_string(value)
     self._execute_non_query(query, (key, value), multi=True)
Exemplo n.º 6
0
 def set_value(self, key, value, table=db_utils.TABLE_APP_CONF):
     """
     Store a single value to database
     :param key: The key to store the value
     :param value: Value to save
     :param table: Table map
     """
     table_name = table[0]
     table_columns = table[1]
     # Update or insert approach, if there is no updated row then insert new one (no id changes)
     update_query = f'UPDATE {table_name} SET {table_columns[1]} = ? WHERE {table_columns[0]} = ?'
     value = common.convert_to_string(value)
     cur = self._execute_query(update_query, (value, key))
     if cur.rowcount == 0:
         insert_query = f'INSERT INTO {table_name} ({table_columns[0]}, {table_columns[1]}) VALUES (?, ?)'
         self._execute_non_query(insert_query, (key, value))
Exemplo n.º 7
0
 def insert_profile_configs(self, dict_values, guid=None):
     """
     Store multiple values to a profile by deleting all existing values,
     if guid is not specified, is stored to active profile
     """
     # Doing many sqlite operations at the same makes the performance much worse (especially on Kodi 18)
     # The use of 'executemany' and 'transaction' can improve performance up to about 75% !!
     if not guid:
         guid = self._get_active_guid_profile()
     cur = self.get_cursor()
     cur.execute("BEGIN TRANSACTION;")
     query = 'DELETE FROM profiles_config WHERE Guid = ?'
     self._execute_non_query(query, (guid, ), cur)
     records_values = [(guid, key, common.convert_to_string(value))
                       for key, value in dict_values.items()]
     insert_query = 'INSERT INTO profiles_config (Guid, Name, Value) VALUES (?, ?, ?)'
     self._executemany_non_query(insert_query, records_values, cur)
     cur.execute("COMMIT;")
Exemplo n.º 8
0
 def set_watched_status(self, profile_guid, videoid, value):
     """Update or insert the watched status override value to current profile"""
     # Update or insert approach, if there is no updated row then insert new one
     value = common.convert_to_string(value)
     if self.is_mysql_database:
         query = db_utils.mysql_insert_or_update('watched_status_override',
                                                 ['ProfileGuid', 'VideoID'],
                                                 ['Value'])
         self._execute_non_query(query, (profile_guid, videoid, value),
                                 multi=True)
     else:
         update_query = ('UPDATE watched_status_override '
                         'SET Value = ? '
                         'WHERE ProfileGuid = ? AND VideoID = ?')
         cur = self._execute_query(update_query, (value, profile_guid, videoid))
         if cur.rowcount == 0:
             insert_query = ('INSERT INTO watched_status_override '
                             '(ProfileGuid, VideoID, Value) '
                             'VALUES (?, ?, ?)')
             self._execute_non_query(insert_query, (profile_guid, videoid, value))
Exemplo n.º 9
0
 def set_tvshow_property(self, tvshowid, enum_vid_prop, value):
     update_query = ('UPDATE video_lib_tvshows '
                     'SET ' + enum_vid_prop.value +
                     ' = ? WHERE TvShowID = ?')
     value = common.convert_to_string(value)
     cur = self._execute_query(update_query, (value, tvshowid))
Exemplo n.º 10
0
 def update_search_item_value(self, row_id, value):
     """Update the 'value' data to a search item"""
     update_query = 'UPDATE search SET Value = ?, LastAccess = ? WHERE ID = ?'
     date_last_access = common.convert_to_string(datetime.now())
     self._execute_non_query(update_query,
                             (value, date_last_access, row_id))
Exemplo n.º 11
0
 def update_search_item_last_access(self, row_id):
     """Update the last access data to a search item"""
     update_query = 'UPDATE search SET LastAccess = ? WHERE ID = ?'
     date_last_access = common.convert_to_string(datetime.now())
     self._execute_non_query(update_query, (date_last_access, row_id))