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