3 * This file contains database error classes.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Database error base class
28 class DBError
extends Exception
{
33 * Construct a database error
34 * @param IDatabase $db Object which threw the error
35 * @param string $error A simple error message to be used for debugging
37 function __construct( IDatabase
$db = null, $error ) {
39 parent
::__construct( $error );
44 * Base class for the more common types of database errors. These are known to occur
45 * frequently, so we try to give friendly error messages for them.
50 class DBExpectedError
extends DBError
{
56 class DBConnectionError
extends DBExpectedError
{
58 * @param IDatabase $db Object throwing the error
59 * @param string $error Error text
61 function __construct( IDatabase
$db = null, $error = 'unknown error' ) {
62 $msg = 'Cannot access the database';
63 if ( trim( $error ) != '' ) {
67 parent
::__construct( $db, $msg );
74 class DBQueryError
extends DBExpectedError
{
85 * @param IDatabase $db
86 * @param string $error
87 * @param int|string $errno
89 * @param string $fname
91 function __construct( IDatabase
$db, $error, $errno, $sql, $fname ) {
92 if ( $db instanceof DatabaseBase
&& $db->wasConnectionError( $errno ) ) {
93 $message = "A connection error occured. \n" .
95 "Function: $fname\n" .
96 "Error: $errno $error\n";
98 $message = "A database error has occurred. Did you forget to run " .
99 "maintenance/update.php after upgrading? See: " .
100 "https://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" .
102 "Function: $fname\n" .
103 "Error: $errno $error\n";
105 parent
::__construct( $db, $message );
107 $this->error
= $error;
108 $this->errno
= $errno;
110 $this->fname
= $fname;
117 class DBReadOnlyError
extends DBExpectedError
{
123 class DBTransactionError
extends DBExpectedError
{
127 * Exception class for replica DB wait timeouts
130 class DBReplicationWaitError
extends DBExpectedError
{
136 class DBUnexpectedError
extends DBError
{
140 * Exception class for attempted DB access
143 class DBAccessError
extends DBUnexpectedError
{
144 public function __construct() {
145 parent
::__construct( "Mediawiki tried to access the database via wfGetDB(). " .
146 "This is not allowed, because database access has been disabled." );