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