Move DatabaseException into the Database namespace.

This commit is contained in:
Lonnie Ezell 2017-10-07 23:46:24 -05:00
parent 24c18f2047
commit 77bbeae827
No known key found for this signature in database
GPG Key ID: 8EB408F8D82F5002
17 changed files with 97 additions and 63 deletions

View File

@ -35,7 +35,7 @@
* @since Version 3.0.0
* @filesource
*/
use CodeIgniter\DatabaseException;
use \CodeIgniter\Database\Exceptions\DatabaseException;
/**
* Class BaseBuilder
@ -357,7 +357,7 @@ class BaseBuilder
* @param string $type
*
* @return BaseBuilder
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
protected function maxMinAvgSum($select = '', $alias = '', $type = 'MAX')
{
@ -1936,7 +1936,7 @@ class BaseBuilder
*
*
* @return bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
protected function validateUpdate()
{
@ -1966,7 +1966,7 @@ class BaseBuilder
* @param bool $returnSQL True means SQL is returned, false will execute the query
*
* @return mixed Number of rows affected or FALSE on failure
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function updateBatch($set = null, $index = null, $batch_size = 100, $returnSQL = false)
{
@ -2085,7 +2085,7 @@ class BaseBuilder
* @param bool $escape
*
* @return BaseBuilder
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function setUpdateBatch($key, $index = '', $escape = null)
{
@ -2234,7 +2234,7 @@ class BaseBuilder
* @param bool $returnSQL
*
* @return mixed
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function delete($where = '', $limit = null, $reset_data = true, $returnSQL = false)
{

View File

@ -35,8 +35,8 @@
* @since Version 3.0.0
* @filesource
*/
use CodeIgniter\DatabaseException;
use CodeIgniter\Events\Events;
use CodeIgniter\Database\Exceptions\DatabaseException;
/**
* Class BaseConnection
@ -339,7 +339,7 @@ abstract class BaseConnection implements ConnectionInterface
* Initializes the database connection/settings.
*
* @return mixed
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function initialize()
{
@ -1260,7 +1260,7 @@ abstract class BaseConnection implements ConnectionInterface
* @param string $table the table
*
* @return string
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function prefixTable($table = '')
{
@ -1447,7 +1447,7 @@ abstract class BaseConnection implements ConnectionInterface
*
* @param bool $constrain_by_prefix = FALSE
* @return bool|array
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function listTables($constrain_by_prefix = FALSE)
{

View File

@ -35,7 +35,7 @@
* @since Version 3.0.0
* @filesource
*/
use CodeIgniter\DatabaseException;
use \CodeIgniter\Database\Exceptions\DatabaseException;
/**
* Class BaseUtils
@ -91,7 +91,7 @@ abstract class BaseUtils
* List databases
*
* @return array|bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function listDatabases()
{
@ -145,7 +145,7 @@ abstract class BaseUtils
*
* @param string $table_name
* @return bool|mixed
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function optimizeTable($table_name)
{
@ -174,7 +174,7 @@ abstract class BaseUtils
* Optimize Database
*
* @return mixed
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function optimizeDatabase()
{
@ -216,7 +216,7 @@ abstract class BaseUtils
*
* @param string $table_name
* @return mixed
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function repairTable($table_name)
{
@ -324,7 +324,7 @@ abstract class BaseUtils
*
* @param array $params
* @return mixed
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function backup($params = [])
{

View File

@ -0,0 +1,48 @@
<?php namespace CodeIgniter\Database\Exceptions;
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2017 British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2017 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @filesource
*/
class DatabaseException extends \Error
{
/**
* Exit status code
* @var int
*/
protected $code = 8;
}

View File

