]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/database/backend/class_CachedLocalFileDatabase.php
Added some new stuff.
[core.git] / inc / classes / main / database / backend / class_CachedLocalFileDatabase.php
index 1b25719c4618423638686c1fa086cefc0227cf76..4e1a6a6a01076d0f9f962202c30305b88dea4ed6 100644 (file)
@@ -583,7 +583,7 @@ class CachedLocalFileDatabase extends BaseDatabaseBackend implements DatabaseBac
                        $this->setLastException($e);
 
                        // Throw an SQL exception
                        $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;
        }
                //* 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]
 }
 
 // [EOF]