]> git.mxchange.org Git - core.git/blob - inc/main/classes/database/class_BaseDatabaseBackend.php
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\Generic\FrameworkException;
7 use CoreFramework\Object\BaseFrameworkSystem;
8
9 /**
10  * An abstract database access class for handling database I/O requests
11  *
12  * @see                 DatabaseBackend - An interface for database backends
13  * @author              Roland Haeder <webmaster@shipsimu.org>
14  * @version             0.0.0
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
18  *
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.
23  *
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.
28  *
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/>.
31  */
32 abstract class BaseDatabaseBackend extends BaseFrameworkSystem implements DatabaseBackend {
33         // Constants for exceptions
34         const EXCEPTION_SQL_QUERY = 0x140;
35
36         // Result array indexes
37         const RESULT_INDEX_ROWS      = 'rows';
38         const RESULT_INDEX_STATUS    = 'status';
39         const RESULT_INDEX_EXCEPTION = 'exception';
40
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;
45
46         // Status results
47         const RESULT_OKAY = 'ok';
48
49         /**
50          * Last thrown exception or NULL if all is fine
51          */
52         private $lastException = NULL;
53
54         /**
55          * Protected constructor
56          *
57          * @param       $className      Name of the class
58          * @return      void
59          */
60         protected function __construct ($className) {
61                 // Call parent constructor
62                 parent::__construct($className);
63         }
64
65         /**
66          * Getter for last exception
67          *
68          * @return      $lastException  Last thrown exception
69          */
70         public final function getLastException () {
71                 return $this->lastException;
72         }
73
74         /**
75          * Setter for last exception
76          *
77          * @param       $lastException  Last thrown exception
78          * @return      void
79          */
80         public final function setLastException (FrameworkException $exceptionInstance) {
81                 $this->lastException = $exceptionInstance;
82         }
83
84         /**
85          * Reset the last exception instance. This should be done after a "query"
86          * was completed without any errors.
87          *
88          * @return      void
89          */
90         protected final function resetLastException () {
91                 $this->lastException = NULL;
92         }
93
94         /**
95          * Removes non-public data from given array.
96          *
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.
99          */
100         public abstract function removeNonPublicDataFromArray (array $data);
101
102 }