From 3fbfad865619c01d2a89b40ef955934999d47a2d Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sat, 23 Mar 2013 02:50:09 +0100 Subject: [PATCH] Bypass cache on data reload, and fix a bug where a difference between column name and variable name would cause the clearing of old data in an object to fail --- class.databaserecord.php | 15 ++++++++------- include.mysql.php | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/class.databaserecord.php b/class.databaserecord.php index 20f028f..35db37e 100644 --- a/class.databaserecord.php +++ b/class.databaserecord.php @@ -38,7 +38,7 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass die("No class map was specified. Refer to the CPHP manual for instructions."); } - $this->ConstructDataset($uDataSource, $defaultable); + $this->ConstructDataset($uDataSource); $this->EventConstructed(); } @@ -77,7 +77,7 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass public function RefreshData() { $this->PurgeCache(); - $this->ConstructDataset($this->sId); + $this->ConstructDataset($this->sId, 0); if($this->autoloading === true) { @@ -89,17 +89,17 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass { foreach($this->prototype as $type => $dataset) { - foreach($dataset as $field) + foreach($dataset as $key => $field) { - $variable_name_safe = "s" . $field; - $variable_name_unsafe = "u" . $field; + $variable_name_safe = "s" . $key; + $variable_name_unsafe = "u" . $key; unset($this->$variable_name_safe); unset($this->$variable_name_unsafe); } } } - public function ConstructDataset($uDataSource, $defaultable = null) + public function ConstructDataset($uDataSource, $expiry = -1) { global $database; @@ -112,9 +112,10 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass if(!empty($this->fill_query)) { $this->sId = (is_numeric($uDataSource)) ? $uDataSource : 0; + $expiry = ($expiry == -1) ? $this->query_cache : $expiry; /* Use PDO to fetch the object from the database. */ - if($result = $database->CachedQuery($this->fill_query, array(":Id" => $this->sId), $this->query_cache)) + if($result = $database->CachedQuery($this->fill_query, array(":Id" => $this->sId), $expiry)) { $uDataSource = $result->data[0]; } diff --git a/include.mysql.php b/include.mysql.php index b5939a9..e725578 100644 --- a/include.mysql.php +++ b/include.mysql.php @@ -108,7 +108,7 @@ class CachedPDO extends PDO throw new DatabaseException("The query failed.", 0, null, array('query' => $query, 'parameters' => $parameters)); } } - + return $return_object; }