Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true,
"composer/package-versions-deprecated": true
}
},
"scripts": {
"test": "phpunit --testdox --no-interaction",
Expand Down
20 changes: 15 additions & 5 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ public function execute(): int
foreach ($statements as $statement) {
/** @var array $statement */
[$statementSql, $statementParams] = $statement;
$this->setSql($statementSql)->bindValues($statementParams);
$this
->setSql($statementSql)
->bindValues($statementParams);
$result = parent::execute();
}

$this->setSql($sql)->bindValues($params);
$this
->setSql($sql)
->bindValues($params);

return $result;
}
Expand Down Expand Up @@ -87,15 +91,21 @@ protected function queryInternal(string $method, $fetchMode = null)

foreach ($statements as $statement) {
[$statementSql, $statementParams] = $statement;
$this->setSql($statementSql)->bindValues($statementParams);
$this
->setSql($statementSql)
->bindValues($statementParams);
parent::execute();
}

$this->setSql($lastStatementSql)->bindValues($lastStatementParams);
$this
->setSql($lastStatementSql)
->bindValues($lastStatementParams);

$result = parent::queryInternal($method, $fetchMode);

$this->setSql($sql)->bindValues($params);
$this
->setSql($sql)
->bindValues($params);

return $result;
}
Expand Down
197 changes: 144 additions & 53 deletions src/QueryBuilder.php

Large diffs are not rendered by default.

88 changes: 64 additions & 24 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ protected function findTableNames(string $schema = ''): array
{
$sql = "SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence' ORDER BY tbl_name";

return $this->getDb()->createCommand($sql)->queryColumn();
return $this
->getDb()
->createCommand($sql)
->queryColumn();
}

