Skip to content

Commit

Permalink
fixing up errors with DBPrefix getting applied multiple times. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnieezell committed Jul 8, 2016
1 parent 3562895 commit e928bde
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions application/Config/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Database extends \CodeIgniter\Database\Config
'password' => '',
'database' => '',
'DBDriver' => '',
'DBPrefix' => '',
'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE.
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'cacheOn' => false,
Expand Down Expand Up @@ -93,7 +93,7 @@ public function __construct()
$this->defaultGroup = 'tests';

// Under Travis-CI, we can set an ENV var named 'DB_GROUP'
// so that we can test against multiple databases.
// so that we can test against multiple databases.
if ($group = getenv('DB_GROUP'))
{
if (is_file(TESTPATH.'travis/Database.php'))
Expand Down
9 changes: 3 additions & 6 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* CodeIgniter
*
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
Expand Down Expand Up @@ -198,7 +198,7 @@ class BaseBuilder

/**
* Constructor
*
*
* @param type $tableName
* @param \CodeIgniter\Database\ConnectionInterface $db
* @param array $options
Expand All @@ -213,7 +213,6 @@ public function __construct($tableName, ConnectionInterface &$db, array $options

$this->db = $db;

$this->trackAliases($tableName);
$this->from($tableName);

if (count($options))
Expand Down Expand Up @@ -1737,8 +1736,6 @@ protected function _insert($table, array $keys, array $unescapedKeys)
*
* @return bool TRUE on success, FALSE on failure
* @throws DatabaseException
* @internal param true $bool returns the generated SQL, false executes the query.
*
*/
public function replace($set = null, $returnSQL = false)
{
Expand Down Expand Up @@ -2243,7 +2240,7 @@ public function delete($where = '', $limit = null, $reset_data = true, $returnSQ
{
$sql = $this->_limit($sql);
}

if ($reset_data)
{
$this->resetWrite();
Expand Down
5 changes: 5 additions & 0 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,11 @@ public function protectIdentifiers($item, $prefixSingle = false, $protectIdentif
return $item.$alias;
}

// In some cases, especially 'from', we end up running through
// protect_identifiers twice. This algorithm won't work when
// it contains the escapeChar so strip it out.
$item = trim($item, $this->escapeChar);

// Is there a table prefix? If not, no need to insert it
if ($this->DBPrefix !== '')
{
Expand Down
12 changes: 6 additions & 6 deletions tests/system/Database/Builder/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
class SelectTest extends \CIUnitTestCase
{
protected $db;

//--------------------------------------------------------------------
public function setUp()

public function setUp()
{
$this->db = new MockConnection([]);
}

//--------------------------------------------------------------------

public function testSimpleSelect()
{
$builder = new BaseBuilder('users', $this->db);
Expand All @@ -24,7 +24,7 @@ public function testSimpleSelect()

$this->assertEquals($expected, str_replace("\n", ' ', $builder->getCompiledSelect()));
}

//--------------------------------------------------------------------

public function testSelectOnlyOneColumn()
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Database/Live/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testInsertBatch()
}

//--------------------------------------------------------------------

public function testReplaceWithNoMatchingData()
{
$data = array('id' => 5, 'name' => 'Cab Driver', 'description' => 'Iam yellow');
Expand Down
4 changes: 2 additions & 2 deletions tests/travis/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'password' => '',
'database' => 'test',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'DBPrefix' => 'db_',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'cacheOn' => false,
Expand All @@ -31,7 +31,7 @@
'password' => '',
'database' => 'test',
'DBDriver' => 'Postgre',
'DBPrefix' => '',
'DBPrefix' => 'db_',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'cacheOn' => false,
Expand Down

0 comments on commit e928bde

Please sign in to comment.