The LoBDb.NET recycle bin is a convenient way to restore erroneously deleted records. This mechanism divides the process of deletion in two steps. On the first step a record is deleted from a table as a result of invoking an SQL delete command. On the second step such a record can be restored and or can be permanently deleted from the recycle bin. Let us illustrate it with an example. Suppose that a database contains two tables namely groups and students which are connected by a reference field group_id with the Cascade Delete flag set.

1_schema.png

In order to enable editing the tables let’s grant all necessary permissions to the current user.

2_granting_permissions.png

Then insert a record into the groups table and copy the id value of that row into the clipboard.

3_inserting_group.png

Insert two records into the students table that reference the record from the groups table.

4_inserting_groups.png

After everything is ready issue a delete statement upon the groups table and make sure that all records in the students table were deleted.

5_deleting_all.png

All deleted rows can be found in the recycle bin that is opened by clicking Open Recycle Bin on the domain icon. This designer displays the number of deleted rows in each of the tables. Let’s view the deleted rows in the students table by selecting the corresponding table in the designer and clicking the Browse button.

6_recycle_bin.png

Recycle Bin Explorer allows viewing the fields of deleted records as well as the date and time of deletion and the user that performed that operation. Let’s restore one of the records in the students table by clicking on the Restore Rows button.

7_recycle_bin_explorer.png

If you click the Refresh button in the recycle bin designer at this moment you will find out that the record in the groups table was restored as well because it was referenced by the restored record in the students table.

8_recycle_bin_after_restoring.png

Let’s make sure that we can read the restored records.

9_reading_restored_rows.png

If you do not want to store deleted records you can disable the recycle bin all together. In order to do that unset the Domain has recycle bin enabled checkbox in the properties window of the current domain.

10_disabling_recycle_bin.png

After that the record that was not restored in the students table will become visible again.

10_reading_rows_with_no_recycle_bin.png

Now let’s delete all rows again.

11_deleting_all_with_no_recycle_bin.png

In this case the deletion process cannot be reverted because the deleted records will not end up in the recycle bin.

12_no_way_to_restore.png

Last edited Jul 28, 2012 at 4:42 AM by mapase, version 8

Comments

No comments yet.