CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    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

  2. #17
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401
    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.

  3. #18
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    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

  4. #19
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Those that say it can't be done provide opportunity for those of us that can.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured