mardi 22 mars 2016

Rename a prefix of an attribute with SQLite and C#

I have an application server that want keep the last N versions of client's files. The client application send all the files and all the information about folders and changes of the file system. I have to build a database that want represent a file system with SQLite. The table that I have design are:

    FOLDER(FolderPath TEXT,
           User TEXT,
           ParentPath TEXT,
           TimestampFolder DATETIME DEFAULT CURRENT_TIMESTAMP,
           TimestampParent DATETIME,
           Present TEXT,
           PRIMARY KEY(FolderPath,User,TimestampFolder), 
           FOREIGN KEY(User) REFERENCES USER (Username) ON DELETE CASCADE ON UPDATE CASCADE,
           FOREIGN KEY(ParentPath, User, TimestampParent)
           REFERENCES FOLDER(FolderPath, User, TimestampFolder) ON DELETE CASCADE ON UPDATE CASCADE);

FolderPath contains the path of the folder. The problem is when the client performs a rename of a folder. If it renames a folder I can rename the specific FolderPath and consequently in cascade the attribute that references the tuple. But does not rename the attribute FolderPath of all childs folders.

For example: before renaming

FolderPath | FolderParent
    C:     |    NULL
   C:/A    |     C
  C:/A/B   |   C:/A

after renaming (from A to C)

FolderPath | FolderParent
    C:     |    NULL
   C:/C    |     C
  C:/A/B   |   C:/C

I want rename also the prefix of C:/A/B to C:/C/B keeping the suffix with a SQL query. I look the operator LIKE with the wildcard % but I don't know how use them.

I would like to happen this:

before renaming

FolderPath | FolderParent
    C:     |    NULL
   C:/A    |     C
  C:/A/B   |   C:/A

after renaming (from A to C)

FolderPath | FolderParent
    C:     |    NULL
   C:/C    |     C
  C:/C/B   |   C:/C

Sorry for my english. Marco.

Aucun commentaire:

Enregistrer un commentaire