/**
* Does the specified offset exist in cache?
*
- * @param $offset The offset we are looking for
- * @return $exists Whether the offset exists
+ * @param $offset The offset we are looking for
+ * @param $arrayElement If type is array, then this element must be found
+ * @param $minimumCount If array element is found then this count must at least match
+ * @return $exists Whether the offset exists
*/
- function offsetExists($offset);
+ function offsetExists($offset, $arrayElement = NULL, $minimumCount = 0);
/**
* Setter for cache offset
/**
* Does the specified offset exist in cache?
*
- * @param $offset The offset we are looking for
- * @return $exists Whether the offset exists
+ * @param $offset The offset we are looking for
+ * @param $arrayElement If type is array, then this element must be found
+ * @param $minimumCount If array element is found then this count must at least match
+ * @return $exists Whether the offset exists
*/
- public function offsetExists ($offset) {
+ public function offsetExists ($offset, $arrayElement = NULL, $minimumCount = 0) {
+ // Is it there?
$exists = $this->dataCache->offsetExists($offset);
+
+ // So look for array element?
+ if (($exists === TRUE) && (!is_null($arrayElement))) {
+ // Get it
+ $array = $this->offetget($offset);
+
+ // Is it an array and element is found?
+ if ((is_array($array)) && (isset($array[$arrayElement]))) {
+ // Is an array and element is found, so check count
+ $exists = (count($array[$arrayElement]) >= $minimumCount);
+ } else {
+ // Not found
+ $exists = FALSE;
+ }
+ } // END - if
+
+ // Return status
return $exists;
}
$criteriaKey = $this->convertDashesToUnderscores($criteriaKey);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($criteriaType) . '(' . $this->__toString() . ')-CRITERIA[' . __LINE__ . ']: criteriaKey=' . $criteriaKey . ',criteriaValue=' . $criteriaValue);
// Is it already there?
if ($this->isKeySet($criteriaType, $criteriaKey)) {
$valueArray = explode($separator, $value);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: key=' . $key . ',value[' . gettype($value) . ']=' . $value . ' - ENTERED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: key=' . $key . ',value[' . gettype($value) . ']=' . $value . ' - ENTERED!');
// Get 'default' search value
$searchDefault = $this->getCriteriaElemnent($key);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault);
// 'default' check
$isMatching = (((($searchDefault !== FALSE) && ($searchDefault == $value)) || ((is_null($searchDefault)) && (is_null($value)))) || ($searchDefault === FALSE));
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault . ',isMatching=' . intval($isMatching));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaElement(' . $key . ')[' . gettype($searchDefault) . ']=' . $searchDefault . ',isMatching=' . intval($isMatching));
// Get 'choice' search value (can be NULL or $separator-separated string)
$searchChoice = $this->getCriteriaChoiceElemnent($key);
assert(($searchChoice === FALSE) || (is_array($searchChoice)));
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[' . gettype($searchChoice) . ']=' . print_r($searchChoice, TRUE));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[' . gettype($searchChoice) . ']=' . print_r($searchChoice, TRUE));
// 'choice' check
if ((is_array($searchChoice)) && (count($valueArray) == 1)) {
$isMatching = ((($isMatching === TRUE) || (($searchDefault === FALSE) && (!is_null($value)))) && (in_array($value, $searchChoice)));
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',value[' . gettype($value) . ']=' . $value . ',isMatching=' . intval($isMatching) . ' - SINGLE-MATCH');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',value[' . gettype($value) . ']=' . $value . ',isMatching=' . intval($isMatching) . ' - SINGLE-MATCH');
} elseif ((is_array($searchChoice)) && (count($valueArray) > 1)) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',valueArray()=' . count($valueArray) . ',isMatching=' . intval($isMatching));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',valueArray()=' . count($valueArray) . ',isMatching=' . intval($isMatching));
// $value is choice-search value, so check all entries
$isMatching = (($isMatching === TRUE) || (($searchDefault === FALSE) && (!is_null($value))));
$idx = 0;
foreach ($valueArray as $idx => $match) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: match=' . $match . ',count(searchChoice)=' . count($searchChoice));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: match=' . $match . ',count(searchChoice)=' . count($searchChoice));
// Is it found? (one is okay)
$isMatching = (($isMatching === TRUE) && (in_array($match, $searchChoice)));
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: match=' . $match . ',isMatching=' . intval($isMatching));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: match=' . $match . ',isMatching=' . intval($isMatching));
} // END - foreach
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',valueArray()=' . count($valueArray) . ',idx=' . $idx . ',isMatching=' . intval($isMatching) . ' - CHOICE-MATCH');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',valueArray()=' . count($valueArray) . ',idx=' . $idx . ',isMatching=' . intval($isMatching) . ' - CHOICE-MATCH');
} else {
// Choice-match is FALSE
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',value[' . gettype($value) . ']=' . $value . ',isMatching=' . intval($isMatching) . ' - FALSE-MATCH');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',value[' . gettype($value) . ']=' . $value . ',isMatching=' . intval($isMatching) . ' - FALSE-MATCH');
}
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',isMatching=' . intval($isMatching));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaChoiceElement(' . $key . ')[]=' . gettype($searchChoice) . ',isMatching=' . intval($isMatching));
// Get 'exclude' search value
$searchExclude = $this->getCriteriaExcludeElemnent($key);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaExcludeElement(' . $key . ')[' . gettype($searchExclude) . ']=' . $searchExclude);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: getCriteriaExcludeElement(' . $key . ')[' . gettype($searchExclude) . ']=' . $searchExclude);
// 'exclude' check
$isMatching = (
);
// Return result
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: key=' . $key . ',value[' . gettype($value) . ']=' . $value . ',isMatching=' . intval($isMatching) . ' - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SEARCH-CRITERIA[' . __LINE__ . ']: key=' . $key . ',value[' . gettype($value) . ']=' . $value . ',isMatching=' . intval($isMatching) . ' - EXIT!');
return $isMatching;
}
}
$cacheKey = $this->getCacheKeyByCriteria($criteriaInstance, $onlyKeys);
// Does this key exists in cache?
- if ($this->cacheInstance->offsetExists($cacheKey)) {
+ if ($this->cacheInstance->offsetExists($cacheKey, BaseDatabaseBackend::RESULT_INDEX_ROWS, 1)) {
// Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Cache used for cacheKey=' . $cacheKey);
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Cache used for cacheKey=' . $cacheKey . ':' . print_r($this->cacheInstance->offsetGet($cacheKey), TRUE));
// Then use this result
$result = $this->cacheInstance->offsetGet($cacheKey);
$this->writeDataArrayToFqfn($fqfn, $this->tableInfo[$dataSetInstance->getTableName()]);
}
+ /**
+ * Updates the table info file from given dataset instance
+ *
+ * @param $dataSetInstance An instance of a database set class
+ * @return void
+ */
+ private function updateTableInfoFile (StoreableCriteria $dataSetInstance) {
+ // "Cache" table name
+ $tableName = $dataSetInstance->getTableName();
+
+ // Create FQFN for creating the table information file
+ $fqfn = $this->generateFqfnFromDataSet($dataSetInstance, 'info');
+
+ // Get the data out from dataset in a local array
+ $this->tableInfo[$tableName]['primary'] = $dataSetInstance->getPrimaryKey();
+ $this->tableInfo[$tableName]['last_updated'] = time();
+
+ // Write the data to the file
+ $this->writeDataArrayToFqfn($fqfn, $this->tableInfo[$tableName]);
+ }
+
/**
* Updates the primary key information or creates the table info file if not found
*
* @return void
*/
private function updatePrimaryKey (StoreableCriteria $dataSetInstance) {
+ // "Cache" table name
+ $tableName = $dataSetInstance->getTableName();
+
// Get the information array from lower method
$infoArray = $this->getContentsFromTableInfoFile($dataSetInstance);
// Is the primary key there?
- if (!isset($this->tableInfo['primary'])) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: tableInfo=' . print_r($this->tableInfo, TRUE));
+ if (!isset($this->tableInfo[$tableName]['primary'])) {
// Then create the info file
$this->createTableInfoFile($dataSetInstance);
- } elseif (($this->getConfigInstance()->getConfigEntry('db_update_primary_forced') == 'Y') && ($dataSetInstance->getPrimaryKey() != $this->tableInfo['primary'])) {
+ } elseif (($this->getConfigInstance()->getConfigEntry('db_update_primary_forced') == 'Y') && ($dataSetInstance->getPrimaryKey() != $this->tableInfo[$tableName]['primary'])) {
// Set the array element
- $this->tableInfo[$dataSetInstance->getTableName()]['primary'] = $dataSetInstance->getPrimaryKey();
+ $this->tableInfo[$tableName]['primary'] = $dataSetInstance->getPrimaryKey();
// Update the entry
$this->updateTableInfoFile($dataSetInstance);
// Read the file
$dataArray = $this->getDataArrayFromFile($pathName . $dataFile);
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',dataArray='.print_r($dataArray, TRUE));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',dataArray='.print_r($dataArray, TRUE));
// Is this an array?
if (is_array($dataArray)) {
// Found one entry?
$isFound = (($isFound === TRUE) && ($searchInstance->isCriteriaMatching($key, $value)));
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: key=' . $key . ',value=' . $value . ',isFound=' . intval($isFound));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: key=' . $key . ',value=' . $value . ',isFound=' . intval($isFound));
} // END - foreach
// Is all found?
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: isFound=' . intval($isFound) . ',limitFound=' . $limitFound . ',limit=' . $searchInstance->getLimit());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: isFound=' . intval($isFound) . ',limitFound=' . $limitFound . ',limit=' . $searchInstance->getLimit());
if ($isFound === TRUE) {
// Shall we skip this entry?
if ($searchInstance->getSkip() > 0) {
foreach ($searchArray as $searchKey => $searchValue) {
// Make sure the value is not bool again
assert(!is_bool($searchValue));
+ assert($searchKey != $this->indexKey);
// Debug message + add/update it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: criteriaKey=' . $searchKey . ',criteriaValue=' . $searchValue);
return $isValid;
}
+ /**
+ * Returns count of entries
+ *
+ * @return $isValid Whether the next/rewind entry is valid
+ */
+ public function count () {
+ // Return it
+ return count($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS]);
+ }
+
/**
* Determines whether the status of the query was fine (BaseDatabaseBackend::RESULT_OKAY)
*