'@param tags: list of strings
@param append: If True existing tags are not removed'

def set_tags(self, id, tags, append=False):

    if (not append):
        self.conn.execute('DELETE    FROM    books_tags_link    WHERE    book=?', (id,))
    for tag in set(tags):
        tag = tag.lower().strip()
        if (not tag):
            continue
        t = self.conn.get('SELECT    id    FROM    tags    WHERE    name=?', (tag,), all=False)
        if t:
            tid = t
        else:
            tid = self.conn.execute('INSERT    INTO    tags(name)    VALUES(?)', (tag,)).lastrowid
        if (not self.conn.get('SELECT    book    FROM    books_tags_link    WHERE    book=?    AND    tag=?', (id, tid), all=False)):
            self.conn.execute('INSERT    INTO    books_tags_link(book,    tag)    VALUES    (?,?)', (id, tid))
    self.conn.commit()
