[英]How to detect only the changes in the uploaded file?
If i have an xml
file (uploaded to my server), and i do some processing on it to get the data from it,then store those data in my database . 如果我有一个
xml
文件(已上传到服务器),并且对其进行了一些处理以从中获取数据,则将这些数据存储在数据库中。
If the user makes some changes (insert,update, delete),then upload the file again to my server . 如果用户进行了一些更改(插入,更新,删除),则将文件再次上传到我的服务器。 Is there any way to detect the changes (insert , update , delete)to update my database according to rather than just deleting all the data and inserting them again .especially ,there is some data depends on the the existing data(referential integrity)and if i delete all the data , the dependents will be deleted.(cascade delete)!!
有什么方法可以检测到更改(插入,更新,删除)以根据我的数据库进行更新,而不仅仅是删除所有数据并再次插入它们。特别是,有些数据取决于现有数据(参照完整性),并且如果我删除所有数据,则将删除依赖项。(级联删除)!
As Darin pointed out in his comment, this depends largely on the structure and content of both your XML file and your database. 正如Darin在他的评论中指出的那样,这在很大程度上取决于XML文件和数据库的结构和内容。
In principle currently you delete a set of rows of a certain number of tables and (re-)insert another set of rows afterwards. 原则上,当前您删除具有一定数量表的一组行,然后再(重新)插入另一组行。
If you only want to update your database, you could - for each table - first identify all rows you would currently delete (ie do a SELECT ... WHERE
instead of a DELETE ... WHERE
), prepare a set of rows you would insert and compare these two sets (lets call them DELETE and INSERT ): 如果您只想更新数据库,则可以-对于每个表-首先确定当前要删除的所有行(即,执行
SELECT ... WHERE
而不是DELETE ... WHERE
),准备一组行插入并比较这两个集合(将它们称为DELETE和INSERT ):
But as mentioned, excatly how and in what order to perform these operations depends on your specific data structures. 但是如前所述,执行这些操作的方式和顺序完全取决于您的特定数据结构。 Eg if you have dependencies between tables (ie parent-child relationships), the delete operation on a parent entity has also to take care of the childs (possibly using a
ON DELETE CASCADE
clause in your foreign key definition). 例如,如果您在表之间具有依赖性(即,父子关系),则对父实体的删除操作还必须照顾孩子(可能在外键定义中使用
ON DELETE CASCADE
子句)。 In this case you should also process parent tables befor their child tables. 在这种情况下,您还应该在其子表之前处理父表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.