delete cascade

Forum for posting problems using QxOrm library

delete cascade

Postby ruddy32 » Tue Jan 25, 2011 10:37 pm

Hello,
Is possible to use delete cascade? How?
Thanks
ruddy32
 

Re: delete cascade

Postby QxOrm admin » Wed Jan 26, 2011 8:37 am

Hi,

You can try to use QxOrm triggers, I have added new post in the FAQ of QxOrm web site to explain how it works :
http://www.qxorm.com/qxorm_en/faq.html#faq_130

And you can find a sample in the directory ./test/dll2/ with the class BaseClassTrigger (available from version QxOrm 1.1.4).

You have to use "onBeforeDelete" and/or "onAfterDelete" triggers to delete what you want...
QxOrm admin
 

Re: delete cascade

Postby ruddy32 » Wed Jan 26, 2011 3:20 pm

Does it mean that I can happened the "CASCADE" keyword into to SQL request before sending it to the postgres server?
Or do I have to delete depending objects manually?
ruddy32
 

Re: delete cascade

Postby QxOrm admin » Wed Jan 26, 2011 4:07 pm

No, you can't modify SQL request to append "CASCADE" keyword.

In your QxOrm trigger ("onBeforeDelete" and/or "onAfterDelete"), you have to delete your objects manually.
You can retrieve the current connexion to database with the parameter "qx::dao::detail::IxDao_Helper * dao" ===> "dao->database()" returns the current connexion (QSqlDatabase type).

Imagine you have a "onAfterDelete()" method in the "BaseClassTrigger" of the FAQ (http://www.qxorm.com/qxorm_en/faq.html#faq_130), you can write something like this :

Code: Select all
void BaseClassTrigger::onAfterDelete(qx::dao::detail::IxDao_Helper * dao)
{
   // If an error has been generated before this process
   if (dao->error().isValid()) { return; }

   // Retrieve current connexion to database
   QSqlDatabase connexion = dao->database();

   // Delete my object manually with the same connexion
   QSqlError error = qx::dao::delete_by_id(my_object, & connexion);

   // If an error occured : transfert error to dao parameter
   if (error.isValid()) { dao->updateError(error); }
}


---

Or another solution : I think you can define your "delete cascade" directly in your SGBD.
QxOrm admin
 

Re: delete cascade

Postby ruddy32 » Thu Jan 27, 2011 9:36 am

What do you think about adding a parameter in deleteById and deleteAll that would specified the cascade option? By defaut this option would be set to false.
ruddy32
 

Re: delete cascade

Postby QxOrm admin » Thu Jan 27, 2011 10:55 am

I think it is possible to add something like this :
qx::dao::delete_by_id_with_relation()
qx::dao::delete_all_with_relation()
qx::dao::delete_by_query_with_relation()


This would be similar to fetch, update, insert and save methods and the developper could specify each relation to delete.

If you have another idea, you can submit a patch and/or evolution at this address : contact@qxorm.com
QxOrm admin
 

Re: delete cascade

Postby Guest » Mon Jul 04, 2011 8:20 am

This would be fine.
Guest
 

Re: delete cascade

Postby QxOrm admin » Mon Jul 04, 2011 7:50 pm

Ok, I will try to include this feature in the next release...
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 4 guests

cron