-
February 27th, 2004, 03:06 AM
#16
The database though has strictly defined areas where it can search for referenced or referencing objects. C++ cannot, you can't search the whole memory or even stack for pointers. It would require every pointer to register in some global datastructure.
All the buzzt
CornedBee
-
February 27th, 2004, 03:21 AM
#17
Originally posted by CornedBee
Relational databases are a lot more specialized than a general-purpose programming language...
But referential integrity is imho a very general purpose thing. I dare to say that a lot of program crashes are caused by broken referential integrity (e.g. accessing a null-pointer where the program expects a pointer to an object). So shouldn't a programming language support this principle (open question to the void)?
Originally posted by CornedBee
The real problem is the lack of backreferencing.
Keeping a list of referencing objects in the object that is referenced is what I had in mind. But it is work I am not willing to put into my program, because in the end the program logic should ensure the referential integrity as well (i.e. the program at the beginning of this post has errors breaking it). So I would write a lot of code to protect my program from coding errors...
Originally posted by Sam Hobbs
Probably they are easy if you want them to be.
Is there actually a way to prevent an object from being deleted? (Option 1). I could of course provide a static function that would first check and then delete the object, but could I enforce that this function was used? Any ideas on that appreciated.
Originally posted by CornedBee
If something from A is deleted, it should delete the referenced value in C...
No. If something from C is deleted, it should delete all values from A referencing it.
And if the relationship is complex enough, wouldn't that lead to the possibility of emptying the entire database?
Depending on your database design, possibly. If you delete a customer from your database, you will automatically also delete all his phone numbers, all orders that he has made, all items that were part of these orders, all discounts that related to an item that was part of the order of that customer, ... Simple as that.
-
February 27th, 2004, 06:06 AM
#18
Keeping track of references is something that is done for instance in Java. There you simply cannot explicitly delete objects, the garbage collector takes care of this. I don't think it makes sense to both allow explicit deletion and then prevent it if there are still references to the object.
Use reference counting instead, like boost::shared_ptr. Of course this only works with objects on the heap.
All the buzzt
CornedBee
-
February 27th, 2004, 10:20 AM
#19
Those that say it can't be done provide opportunity for those of us that can.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|