$serializedData = $this->getCompressorChannel()->getCompressor()->decompressStream($compressedData);
// Unserialize it
- $dataArray = unserialize($serializedData);
+ $dataArray = json_decode($serializedData, TRUE);
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: Read ' . count($dataArray) . ' elements from database file ' . $fqfn . '.');
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataArray=' . print_r($dataArray, TRUE));
// Serialize and compress it
- $compressedData = $this->getCompressorChannel()->getCompressor()->compressStream(serialize($dataArray));
+ $compressedData = $this->getCompressorChannel()->getCompressor()->compressStream(json_encode($dataArray));
// Write data
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: Writing ' . strlen($compressedData) . ' bytes ...');
// Get the file contents
try {
$infoArray = $this->getDataArrayFromFile($fqfn);
- } catch (FileIoException $e) {
+ } catch (FileNotFoundException $e) {
// Not found, so ignore it here
}
* @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');
$this->tableInfo[$tableName]['last_updated'] = time();
// Write the data to the file
- $this->writeDataArrayToFqfn($fqfn, $this->tableInfo[$tableName]);
+ $this->writeDataArrayToFqfn($fqfn, $this->tableInfo[$dataSetInstance->getTableName()]);
}
/**
$this->setLastException($e);
// Throw an SQL exception
- throw new SqlException(array($this, sprintf("Cannot write data to table '%s', is the table created?", $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY);
+ throw new SqlException(array($this, sprintf('Cannot write data to table '%s', is the table created? Exception: %s, message:%s', $dataSetInstance->getTableName(), $e->__toString(), $e->getMessage()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY);
}
}
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: data[' . gettype($data) . ']='.print_r($data, TRUE));
return $data;
}
+
+ /**
+ * Counts total rows of given table
+ *
+ * @param $tableName Table name
+ * @return $count Total rows of given table
+ */
+ public function countTotalRows($tableName) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: tableName=' . $tableName . ' - CALLED!');
+
+ // Create full path name
+ $pathName = $this->getConfigInstance()->getConfigEntry('local_db_path') . $tableName . '/';
+
+ // Try all the requests
+ try {
+ // Get a file pointer instance
+ $directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($pathName));
+
+ // Initialize counter
+ $count = 0;
+
+ // Read the directory with some exceptions
+ while ($dataFile = $directoryInstance->readDirectoryExcept(array('.htaccess', 'info.' . $this->getFileExtension()))) {
+ // Does the extension match?
+ if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',getFileExtension()=' . $this->getFileExtension() . ' - SKIPPED!');
+ // Skip this file!
+ continue;
+ } // END - if
+
+ // Count this row up
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: dataFile=' . $dataFile . ',getFileExtension()=' . $this->getFileExtension() . ' - COUNTED!');
+ $count++;
+ } // END - while
+ } catch (FrameworkException $e) {
+ // Catch all exceptions and store them in last error
+ $this->setLastException($e);
+
+ // Throw an SQL exception
+ throw new SqlException(array($this, sprintf('Cannot count on table '%s', is the table created?', $dataSetInstance->getTableName()), self::DB_CODE_TABLE_NOT_FOUND), self::EXCEPTION_SQL_QUERY);
+ }
+
+ // Return count
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE: tableName=' . $tableName . ',count=' . $count . ' - EXIT!');
+ return $count;
+ }
}
// [EOF]