3 namespace CoreFramework\Database\Backend;
5 // Import framework stuff
6 use CoreFramework\Generic\FrameworkException;
7 use CoreFramework\Object\BaseFrameworkSystem;
10 * An abstract database access class for handling database I/O requests
12 * @see DatabaseBackend - An interface for database backends
13 * @author Roland Haeder <webmaster@shipsimu.org>
15 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
16 * @license GNU GPL 3.0 or any newer version
17 * @link http://www.shipsimu.org
19 * This program is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 abstract class BaseDatabaseBackend extends BaseFrameworkSystem implements DatabaseBackend {
33 // Constants for exceptions
34 const EXCEPTION_SQL_QUERY = 0x140;
36 // Result array indexes
37 const RESULT_INDEX_ROWS = 'rows';
38 const RESULT_INDEX_STATUS = 'status';
39 const RESULT_INDEX_EXCEPTION = 'exception';
41 // Constants for MySQL backward-compatiblity (PLEASE FIX THEM!)
42 const DB_CODE_TABLE_MISSING = 0x100;
43 const DB_CODE_TABLE_UNWRITEABLE = 0x101;
44 const DB_CODE_DATA_FILE_CORRUPT = 0x102;
47 const RESULT_OKAY = 'ok';
50 * Last thrown exception or NULL if all is fine
52 private $lastException = NULL;
55 * Protected constructor
57 * @param $className Name of the class
60 protected function __construct ($className) {
61 // Call parent constructor
62 parent::__construct($className);
66 * Getter for last exception
68 * @return $lastException Last thrown exception
70 public final function getLastException () {
71 return $this->lastException;
75 * Setter for last exception
77 * @param $lastException Last thrown exception
80 public final function setLastException (FrameworkException $exceptionInstance) {
81 $this->lastException = $exceptionInstance;
85 * Reset the last exception instance. This should be done after a "query"
86 * was completed without any errors.
90 protected final function resetLastException () {
91 $this->lastException = NULL;
95 * Removes non-public data from given array.
97 * @param $data An array with possible non-public data that needs to be removed.
98 * @return $data A cleaned up array with only public data.
100 public abstract function removeNonPublicDataFromArray (array $data);