use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A set of data storeable in databases
*
*
* @param $tableName Name of the table
* @return $criteriaInstance An instance of this criteria
+ * @throws InvalidArgumentException If a parameter is not valid
*/
public static final function createDataSetCriteria (string $tableName) {
+ // Validate parameter
+ if (empty($tableName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "tableName" is empty');
+ }
+
// Get a new instance
$criteriaInstance = new DataSetCriteria();
// Constants for exceptions
const EXCEPTION_SQL_QUERY = 0x140;
- // Result array indexes
- const RESULT_INDEX_ROWS = 'rows';
- const RESULT_INDEX_STATUS = 'status';
- const RESULT_INDEX_EXCEPTION = 'exception';
-
// Constants for MySQL backward-compatiblity (PLEASE FIX THEM!)
const DB_CODE_TABLE_MISSING = 0x100;
const DB_CODE_TABLE_UNWRITEABLE = 0x101;
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
use Org\Mxchange\CoreFramework\Generic\FrameworkException;
+use Org\Mxchange\CoreFramework\Result\Database\BaseDatabaseResult;
use Org\Mxchange\CoreFramework\Traits\Compressor\Channel\CompressorChannelTrait;
use Org\Mxchange\CoreFramework\Traits\Handler\Io\IoHandlerTrait;
// Import SPL stuff
+use \InvalidArgumentException;
use \SplFileInfo;
/**
* @param $tableName Name of the database table
* @param $searchInstance Local search criteria class
* @return $resultData Result data of the query
+ * @throws InvalidArgumentException If a parameter is not valid
* @throws UnsupportedCriteriaException If the criteria is unsupported
* @throws SqlException If an 'SQL error' occurs
*/
public function querySelect (string $tableName, LocalSearchCriteria $searchInstance) {
- // The result is null by any errors
+ // Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: tableName=%s,searchInstance=%s - CALLED!', $tableName, $searchInstance->__toString()));
+ if (empty($tableName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "tableName" is empty');
+ }
+
+ // The result is null by any errors
$resultData = NULL;
// Create full path name
$directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($pathName));
// Initialize the result data, this need to be rewritten e.g. if a local file cannot be read
- $resultData = array(
- BaseDatabaseBackend::RESULT_INDEX_STATUS => self::RESULT_OKAY,
- BaseDatabaseBackend::RESULT_INDEX_ROWS => []
- );
+ $resultData = [
+ BaseDatabaseResult::RESULT_NAME_STATUS => self::RESULT_OKAY,
+ BaseDatabaseResult::RESULT_NAME_ROWS => []
+ ];
// Initialize limit/skip
$limitFound = 0;
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: Skipping fileInfoInstance->filename=%s ...', $fileInfoInstance->getFilename()));
$directoryInstance->getDirectoryIteratorInstance()->next();
continue;
- } // END - if
+ }
// Read the file
$dataArray = $this->getDataArrayFromFile($fileInfoInstance);
// Found one entry?
$isFound = (($isFound === true) && ($searchInstance->isCriteriaMatching($key, $value)));
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: key=%s,value[%s]=%s,isFound=%s', $key, gettype($value), $value, intval($isFound)));
- } // END - foreach
+ }
// Is all found?
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: isFound=%d,limitFound=%d,limit=%d', intval($isFound), $limitFound, $searchInstance->getLimit()));
// Skip this entry
$skipFound++;
break;
- } // END - if
- } // END - if
+ }
+ }
// Set id number
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: Setting dataArray[%s]=%d', $this->getIndexKey(), $idx));
$dataArray[$this->getIndexKey()] = $idx;
// Entry found!
- array_push($resultData[BaseDatabaseBackend::RESULT_INDEX_ROWS], $dataArray);
+ array_push($resultData[BaseDatabaseResult::RESULT_NAME_ROWS], $dataArray);
// Count found entries up
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: resultData[%s]()=%d', BaseDatabaseBackend::RESULT_INDEX_ROWS, count($resultData[BaseDatabaseBackend::RESULT_INDEX_ROWS])));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-LFDB: resultData[%s]()=%d', BaseDatabaseResult::RESULT_NAME_ROWS, count($resultData[BaseDatabaseResult::RESULT_NAME_ROWS])));
$limitFound++;
- } // END - if
+ }
} else {
// Throw an exception here
throw new SqlException(array($this, sprintf('File '%s' contains invalid data.', $fileInfoInstance->getPathname()), self::DB_CODE_DATA_FILE_CORRUPT), self::EXCEPTION_SQL_QUERY);
// Advance to next entry
$directoryInstance->getDirectoryIteratorInstance()->next();
- } // END - while
+ }
// Close directory and throw the instance away
$directoryInstance->closeDirectory();
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance.extension=' . $fileInfoInstance->getExtension() . ',getFileExtension()=' . $this->getFileExtension() . ' - SKIPPED!');
$directoryInstance->getDirectoryIteratorInstance()->next();
continue;
- } // END - if
+ }
// Open this file for reading
$dataArray = $this->getDataArrayFromFile($fileInfoInstance);
// Found one entry?
$isFound = (($isFound === true) && ($searchInstance->isCriteriaMatching($key, $value)));
- } // END - foreach
+ }
// Is all found?
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: isFound=' . intval($isFound));
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Found entry, but skipping ...');
$skipFound++;
break;
- } // END - if
- } // END - if
+ }
+ }
// Entry found, so update it
foreach ($searchArray as $searchKey => $searchValue) {
// Debug message + add/update it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: criteriaKey=' . $searchKey . ',criteriaValue=' . $searchValue);
$dataArray[$searchKey] = $searchValue;
- } // END - foreach
+ }
// Write the data to a local file
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: Writing data[]=' . count($dataArray) . ' to ' . $fileInfoInstance->getPathname() . ' ...');
// Count found entries up
$limitFound++;
- } // END - if
- } // END - if
+ }
+ }
// Advance to next entry
$directoryInstance->getDirectoryIteratorInstance()->next();
- } // END - while
+ }
// Close the file pointer
$directoryInstance->closeDirectory();
*
* @param $tableName Name of the table we need the primary key from
* @return $primaryKey Primary key column of the given table
+ * @throws InvalidArgumentException If a parameter is not valid
* @todo Rename method to getPrimaryKeyFromTableInfo()
*/
public function getPrimaryKeyOfTable (string $tableName) {
+ // Validate parameter
+ if (empty($tableName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "tableName" is empty');
+ }
+
// Default key is null
$primaryKey = NULL;
if (isset($this->tableInfo[$tableName])) {
// Then return the primary key
$primaryKey = $this->tableInfo[$tableName]['primary'];
- } // END - if
+ }
// Return the column
return $primaryKey;
*
* @param $tableName Table name
* @return $count Total rows of given table
+ * @throws InvalidArgumentException If a parameter is not valid
*/
public function countTotalRows (string $tableName) {
+ // Validate parameter
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: tableName=' . $tableName . ' - CALLED!');
+ if (empty($tableName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "tableName" is empty');
+ }
+
// Create full path name
$pathName = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('local_database_path') . $tableName . DIRECTORY_SEPARATOR;
// Try all the requests
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: pathName=' . $pathName);
try {
// Get a file pointer instance
$directoryInstance = ObjectFactory::createObjectByConfiguredName('directory_class', array($pathName));
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance.extension=' . $fileInfoInstance->getExtension() . ',getFileExtension()=' . $this->getFileExtension() . ' - SKIPPED!');
// Skip this file!
continue;
- } // END - if
+ }
// Count this row up
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-LFDB: fileInfoInstance.pathname=' . $fileInfoInstance->getPathname() . ',getFileExtension()=' . $this->getFileExtension() . ' - COUNTED!');
$count++;
- } // END - while
+ }
} catch (FrameworkException $e) {
// Catch all exceptions and store them in last error
$this->setLastException($e);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BaseDatabaseResult extends BaseFrameworkSystem {
+ // Result array names
+ const RESULT_NAME_ROWS = 'rows';
+ const RESULT_NAME_STATUS = 'status';
+ const RESULT_NAME_EXCEPTION = 'exception';
+
/**
* Update criteria instance
*/
use Org\Mxchange\CoreFramework\Database\Backend\BaseDatabaseBackend;
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Result\Database\BaseDatabaseResult;
use Org\Mxchange\CoreFramework\Traits\Cache\CacheableTrait;
/**
// Does this key exists in cache?
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FRONTEND: cacheKey[%s]=%s', gettype($cacheKey), $cacheKey));
- if ((FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->getCacheInstance()->offsetExists($cacheKey, BaseDatabaseBackend::RESULT_INDEX_ROWS, 1))) {
+ if ((FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->getCacheInstance()->offsetExists($cacheKey, BaseDatabaseResult::RESULT_NAME_ROWS, 1))) {
// Then use this result
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FRONTEND: Cache used for cacheKey=%s', $cacheKey));
$result = $this->getCacheInstance()->offsetGet($cacheKey);
} else {
// This invalid result must be wrapped
$result = array(
- BaseDatabaseBackend::RESULT_INDEX_STATUS => 'invalid',
- BaseDatabaseBackend::RESULT_INDEX_EXCEPTION => FrameworkBootstrap::getDatabaseInstance()->getLastException()
+ BaseDatabaseResult::RESULT_NAME_STATUS => 'invalid',
+ BaseDatabaseResult::RESULT_NAME_EXCEPTION => FrameworkBootstrap::getDatabaseInstance()->getLastException()
);
}
}
// Create an instance of a CachedDatabaseResult class with the given result
// @TODO Minor: Update above comment to e.g. BaseDatabaseResult
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FRONTEND: result[%s]=%s,result[%s]?=%d,result[%s]?=%d', BaseDatabaseBackend::RESULT_INDEX_STATUS, $result[BaseDatabaseBackend::RESULT_INDEX_STATUS], BaseDatabaseBackend::RESULT_INDEX_ROWS, isset($result[BaseDatabaseBackend::RESULT_INDEX_ROWS]), BaseDatabaseBackend::RESULT_INDEX_EXCEPTION, isset($result[BaseDatabaseBackend::RESULT_INDEX_EXCEPTION])));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FRONTEND: result[%s]=%s,result[%s]?=%d,result[%s]?=%d', BaseDatabaseResult::RESULT_NAME_STATUS, $result[BaseDatabaseResult::RESULT_NAME_STATUS], BaseDatabaseResult::RESULT_NAME_ROWS, isset($result[BaseDatabaseResult::RESULT_NAME_ROWS]), BaseDatabaseResult::RESULT_NAME_EXCEPTION, isset($result[BaseDatabaseResult::RESULT_NAME_EXCEPTION])));
$resultInstance = ObjectFactory::createObjectByConfiguredName('database_result_class', array($result));
// And return the instance
use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
use Org\Mxchange\CoreFramework\Database\Frontend\DatabaseFrontend;
use Org\Mxchange\CoreFramework\Database\Backend\BaseDatabaseBackend;
+use Org\Mxchange\CoreFramework\Result\Database\BaseDatabaseResult;
use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
use Org\Mxchange\CoreFramework\Result\Update\UpdateableResult;
if (count($resultArray) == 0) {
// Cannot be empty
throw new InvalidArgumentException('Array "resultArray" cannot be empty.');
- } elseif (!array_key_exists(BaseDatabaseBackend::RESULT_INDEX_ROWS, $resultArray)) {
+ } elseif (!array_key_exists(BaseDatabaseResult::RESULT_NAME_ROWS, $resultArray)) {
// Yes, then abort here
- throw new InvalidArgumentException(sprintf('resultArray(%d)=%s has no element "%s".', count($resultArray), print_r($resultArray, TRUE), BaseDatabaseBackend::RESULT_INDEX_ROWS));
+ throw new InvalidArgumentException(sprintf('resultArray(%d)=%s has no element "%s".', count($resultArray), print_r($resultArray, TRUE), BaseDatabaseResult::RESULT_NAME_ROWS));
}
// Get a new instance
$resultInstance->resetCurrentPosition();
// Set affected rows
- $resultInstance->setAffectedRows(count($resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS]));
+ $resultInstance->setAffectedRows(count($resultArray[BaseDatabaseResult::RESULT_NAME_ROWS]));
// Return the instance
return $resultInstance;
// Now get the update criteria array and update all entries
foreach ($updateInstance->getUpdateCriteria() as $criteriaKey => $criteriaValue) {
// Update data
- $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$entryKey][$criteriaKey] = $criteriaValue;
+ $this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][$entryKey][$criteriaKey] = $criteriaValue;
// Mark it as out-dated
$this->outDated[$criteriaKey] = 1;
// Is the result valid?
if ($this->valid()) {
// Next entry found, so cache it
- $this->currentRow = $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos];
+ $this->currentRow = $this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][$this->currentPos];
$nextValid = true;
}
$current = NULL;
// Does the current enty exist?
- if (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos])) {
+ if (isset($this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][$this->currentPos])) {
// Then get it
- $current = $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos];
+ $current = $this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][$this->currentPos];
}
// Return the result
public function valid () {
// Check if all is fine ...
//* 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]));
+ $isValid = ($this->ifStatusIsOkay() && isset($this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][$this->currentPos]) && isset($this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][0]));
// Return the result
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-DATABASE-RESULT: isValid=%d - EXIT!', intval($isValid)));
public function count () {
// Count rows
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CACHED-DATABASE-RESULT: CALLED!');
- $count = count($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS]);
+ $count = count($this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS]);
// Return it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-DATABASE-RESULT: count=%d - EXIT!', $count));
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);
+ $ifStatusOkay = (isset($this->resultArray[BaseDatabaseResult::RESULT_NAME_STATUS]) && $this->resultArray[BaseDatabaseResult::RESULT_NAME_STATUS] === BaseDatabaseBackend::RESULT_OKAY);
// Return status
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CACHED-DATABASE-RESULT: ifStatusOkay=%s - EXIT!', intval($ifStatusOkay)));
use Org\Mxchange\CoreFramework\Middleware\BaseMiddleware;
use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* Database selector class
*
/**
* The real database layer
*/
- private $dbLayer = NULL;
+ private $backendInstance = NULL;
/**
* An instance of this class
/**
* Creates a new database connection layer
*
- * @param $debugInstance An instance of a DebugMiddleware class
- * @param $dbLayer An instance of a DatabaseBackend class
+ * @param $debugInstance An instance of a DebugMiddleware class
+ * @param $backendInstance An instance of a DatabaseBackend class
* @todo $debugInstance is currently not used
*/
- public static final function createDatabaseConnection (DebugMiddleware $debugInstance, DatabaseBackend $dbLayer) {
+ public static final function createDatabaseConnection (DebugMiddleware $debugInstance, DatabaseBackend $backendInstance) {
// Get instance
$databaseInstance = new DatabaseConnection();
// Set database layer
- $databaseInstance->setDatabaseLayer($dbLayer);
+ $databaseInstance->setDatabaseLayer($backendInstance);
// Set db instance
self::$selfInstance = $databaseInstance;
/**
* Setter for the real database layer
- * @param $dbLayer An instance of the real database layer
+ * @param $backendInstance An instance of a DatabaseBackend class
* @return void
*/
- public final function setDatabaseLayer (DatabaseBackend $dbLayer) {
- $this->dbLayer = $dbLayer;
+ public final function setDatabaseLayer (DatabaseBackend $backendInstance) {
+ $this->backendInstance = $backendInstance;
}
/**
* @return $indexKey Index key
*/
public final function getIndexKey () {
- return $this->dbLayer->getIndexKey();
+ return $this->backendInstance->getIndexKey();
}
/**
* @param $tableName Name of the 'table' we shall query
* @param $criteriaInstance An instance of a Criteria class
* @return $result The result as an array
+ * @throws InvalidArgumentException If a parameter is empty
*/
public function doSelectByTableCriteria (string $tableName, Criteria $criteriaInstance) {
+ // Validate parameter
+ if (empty($tableName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "tableName" is empty');
+ }
+
// Connect to the database
- $this->dbLayer->connectToDatabase();
+ $this->backendInstance->connectToDatabase();
// Get result from query
- $result = $this->dbLayer->querySelect($tableName, $criteriaInstance);
+ $result = $this->backendInstance->querySelect($tableName, $criteriaInstance);
// Return the result
return $result;
* @return $exceptionInstance Last thrown exception
*/
public final function getLastException () {
- $exceptionInstance = $this->dbLayer->getLastException();
+ $exceptionInstance = $this->backendInstance->getLastException();
return $exceptionInstance;
}
*/
public function queryInsertDataSet (StoreableCriteria $dataSetInstance) {
// Connect to the database
- $this->dbLayer->connectToDatabase();
+ $this->backendInstance->connectToDatabase();
// Ask the database layer
- $this->dbLayer->queryInsertDataSet($dataSetInstance);
+ $this->backendInstance->queryInsertDataSet($dataSetInstance);
}
/**
*/
public function queryUpdateDataSet (StoreableCriteria $dataSetInstance) {
// Connect to the database
- $this->dbLayer->connectToDatabase();
+ $this->backendInstance->connectToDatabase();
// Ask the database layer
- $this->dbLayer->queryUpdateDataSet($dataSetInstance);
+ $this->backendInstance->queryUpdateDataSet($dataSetInstance);
}
/**
*
* @param $tableName Name of table we need the primary key column from
* @return $primaryKey Primary key column of requested table
+ * @throws InvalidArgumentException If a parameter is empty
*/
public function getPrimaryKeyOfTable (string $tableName) {
+ // Validate parameter
+ if (empty($tableName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "tableName" is empty');
+ }
+
// Connect to the database
- $this->dbLayer->connectToDatabase();
+ $this->backendInstance->connectToDatabase();
// Ask the database layer
- $primaryKey = $this->dbLayer->getPrimaryKeyOfTable($tableName);
+ $primaryKey = $this->backendInstance->getPrimaryKeyOfTable($tableName);
// Return the value
return $primaryKey;
*/
public function removeNonPublicDataFromArray (array $data) {
// Connect to the database
- $this->dbLayer->connectToDatabase();
+ $this->backendInstance->connectToDatabase();
// Call database backend
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DB-CONNECTION[' . $this->__toString() . ']: Calling this->dbLayer->removeNonPublicDataFromArray(data) ...');
- $data = $this->dbLayer->removeNonPublicDataFromArray($data);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DB-CONNECTION[' . $this->__toString() . ']: Calling this->backendInstance->removeNonPublicDataFromArray(data) ...');
+ $data = $this->backendInstance->removeNonPublicDataFromArray($data);
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DB-CONNECTION[' . $this->__toString() . ']: data[]=' . gettype($data));
return $data;
*
* @param $tableName Table name
* @return $count Total row count
+ * @throws InvalidArgumentException If a parameter is empty
*/
public function countTotalRows (string $tableName) {
+ // Validate parameter
+ if (empty($tableName)) {
+ // Throw IAE
+ throw new InvalidArgumentException('Parameter "tableName" is empty');
+ }
+
// Connect to the database
- $this->dbLayer->connectToDatabase();
+ $this->backendInstance->connectToDatabase();
// Ask the database layer
- $count = $this->dbLayer->countTotalRows($tableName);
+ $count = $this->backendInstance->countTotalRows($tableName);
// Return the value
return $count;