/**
Expand Down Expand Up @@ -151,9 +154,12 @@ protected function loadTablePrimaryKey(string $tableName): ?Constraint
*/
protected function loadTableForeignKeys(string $tableName): array
{
$foreignKeys = $this->getDb()->createCommand(
'PRAGMA FOREIGN_KEY_LIST (' . $this->quoteValue($tableName) . ')'
)->queryAll();
$foreignKeys = $this
->getDb()
->createCommand(
'PRAGMA FOREIGN_KEY_LIST (' . $this->quoteValue($tableName) . ')'
)
->queryAll();

$foreignKeys = $this->normalizePdoRowKeyCase($foreignKeys, true);

Expand Down Expand Up @@ -216,9 +222,12 @@ protected function loadTableUniques(string $tableName): array
*/
protected function loadTableChecks(string $tableName): array
{
$sql = $this->getDb()->createCommand('SELECT `sql` FROM `sqlite_master` WHERE name = :tableName', [
':tableName' => $tableName,
])->queryScalar();
$sql = $this
->getDb()
->createCommand('SELECT `sql` FROM `sqlite_master` WHERE name = :tableName', [
':tableName' => $tableName,
])
->queryScalar();

/** @var SqlToken[]|SqlToken[][]|SqlToken[][][] $code */
$code = (new SqlTokenizer($sql))->tokenize();
Expand Down Expand Up @@ -314,7 +323,10 @@ public function createColumnSchemaBuilder(string $type, $length = null): ColumnS
protected function findColumns(TableSchema $table): bool
{
$sql = 'PRAGMA table_info(' . $this->quoteSimpleTableName($table->getName()) . ')';
$columns = $this->getDb()->createCommand($sql)->queryAll();
$columns = $this
->getDb()
->createCommand($sql)
->queryAll();

if (empty($columns)) {
return false;
Expand All @@ -329,9 +341,13 @@ protected function findColumns(TableSchema $table): bool
}

$pk = $table->getPrimaryKey();
if (count($pk) === 1 && !strncasecmp($table->getColumn($pk[0])->getDbType(), 'int', 3)) {
if (count($pk) === 1 && !strncasecmp($table
->getColumn($pk[0])
->getDbType(), 'int', 3)) {
$table->sequenceName('');
$table->getColumn($pk[0])->autoIncrement(true);
$table
->getColumn($pk[0])
->autoIncrement(true);
}

return true;
Expand All @@ -347,7 +363,10 @@ protected function findColumns(TableSchema $table): bool
protected function findConstraints(TableSchema $table): void
{
$sql = 'PRAGMA foreign_key_list(' . $this->quoteSimpleTableName($table->getName()) . ')';
$keys = $this->getDb()->createCommand($sql)->queryAll();
$keys = $this
->getDb()
->createCommand($sql)
->queryAll();

foreach ($keys as $key) {
$id = (int) $key['id'];
Expand Down Expand Up @@ -382,14 +401,20 @@ protected function findConstraints(TableSchema $table): void
public function findUniqueIndexes(TableSchema $table): array
{
$sql = 'PRAGMA index_list(' . $this->quoteSimpleTableName($table->getName()) . ')';
$indexes = $this->getDb()->createCommand($sql)->queryAll();
$indexes = $this
->getDb()
->createCommand($sql)
->queryAll();
$uniqueIndexes = [];

foreach ($indexes as $index) {
$indexName = $index['name'];
$indexInfo = $this->getDb()->createCommand(
'PRAGMA index_info(' . $this->quoteValue($index['name']) . ')'
)->queryAll();
$indexInfo = $this
->getDb()
->createCommand(
'PRAGMA index_info(' . $this->quoteValue($index['name']) . ')'
)
->queryAll();

if ($index['unique']) {
$uniqueIndexes[$indexName] = [];
Expand Down Expand Up @@ -476,10 +501,16 @@ public function setTransactionIsolationLevel(string $level): void
{
switch ($level) {
case Transaction::SERIALIZABLE:
$this->getDb()->createCommand('PRAGMA read_uncommitted = False;')->execute();
$this
->getDb()
->createCommand('PRAGMA read_uncommitted = False;')
->execute();
break;
case Transaction::READ_UNCOMMITTED:
$this->getDb()->createCommand('PRAGMA read_uncommitted = True;')->execute();
$this
->getDb()
->createCommand('PRAGMA read_uncommitted = True;')
->execute();
break;
default:
throw new NotSupportedException(
Expand All @@ -499,9 +530,12 @@ public function setTransactionIsolationLevel(string $level): void
*/
private function loadTableColumnsInfo(string $tableName): array
{
$tableColumns = $this->getDb()->createCommand(
'PRAGMA TABLE_INFO (' . $this->quoteValue($tableName) . ')'
)->queryAll();
$tableColumns = $this
->getDb()
->createCommand(
'PRAGMA TABLE_INFO (' . $this->quoteValue($tableName) . ')'
)
->queryAll();

$tableColumns = $this->normalizePdoRowKeyCase($tableColumns, true);

Expand All @@ -521,9 +555,12 @@ private function loadTableColumnsInfo(string $tableName): array
private function loadTableConstraints(string $tableName, string $returnType)
{
$tableColumns = null;
$indexList = $this->getDb()->createCommand(
'PRAGMA INDEX_LIST (' . $this->quoteValue($tableName) . ')'
)->queryAll();
$indexList = $this
->getDb()
->createCommand(
'PRAGMA INDEX_LIST (' . $this->quoteValue($tableName) . ')'
)
->queryAll();
$indexes = $this->normalizePdoRowKeyCase($indexList, true);

if (!empty($indexes) && !isset($indexes[0]['origin'])) {
Expand Down Expand Up @@ -621,7 +658,10 @@ private function createColumnSchema(): ColumnSchema
*/
private function getPragmaIndexInfo(string $name): array
{
$column = $this->getDb()->createCommand('PRAGMA INDEX_INFO (' . $this->quoteValue($name) . ')')->queryAll();
$column = $this
->getDb()
->createCommand('PRAGMA INDEX_INFO (' . $this->quoteValue($name) . ')')
->queryAll();
$columns = $this->normalizePdoRowKeyCase($column, true);
ArraySorter::multisort($columns, 'seqno', SORT_ASC, SORT_NUMERIC);

Expand Down
Loading