@ -35,7 +35,7 @@
* @since Version 3.0.0
* @filesource
*/
use CodeIgniter\DatabaseException;
use \CodeIgniter\Database\Exceptions\DatabaseException;
/**
* Class Forge
@ -184,7 +184,7 @@ class Forge
* @param string $db_name
*
* @return bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function createDatabase($db_name)
{
@ -224,7 +224,7 @@ class Forge
* @param string $db_name
*
* @return bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function dropDatabase($db_name)
{
@ -339,7 +339,7 @@ class Forge
* @param array $attributes Associative array of table attributes
*
* @return bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function createTable($table, $if_not_exists = false, array $attributes = [])
{
@ -474,7 +474,7 @@ class Forge
* @param bool $if_exists Whether to add an IF EXISTS condition
*
* @return mixed
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function dropTable($table_name, $if_exists = false)
{
@ -557,7 +557,7 @@ class Forge
* @param string $new_table_name New table name
*
* @return mixed
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function renameTable($table_name, $new_table_name)
{
@ -599,7 +599,7 @@ class Forge
* @param array $field Column definition
*
* @return bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function addColumn($table, $field)
{
@ -643,7 +643,7 @@ class Forge
* @param string $column_name Column name
*
* @return bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function dropColumn($table, $column_name)
{
@ -670,7 +670,7 @@ class Forge
* @param string $field Column definition
*
* @return bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function modifyColumn($table, $field)
{

View File

@ -37,7 +37,7 @@
*/
use CodeIgniter\Database\BaseConnection;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\DatabaseException;
use \CodeIgniter\Database\Exceptions\DatabaseException;
/**
* Connection for MySQLi
@ -91,7 +91,7 @@ class Connection extends BaseConnection implements ConnectionInterface
* @param bool $persistent
*
* @return mixed
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function connect($persistent = false)
{

View File

@ -36,7 +36,7 @@
* @filesource
*/
use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\DatabaseException;
use \CodeIgniter\Database\Exceptions\DatabaseException;
/**
* Builder for Postgre

View File

@ -163,17 +163,3 @@ class UserInputException extends \OutOfBoundsException
protected $code = 7;
}
/**
* Exception for automatic logging.
*/
class DatabaseException extends Error
{
/**
* Error code
* @var int
*/
protected $code = 8;
}

View File

