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