X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fdatabase%2Fclass_BaseDatabaseWrapper.php;h=1f8ad0325598aa8b173eca959c41b3acdabb8a3d;hb=fdc6a02b5e6c2155cda61fcc345c7583b734ab85;hp=1ca253c8fcff68d9c7a4719ccebe41d4540c59cb;hpb=42842656e56e030851edf8a3546d2eef995c3b24;p=core.git diff --git a/inc/classes/main/database/class_BaseDatabaseWrapper.php b/inc/classes/main/database/class_BaseDatabaseWrapper.php index 1ca253c8..1f8ad032 100644 --- a/inc/classes/main/database/class_BaseDatabaseWrapper.php +++ b/inc/classes/main/database/class_BaseDatabaseWrapper.php @@ -2,11 +2,11 @@ /** * A generic database wrapper * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @link http://www.shipsimu.org * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -84,7 +84,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { protected function queryInsertDataSet (StoreableCriteria $dataSetInstance, array $onlyKeys = array()) { // First get a key suitable for our cache and extend it with this class name $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys); - //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...'); // Does this key exists in cache? if ($this->cacheInstance->offsetExists($cacheKey)) { @@ -106,7 +106,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { protected function queryUpdateDataSet (StoreableCriteria $dataSetInstance, array $onlyKeys = array()) { // First get a key suitable for our cache and extend it with this class name $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys); - //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...'); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...'); // Does this key exists in cache? if ($this->cacheInstance->offsetExists($cacheKey)) { @@ -127,6 +127,15 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { return $this->getDatabaseInstance()->getIndexKey(); } + /** + * Getter for last exception + * + * @return $lastException Last exception or NULL if none occured + */ + public final function getLastException () { + return $this->getDatabaseInstance()->getLastException(); + } + /** * Do a "select" query on the current table with the given search criteria and * store it in cache for later usage @@ -140,15 +149,15 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { $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: */ $this->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); } else { // Debug message - //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: Quering database, cacheKey=' . $cacheKey); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: Quering database, cacheKey=' . $cacheKey); // Now it's time to ask the database layer for this select statement $result = $this->getDatabaseInstance()->doSelectByTableCriteria($this->getTableName(), $criteriaInstance); @@ -160,14 +169,14 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { } else { // This invalid result must be wrapped $result = array( - BaseDatabaseFrontend::RESULT_INDEX_STATUS => 'invalid', - BaseDatabaseFrontend::RESULT_INDEX_EXCEPTION => $this->getDatabaseInstance()->getLastException() + BaseDatabaseBackend::RESULT_INDEX_STATUS => 'invalid', + BaseDatabaseBackend::RESULT_INDEX_EXCEPTION => $this->getDatabaseInstance()->getLastException() ); } } // Create an instance of a DatabaseResult class with the given result - $resultInstance = DatabaseResult::createDatabaseResult($result); + $resultInstance = ObjectFactory::createObjectByConfiguredName('database_result_class', array($result)); // And return the instance return $resultInstance; @@ -193,7 +202,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { $numRows = $resultInstance->getAffectedRows(); // Debug message - //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: numRows=' . $numRows); + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-WRAPPER: numRows=' . $numRows); } // END - if // Return the result