@ -255,7 +255,7 @@ class CIDatabaseTestCase extends CIUnitTestCase
* @param array $where
*
* @return bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function seeInDatabase(string $table, array $where)
{
@ -277,7 +277,7 @@ class CIDatabaseTestCase extends CIUnitTestCase
* @param array $where
*
* @return bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function grabFromDatabase(string $table, string $column, array $where)
{
@ -300,7 +300,7 @@ class CIDatabaseTestCase extends CIUnitTestCase
* @param string $table
* @param array $data
*
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function hasInDatabase(string $table, array $data)
{
@ -323,7 +323,7 @@ class CIDatabaseTestCase extends CIUnitTestCase
* @param array $where
*
* @return bool
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function seeNumRecords(int $expected, string $table, array $where)
{

View File

@ -76,7 +76,7 @@ class BaseConnectionTest extends \CIUnitTestCase
{
$db = new MockConnection($this->options);
$this->expectException('CodeIgniter\DatabaseException');
$this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException');
$this->expectExceptionMessage('Unable to connect to the database.');
$db->shouldReturn('connect', false)
@ -98,7 +98,7 @@ class BaseConnectionTest extends \CIUnitTestCase
//--------------------------------------------------------------------
/**
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
* @group single
*/
public function testCanConnectToFailoverWhenNoConnectionAvailable()

View File

@ -40,7 +40,7 @@ class InsertTest extends \CIUnitTestCase
{
$builder = $this->db->table('jobs');
$this->expectException('CodeIgniter\DatabaseException');
$this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException');
$this->expectExceptionMessage('You must use the "set" method to update an entry.');
$builder->insert(null, true, true);
@ -81,7 +81,7 @@ class InsertTest extends \CIUnitTestCase
{
$builder = $this->db->table('jobs');
$this->expectException('CodeIgniter\DatabaseException', 'You must use the "set" method to update an entry.');
$this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException', 'You must use the "set" method to update an entry.');
$this->expectExceptionMessage('You must use the "set" method to update an entry.');
$builder->insertBatch();
}
@ -92,7 +92,7 @@ class InsertTest extends \CIUnitTestCase
{
$builder = $this->db->table('jobs');
$this->expectException('CodeIgniter\DatabaseException');
$this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException');
$this->expectExceptionMessage('insertBatch() called with no data');
$builder->insertBatch([]);
}

View File

@ -36,7 +36,7 @@ class ReplaceTest extends \CIUnitTestCase
{
$builder = $this->db->table('jobs');
$this->expectException('CodeIgniter\DatabaseException');
$this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException');
$this->expectExceptionMessage('You must use the "set" method to update an entry.');
$builder->replace();

View File

@ -200,7 +200,7 @@ class SelectTest extends \CIUnitTestCase
{
$builder = new BaseBuilder('invoices', $this->db);
$this->expectException('CodeIgniter\DatabaseException');
$this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException');
$this->expectExceptionMessage('The query you submitted is not valid.');
$builder->selectSum('');

View File

@ -66,7 +66,7 @@ class UpdateTest extends \CIUnitTestCase
{
$builder = new BaseBuilder('jobs', $this->db);
$this->expectException('CodeIgniter\DatabaseException', 'You must use the "set" method to update an entry.');
$this->expectException('CodeIgniter\Database\Exceptions\DatabaseException', 'You must use the "set" method to update an entry.');
$builder->update(null, null, null, true);
}
@ -120,7 +120,7 @@ WHERE "id" IN(2,3)';
{
$builder = new BaseBuilder('jobs', $this->db);
$this->expectException('CodeIgniter\DatabaseException');
$this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException');
$this->expectExceptionMessage('You must use the "set" method to update an entry.');
$builder->updateBatch(null, 'id');
@ -132,7 +132,7 @@ WHERE "id" IN(2,3)';
{
$builder = new BaseBuilder('jobs', $this->db);
$this->expectException('CodeIgniter\DatabaseException');
$this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException');
$this->expectExceptionMessage('You must specify an index to match on for batch updates.');
$builder->updateBatch([]);
@ -144,7 +144,7 @@ WHERE "id" IN(2,3)';
{
$builder = new BaseBuilder('jobs', $this->db);
$this->expectException('CodeIgniter\DatabaseException');
$this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException');
$this->expectExceptionMessage('updateBatch() called with no data');
$builder->updateBatch([], 'id');

View File

@ -1,6 +1,6 @@
<?php namespace CodeIgniter\Database\Live;
use CodeIgniter\DatabaseException;
use \CodeIgniter\Database\Exceptions\DatabaseException;
/**
* @group DatabaseLive
@ -13,7 +13,7 @@ class DeleteTest extends \CIDatabaseTestCase
public function testDeleteThrowExceptionWithNoCriteria()
{
$this->expectException('CodeIgniter\DatabaseException');
$this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException');
$this->db->table('job')->delete();
}
@ -44,7 +44,7 @@ class DeleteTest extends \CIDatabaseTestCase
/**
* @group single
* @throws \CodeIgniter\DatabaseException
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
*/
public function testDeleteWithLimit()
{
@ -68,4 +68,4 @@ class DeleteTest extends \CIDatabaseTestCase
//--------------------------------------------------------------------
}
}

View File

@ -1,6 +1,6 @@
<?php namespace CodeIgniter\Database\Live;
use CodeIgniter\DatabaseException;
use \CodeIgniter\Database\Exceptions\DatabaseException;
/**
* @group DatabaseLive

View File

@ -132,6 +132,6 @@ DatabaseException
This exception is thrown for database errors, such as when the database connection cannot be created,
or when it is temporarily lost::
throw new \CodeIgniter\DatabaseException();
throw new \CodeIgniter\Database\Exceptions\DatabaseException();
This provides an HTTP status code of 500, and an exit code of 8.