How to: Variables Variables - used in Object archiving example

thread: 3 messages  |  last: about 5 years ago  |  started: monday, february 11, 2008, 5:16 pm pst


#1  |  tronics (VIE, AUT) Austria
Monday, February 11, 2008, 5:16 PM PST

This is some working code for archiving from one Table into another.
This is for archiving, not for cloning.

I'm using Variables Variables to step through different qcodo lstObjects and dump all their information from the database directly into an archive table with mysql features.

This workes fast and convenient.

The archive table has an additional primary field and a key field to the original table. This is of course for the relation between those tables.

The keyfield identifies the archive table (can also be uniquely identified by only writing the first part of the key, but I use a concatinated string for the fun of it and it works well).

$this->arrPersonen = array("lstZugehoerigkeitObjektObject", 
"lstZugehoerigkeitAbgeberObject","lstZugehoerigkeitKundeObject","lstZugehoerigkeitZubringerAbgeberObject","lstZugehoerigkeitZubringerKundeObject",


$objDatabase = QApplication::$Database[1];
for ($r=0;$r<sizeof($this->arrPersonen);$r++)
{
if ($this->{$this->arrPersonen[$r]}->SelectedValue!=NULL)
{                                        
$strQuery = "SELECT * FROM `PersonenArchiv` WHERE PersonenArchiv.key='".$this->lblId->Text."X".$this->{$this->arrPersonen[$r]}->SelectedValue."'";    
$objDbResult = $objDatabase->Query($strQuery);
if ($objDbResult->CountRows()<1)
{
$strQuery = "INSERT INTO `PersonenArchiv` SELECT '','".$this->lblId->Text."X".$this->{$this->arrPersonen[$r]}->SelectedValue."',Personen.* FROM `Personen` WHERE Personen.id='".$this->{$this->arrPersonen[$r]}->SelectedValue."'";        
$objDbResult = $objDatabase->Query($strQuery);         
}
}
}

So using an attribute with variables variables works like this:

$this->{$this->arrPersonen[$r]}->SelectedValue

All the Best,
tronics

#2  |  tronics (VIE, AUT) Austria
Monday, February 11, 2008, 5:23 PM PST

Code above worked much better then serializing the object in a text field
(found on the forum that text is better then blob).

When getting out the informations again, I only have to change the ::Load.
All the row Information and the way it can be stepped through (fetchRow) makes all the non-archive code that is already there reusable to a high degree.

Best,
tronics

#3  |  tronics (VIE, AUT) Austria
Wednesday, February 13, 2008, 5:51 PM PST

And here how to concat an attributes Name with variables variables:

$this->{"txt".$personType."rent"}->Text=$percent;

This might be also interesting:
http://qcodo.com/forums/topic.php/1311/1//?strSearch=variables



Copyright © 2005 - 2013, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.