高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】deleted entities
deleted entities
deleted entities
hello,
i have one question.
if i delete an entity from oddbdatabase, like this:
oddbentityptr pent = ptr->safeopenobject(oddb::kforwrite);
pent->erase();
i have noticed, that i can get the deleted entity later:
oddbentityptr pent = ptr->safeopenobject(oddb::kforwrite);
when is this entity realy removed from database. is it safe to reference such entity at any time? or is this entity really deleted from oddbdatabase before file is created.
can i read the attributes of deleted entities at any time, or it is possible, that
entity is really erased, and ptr->safeopenobject() will raise an exception?
best regards, tomaz
hi tomaz,
to delete an entity from the database,
oddbentityptr pent = ptr->safeopenobject(oddb::kforwrite);
pent->erase();
is the only way to do it. be aware that this is functionality of oddbobject, so you can delete any other database object in this way, and not only entities.
however, no destructor of the c++ object is called here, and the data of the entity is not erased. only an erased flag internally is set to true. the reason for this is very simple - if you delete the c++ object, no undo/redo could be performed afterwards.
so for, when the database tables or dictionaries are iterated, usually the erased objects are skipped. also the erased entities are not displayed (ignored during regen operation).
unless an undo operation is performed and the object turns back its erased flag to false.
please note the arguments when you create new iterator and its members - for example see the oddbsymboltableiterator class. you usually call start() member function to start the iteration - and the second argument of the start() member is a bool flag skipdeleted - if you set to false, then you will have the erased objects also iterated.
if you call this:
oddbentityptr pent = ptr->safeopenobject(oddb::kforwrite);
of an erased entity, an exception "object already erased" or similar would be thrown. i don't know why you succeeded in opening the erased object again with no exception by calling this way.
to open an erased object, you should call
id.safeopenobject(oddb::kforread (or oddb::kforwrite), true), because the second flag of this function indicates whether an erased object is allowed to be opened.
the thus erased object is removed from the database only when the database is closed (i.e. destroyed). when you open it again, the object should not be there. (but once i had forgotten an object id of erased entity, and after re-opening the database, the exception was object was permanently erased, which was a very bad bug).
so you can read the attributes of an erased entity by opening it with safeopenobject(read or write, true), but i don't know whether you should really need this. when you iterate entities or objects in a standard way and leave the iterator arguments to their default values, you'll get no erased objects.
hope this helps you.
regards
chudomir
hello chudo,
this answer really helps me a lot.
and you are right, i got the exception when i called
oddbentityptr pent = ptr->safeopenobject(oddb::kforwrite);
on erased entity.
thanks for your help
best regards, tomaz
undo recording can be turned off (oddbhostappservices::newundocontroller() returns null or undo is disabled at database or at object level).
in such case objects get erased permanently and memory is freed. but this was temporary disabled in 1.10
sergey slezkin
|