SV: Nested db-objects

Sigurd Nes <[email protected]>
Newsgroups gmane.comp.web.phpgroupware.devel
Message-ID <[email protected]>
> From: Olivier Berger [[email protected]]
> Sent: 2008-05-22 13:35:48 CEST
> To: [email protected]
> Subject: Re: [phpGroupWare-developers] Nested db-objects
> 
> Le mercredi 21 mai 2008 à 20:02 +0200, Sigurd Nes a écrit :
> > Hi all,
> > 
> > I find it very useful to have the ability to have the choice of using nested 
> > db-objects.
> > 
> > Example:
> > When integrating with external systems - it is very convenient to start a 
> > transaction on system 1 - do some work (like sync) on system 2 - and if things 
> > went well do a commit on the result in system 1.
> > 
> 
> Sure.
> 
> Are there any test cases to verify that such frameworks are working as
> expected in phpgw ?

Her is one example on how I have used nested db-objects:
I have a configurable hierarchy of locations (read: estate/building/floor/room etc)
Within each level (which is represented by a set of tables) one can have custom fields of any type.
This function allows you to delete the bottom level and cleaning out the custom fields from the meta database in the process.

<code>
function delete($id)
{
	$this->init_process();
	$this->oProc->m_odb->transaction_begin();
	$this->db->transaction_begin();

	$table 		= 'fm_location_type';

	$this->db->query("SELECT max(id) as id FROM $table",__LINE__,__FILE__);
	$this->db->next_record();
	if($this->db->f('id') > $id)
	{
		$this->db->transaction_abort();
		$this->oProc->m_odb->transaction_abort();
		$receipt['error'][] = array('msg' => lang('please delete from the bottom'));
		$GLOBALS['phpgw']->session->appsession('receipt','property',$receipt);

		return $receipt;
	}

	$this->oProc->DropTable('fm_location' . $id);
	$this->oProc->DropTable('fm_location' . $id . '_category');
	$this->oProc->DropTable('fm_location' . $id . '_history');

	$attrib_table 	= 'phpgw_cust_attribute';
	$choice_table 	= 'phpgw_cust_choice';

	$this->db->query("DELETE FROM $attrib_table WHERE ...
	$this->db->query("DELETE FROM $choice_table WHERE ...
	$this->db->query("DELETE FROM $table WHERE id=" . (int)$id,__LINE__,__FILE__);

	if($this->db->transaction_commit()
	{
		$this->oProc->m_odb->transaction_commit();
	}
}
</code>

Regards

Sigurd

_______________________________________________
phpGroupWare-developers mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/phpgroupware-developers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.