-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6221 from sclubricants/SQLiteConnectiongetIndexData
SQLite3 Connection getIndexData()
- Loading branch information
Showing
7 changed files
with
176 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CodeIgniter\Database\Live\SQLite; | ||
|
||
use CodeIgniter\Database\SQLite3\Connection; | ||
use CodeIgniter\Database\SQLite3\Forge; | ||
use CodeIgniter\Test\CIUnitTestCase; | ||
use CodeIgniter\Test\DatabaseTestTrait; | ||
use Config\Database; | ||
use stdClass; | ||
|
||
/** | ||
* @group DatabaseLive | ||
* | ||
* @internal | ||
*/ | ||
final class GetIndexDataTest extends CIUnitTestCase | ||
{ | ||
use DatabaseTestTrait; | ||
|
||
/** | ||
* In setUp() db connection is changed. So migration doesn't work | ||
* | ||
* @var bool | ||
*/ | ||
protected $migrate = false; | ||
|
||
/** | ||
* @var Connection | ||
*/ | ||
protected $db; | ||
|
||
private Forge $forge; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$config = [ | ||
'DBDriver' => 'SQLite3', | ||
'database' => 'database.db', | ||
'DBDebug' => true, | ||
]; | ||
|
||
$this->db = db_connect($config); | ||
$this->forge = Database::forge($config); | ||
} | ||
|
||
public function testGetIndexData() | ||
{ | ||
// INTEGER PRIMARY KEY AUTO_INCREMENT doesn't get an index by default | ||
$this->forge->addField([ | ||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true], | ||
'userid' => ['type' => 'INTEGER', 'constraint' => 3], | ||
'name' => ['type' => 'VARCHAR', 'constraint' => 80], | ||
'email' => ['type' => 'VARCHAR', 'constraint' => 100], | ||
'country' => ['type' => 'VARCHAR', 'constraint' => 40], | ||
'created_at' => ['type' => 'DATETIME', 'null' => true], | ||
'updated_at' => ['type' => 'DATETIME', 'null' => true], | ||
'deleted_at' => ['type' => 'DATETIME', 'null' => true], | ||
]) | ||
->addKey(['id'], true) | ||
->addUniqueKey('email') | ||
->addKey('country') | ||
->createTable('testuser', true); | ||
|
||
$expectedIndexes = []; | ||
|
||
$row = new stdclass(); | ||
$row->name = 'PRIMARY'; | ||
$row->fields = ['id']; | ||
$row->type = 'PRIMARY'; | ||
$expectedIndexes['PRIMARY'] = $row; | ||
|
||
$row = new stdclass(); | ||
$row->name = 'testuser_email'; | ||
$row->fields = ['email']; | ||
$row->type = 'UNIQUE'; | ||
$expectedIndexes['testuser_email'] = $row; | ||
|
||
$row = new stdclass(); | ||
$row->name = 'testuser_country'; | ||
$row->fields = ['country']; | ||
$row->type = 'INDEX'; | ||
$expectedIndexes['testuser_country'] = $row; | ||
|
||
$indexes = $this->db->getIndexData('testuser'); | ||
|
||
$this->assertSame($expectedIndexes['PRIMARY']->fields, $indexes['PRIMARY']->fields); | ||
$this->assertSame($expectedIndexes['PRIMARY']->type, $indexes['PRIMARY']->type); | ||
|
||
$this->assertSame($expectedIndexes['testuser_email']->fields, $indexes['testuser_email']->fields); | ||
$this->assertSame($expectedIndexes['testuser_email']->type, $indexes['testuser_email']->type); | ||
|
||
$this->assertSame($expectedIndexes['testuser_country']->fields, $indexes['testuser_country']->fields); | ||
$this->assertSame($expectedIndexes['testuser_country']->type, $indexes['testuser_country']->type); | ||
|
||
$this->forge->dropTable('testuser', true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters