// Get a new instance
$resultInstance = new CachedDatabaseResult();
- // Set the result array
+ // Set the result array and reset current position
$resultInstance->setResultArray($resultArray);
+ $resultInstance->resetCurrentPosition();
// Set affected rows
$resultInstance->setAffectedRows(count($resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS]));
*/
public function valid () {
// Check if all is fine ...
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-DATABASE-RESULT: this->currentPos=' . $this->currentPos);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-DATABASE-RESULT: this->currentPos=%d - CALLED!', $this->currentPos));
$isValid = ($this->ifStatusIsOkay() && isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos]) && isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][0]));
// Return the result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-DATABASE-RESULT: isValid=%d - EXIT!', intval($isValid)));
return $isValid;
}
* @return $isValid Whether the next/rewind entry is valid
*/
public function count () {
+ // Count rows
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-DATABASE-RESULT: CALLED!');
+ $count = count($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS]);
+
// Return it
- return count($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS]);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-DATABASE-RESULT: count=%d - EXIT!', $count));
+ return $count;
}
/**
* @return $ifStatusOkay Whether the status of the query was okay
*/
public function ifStatusIsOkay () {
+ // Check all conditions
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-DATABASE-RESULT: this->currentPos=%d - CALLED!', $this->currentPos));
$ifStatusOkay = (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS]) && $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS] === BaseDatabaseBackend::RESULT_OKAY);
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-DATABASE-RESULT: ifStatusOkay=' . intval($ifStatusOkay));
+
+ // Return status
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-DATABASE-RESULT: ifStatusOkay=%s - EXIT!', intval($ifStatusOkay)));
return $ifStatusOkay;
}
* @return $currentPos Key from iterator
*/
public function key () {
+ // Return current array position
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-DATABASE-RESULT: this->currentPos=%d - CALLED!', $this->currentPos));
return $this->currentPos;
}
* @return void
*/
public function rewind () {
- $this->currentPos = 0;
+ // Reset both current array position and current row
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-DATABASE-RESULT: this->currentPos=%d - CALLED!', $this->currentPos));
+ $this->resetCurrentPosition();
$this->currentRow = [];
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-DATABASE-RESULT: EXIT!');
+ }
+
+ /**
+ * Resets current array position to 0 if at least one record is there or -1
+ * if no record is there.
+ *
+ * @return void
+ */
+ private function resetCurrentPosition () {
+ // Reset position
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-DATABASE-RESULT: CALLED!');
+ $this->currentPos = ($this->count() > 0 ? 0 : -1);
+
+ // Trace message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-DATABASE-RESULT: EXIT!');
}
/**
* @todo 0% done
*/
public function searchEntry (LocalSearchCriteria $criteriaInstance) {
- $this->debugBackTrace('[' . '[' . __METHOD__ . ':' . __LINE__ . ']: Unfinished!');
+ // Unfinished code
+ $this->debugBackTrace(sprintf('[%s:%d]: criteriaInstance=%s', __METHOD__, __LINE__, print_r($criteriaInstance, TRUE)));
}
/**
// Walk only through out-dated columns
foreach ($this->outDated as $key => $dummy) {
// Does this key exist?
- //* DEBUG: */ echo "outDated: {$key}<br />\n";
if ($this->find($key)) {
// Then update it
$criteriaInstance->addCriteria($key, $this->getFoundValue());
* @param $key The key we shall find
* @return $found Whether the key was found or not
*/
- public function find ($key) {
+ public function find (string $key) {
// By default nothing is found
$found = false;
* @return void
* @todo Find a caching way without modifying the result array
*/
- public function solveResultIndex ($databaseColumn, DatabaseFrontend $frontendInstance, array $callBack) {
+ public function solveResultIndex (string $databaseColumn, DatabaseFrontend $frontendInstance, array $callBack) {
// By default nothing is found
$indexValue = 0;