SQLite更新后触发重命名相同的文件名

SQLite更新后触发重命名相同的文件名,sqlite,triggers,sql-update,Sqlite,Triggers,Sql Update,我正在数据库中存储一些文件信息,并通过sql生成文件名 我正在使用以下内容更新所有行: UPDATE contacts_New SET PhotoName=PersonName||'_'|| Date 问题是,我想重命名重复项,如: Person1_Date -> Person1_Date ........ Person2_Date -> Person2_Date Person2_Date -> Person2_Date-2 Perso

我正在数据库中存储一些文件信息,并通过sql生成文件名

我正在使用以下内容更新所有行:

UPDATE contacts_New SET PhotoName=PersonName||'_'|| Date
问题是,我想重命名重复项,如:

    Person1_Date -> Person1_Date
    ........
    Person2_Date -> Person2_Date
    Person2_Date -> Person2_Date-2
    Person2_Date -> Person2_Date-3
    Person2_Date -> Person2_Date-4
    ........
    Person10_Date -> Person10_Date
我尝试使用更新触发器执行此操作:

CREATE TRIGGER ReNamePhotoNames UPDATE OF PhotoName ON contacts_New for each row
  BEGIN
    UPDATE contacts_New SET PhotoName=PhotoName || '-' || (SELECT count(*)+1 from contacts_New where PhotoName=new.PhotoName) WHERE (PhotoName=new.PhotoName);
  END;
结果:

Person1_Date -> Person1_Date
........
Person2_Date -> Person2_Date
Person2_Date -> Person2_Date-2
Person2_Date -> Person2_Date-2
Person2_Date -> Person2_Date-2
........
Person10_Date -> Person10_Date
我怎样才能解决这个问题

多谢各位

我解决了这个问题:

            DROP TRIGGER IF exists ReNamePhotoNames;
            CREATE TRIGGER ReNamePhotoNames AFTER UPDATE OF PhotoName ON contacts_New for each row
              BEGIN
                UPDATE contacts_New SET PhotoName =
                    new.PhotoName || 
                    CASE WHEN 
                        (SELECT count(*) from contacts_New where (PhotoName LIKE new.PhotoName ||'%')) > 1 
                    THEN 
                        (SELECT count(*) from contacts_New where (PhotoName LIKE new.PhotoName ||'%')) 
                    ELSE '' END || '.jpg'
                WHERE ((PhotoName LIKE new.PhotoName) AND (IFNULL(PhotoCreated,'') IS NOT ''));
              END;