X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fdatabase%2Fbackend%2Fclass_CachedLocalFileDatabase.php;fp=inc%2Fclasses%2Fmain%2Fdatabase%2Fbackend%2Fclass_CachedLocalFileDatabase.php;h=4e1a6a6a01076d0f9f962202c30305b88dea4ed6;hp=1b25719c4618423638686c1fa086cefc0227cf76;hb=70a00fd84fd8d07e075a3479d3475e1a8f36a772;hpb=ca6e07fa5a4112a968891e3331a771fea7cebd4d diff --git a/inc/classes/main/database/backend/class_CachedLocalFileDatabase.php b/inc/classes/main/database/backend/class_CachedLocalFileDatabase.php index 1b25719c..4e1a6a6a 100644 --- a/inc/classes/main/database/backend/class_CachedLocalFileDatabase.php +++ b/inc/classes/main/database/backend/class_CachedLocalFileDatabase.php @@ -583,7 +583,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac $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?', $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY); } } @@ -623,6 +623,53 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac //* 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]