def GetTagId(self, tag) -> int: clean_tag = HydrusTags.CleanTag(tag) try: HydrusTags.CheckTagNotEmpty(clean_tag) except HydrusExceptions.TagSizeException: raise HydrusExceptions.TagSizeException( '"{}" tag seems not valid--when cleaned, it ends up with zero size!' .format(tag)) result = self._Execute( 'SELECT tag_id FROM local_tags_cache WHERE tag = ?;', (tag, )).fetchone() if result is None: return self.modules_tags.GetTagId(tag) else: (tag_id, ) = result return tag_id
def GetTagId( self, tag ) -> int: clean_tag = HydrusTags.CleanTag( tag ) try: HydrusTags.CheckTagNotEmpty( clean_tag ) except HydrusExceptions.TagSizeException: # update this to instead go 'hey, does the dirty tag exist?' if it does, run the fix invalid tags routine raise HydrusExceptions.TagSizeException( '"{}" tag seems not valid--when cleaned, it ends up with zero size!'.format( tag ) ) ( namespace, subtag ) = HydrusTags.SplitTag( clean_tag ) namespace_id = self.GetNamespaceId( namespace ) subtag_id = self.GetSubtagId( subtag ) result = self._c.execute( 'SELECT tag_id FROM tags WHERE namespace_id = ? AND subtag_id = ?;', ( namespace_id, subtag_id ) ).fetchone() if result is None: self._c.execute( 'INSERT INTO tags ( namespace_id, subtag_id ) VALUES ( ?, ? );', ( namespace_id, subtag_id ) ) tag_id = self._c.lastrowid else: ( tag_id, ) = result return tag_id
def TagExists( self, tag ): try: tag = HydrusTags.CleanTag( tag ) except: return False try: HydrusTags.CheckTagNotEmpty( tag ) except HydrusExceptions.TagSizeException: return False ( namespace, subtag ) = HydrusTags.SplitTag( tag ) if self.NamespaceExists( namespace ): namespace_id = self.GetNamespaceId( namespace ) else: return False if self.SubtagExists( subtag ): subtag_id = self.GetSubtagId( subtag ) result = self._c.execute( 'SELECT 1 FROM tags WHERE namespace_id = ? AND subtag_id = ?;', ( namespace_id, subtag_id ) ).fetchone() if result is None: return False else: return True else: return False
def SubtagExists(self, subtag): try: HydrusTags.CheckTagNotEmpty(subtag) except HydrusExceptions.TagSizeException: return False result = self._Execute('SELECT 1 FROM subtags WHERE subtag = ?;', (subtag, )).fetchone() if result is None: return False else: return True