Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move methods from command to abstract pdo command #278

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Add line to CHANGELOG.md
Tigrov committed Nov 5, 2023
commit 4e85b0edb8e9101ae35eb80f61dd92df58ea30f4
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
- Enh #263: Support json type (@Tigrov)
- Bug #268: Fix foreign keys: support multiple foreign keys referencing to one table and possible null columns for reference (@Tigrov)
- Bug #271: Refactor `DMLQueryBuilder`, related with yiisoft/db#746 (@Tigrov)
- Enh #278: Move methods from `Command` to `AbstractPdoCommand` class (@Tigrov)

## 1.0.1 July 24, 2023


Unchanged files with check annotations Beta

$this->advance(1);
}
$this->addTokenFromBuffer();

Check warning on line 127 in src/AbstractTokenizer.php

GitHub Actions / PHP 8.1-sqlite-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ $this->buffer .= $this->substring(1); $this->advance(1); } - $this->addTokenFromBuffer(); + if ($token->getHasChildren() && $token[-1] instanceof SqlToken && !$token[-1]->getHasChildren()) { unset($token[-1]); }
if (
$token->getHasChildren() &&
$this->substrings[$cacheKey . ',0'] = mb_strtoupper($this->substrings[$cacheKey . ',1'], 'UTF-8');
}
return $this->substrings[$cacheKey . ',' . (int) $caseSensitive];

Check warning on line 289 in src/AbstractTokenizer.php

GitHub Actions / PHP 8.1-sqlite-ubuntu-latest

Escaped Mutant for Mutator "CastInt": --- Original +++ New @@ @@ if (!$caseSensitive && !isset($this->substrings[$cacheKey . ',0'])) { $this->substrings[$cacheKey . ',0'] = mb_strtoupper($this->substrings[$cacheKey . ',1'], 'UTF-8'); } - return $this->substrings[$cacheKey . ',' . (int) $caseSensitive]; + return $this->substrings[$cacheKey . ',' . $caseSensitive]; } /** * Returns an index after the given string in the SQL code starting with the specified offset.
}
/**
$offset = $this->offset;
}
if ($offset + mb_strlen($string, 'UTF-8') > $this->length) {

Check warning on line 306 in src/AbstractTokenizer.php

GitHub Actions / PHP 8.1-sqlite-ubuntu-latest

Escaped Mutant for Mutator "MBString": --- Original +++ New @@ @@ if ($offset === null) { $offset = $this->offset; } - if ($offset + mb_strlen($string, 'UTF-8') > $this->length) { + if ($offset + strlen($string) > $this->length) { return $this->length; } $afterIndexOf = mb_strpos($this->sql, $string, $offset, 'UTF-8');

Check warning on line 306 in src/AbstractTokenizer.php

GitHub Actions / PHP 8.1-sqlite-ubuntu-latest

Escaped Mutant for Mutator "Plus": --- Original +++ New @@ @@ if ($offset === null) { $offset = $this->offset; } - if ($offset + mb_strlen($string, 'UTF-8') > $this->length) { + if ($offset - mb_strlen($string, 'UTF-8') > $this->length) { return $this->length; } $afterIndexOf = mb_strpos($this->sql, $string, $offset, 'UTF-8');

Check warning on line 306 in src/AbstractTokenizer.php

GitHub Actions / PHP 8.1-sqlite-ubuntu-latest

Escaped Mutant for Mutator "GreaterThan": --- Original +++ New @@ @@ if ($offset === null) { $offset = $this->offset; } - if ($offset + mb_strlen($string, 'UTF-8') > $this->length) { + if ($offset + mb_strlen($string, 'UTF-8') >= $this->length) { return $this->length; } $afterIndexOf = mb_strpos($this->sql, $string, $offset, 'UTF-8');
return $this->length;
}
$afterIndexOf = mb_strpos($this->sql, $string, $offset, 'UTF-8');

Check warning on line 310 in src/AbstractTokenizer.php

GitHub Actions / PHP 8.1-sqlite-ubuntu-latest

Escaped Mutant for Mutator "MBString": --- Original +++ New @@ @@ if ($offset + mb_strlen($string, 'UTF-8') > $this->length) { return $this->length; } - $afterIndexOf = mb_strpos($this->sql, $string, $offset, 'UTF-8'); + $afterIndexOf = strpos($this->sql, $string, $offset); if ($afterIndexOf === false) { $afterIndexOf = $this->length; } else {
if ($afterIndexOf === false) {
$afterIndexOf = $this->length;
} else {
$afterIndexOf += mb_strlen($string, 'UTF-8');

Check warning on line 315 in src/AbstractTokenizer.php

GitHub Actions / PHP 8.1-sqlite-ubuntu-latest

Escaped Mutant for Mutator "MBString": --- Original +++ New @@ @@ if ($afterIndexOf === false) { $afterIndexOf = $this->length; } else { - $afterIndexOf += mb_strlen($string, 'UTF-8'); + $afterIndexOf += strlen($string); } return $afterIndexOf; }
}
return $afterIndexOf;
return false;
}
$this->addTokenFromBuffer();

Check warning on line 333 in src/AbstractTokenizer.php

GitHub Actions / PHP 8.1-sqlite-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ if (!$isIdentifier && !$isStringLiteral) { return false; } - $this->addTokenFromBuffer(); + $this->currentToken[] = (new SqlToken())->type($isIdentifier ? SqlToken::TYPE_IDENTIFIER : SqlToken::TYPE_STRING_LITERAL)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset + $length); return true; }
$this->currentToken[] = (new SqlToken())
->type($isIdentifier ? SqlToken::TYPE_IDENTIFIER : SqlToken::TYPE_STRING_LITERAL)

Check warning on line 336 in src/AbstractTokenizer.php

GitHub Actions / PHP 8.1-sqlite-ubuntu-latest

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ return false; } $this->addTokenFromBuffer(); - $this->currentToken[] = (new SqlToken())->type($isIdentifier ? SqlToken::TYPE_IDENTIFIER : SqlToken::TYPE_STRING_LITERAL)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset + $length); + $this->currentToken[] = (new SqlToken())->type($isIdentifier ? SqlToken::TYPE_STRING_LITERAL : SqlToken::TYPE_IDENTIFIER)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset + $length); return true; } /**
->content(is_string($content) ? $content : $this->substring($length))

Check warning on line 337 in src/AbstractTokenizer.php

GitHub Actions / PHP 8.1-sqlite-ubuntu-latest

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ return false; } $this->addTokenFromBuffer(); - $this->currentToken[] = (new SqlToken())->type($isIdentifier ? SqlToken::TYPE_IDENTIFIER : SqlToken::TYPE_STRING_LITERAL)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset + $length); + $this->currentToken[] = (new SqlToken())->type($isIdentifier ? SqlToken::TYPE_IDENTIFIER : SqlToken::TYPE_STRING_LITERAL)->content(is_string($content) ? $this->substring($length) : $content)->startOffset($this->offset)->endOffset($this->offset + $length); return true; } /**
->startOffset($this->offset)
->endOffset($this->offset + $length);
case '(':
$this->currentToken[] = (new SqlToken())
->type(SqlToken::TYPE_OPERATOR)
->content(is_string($content) ? $content : $this->substring($length))

Check warning on line 359 in src/AbstractTokenizer.php

GitHub Actions / PHP 8-sqlite-ubuntu-latest

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ $this->addTokenFromBuffer(); switch ($this->substring($length)) { case '(': - $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_OPERATOR)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset + $length); + $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_OPERATOR)->content(is_string($content) ? $this->substring($length) : $content)->startOffset($this->offset)->endOffset($this->offset + $length); $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_PARENTHESIS); if ($this->currentToken[-1] !== null) { $this->tokenStack->push($this->currentToken[-1]);
->startOffset($this->offset)
->endOffset($this->offset + $length);

Check warning on line 361 in src/AbstractTokenizer.php

GitHub Actions / PHP 8-sqlite-ubuntu-latest

Escaped Mutant for Mutator "Plus": --- Original +++ New @@ @@ $this->addTokenFromBuffer(); switch ($this->substring($length)) { case '(': - $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_OPERATOR)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset + $length); + $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_OPERATOR)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset - $length); $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_PARENTHESIS); if ($this->currentToken[-1] !== null) { $this->tokenStack->push($this->currentToken[-1]);
$this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_PARENTHESIS);
if ($this->currentToken[-1] !== null) {
$this->currentToken[] = (new SqlToken())
->type(SqlToken::TYPE_OPERATOR)
->content(is_string($content) ? $content : $this->substring($length))

Check warning on line 389 in src/AbstractTokenizer.php

GitHub Actions / PHP 8-sqlite-ubuntu-latest

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ if ($this->currentToken instanceof SqlToken && !$this->currentToken->getHasChildren()) { break; } - $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_OPERATOR)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset + $length); + $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_OPERATOR)->content(is_string($content) ? $this->substring($length) : $content)->startOffset($this->offset)->endOffset($this->offset + $length); $this->tokenStack->pop(); $this->currentToken = $this->tokenStack->top(); $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_STATEMENT);
->startOffset($this->offset)
->endOffset($this->offset + $length);
$this->tokenStack->pop();
default:
$this->currentToken[] = (new SqlToken())
->type(SqlToken::TYPE_OPERATOR)
->content(is_string($content) ? $content : $this->substring($length))

Check warning on line 406 in src/AbstractTokenizer.php

GitHub Actions / PHP 8-sqlite-ubuntu-latest

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ $this->currentToken = $this->tokenStack->top(); break; default: - $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_OPERATOR)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset + $length); + $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_OPERATOR)->content(is_string($content) ? $this->substring($length) : $content)->startOffset($this->offset)->endOffset($this->offset + $length); break; } return true;
->startOffset($this->offset)
->endOffset($this->offset + $length);

Check warning on line 408 in src/AbstractTokenizer.php

GitHub Actions / PHP 8-sqlite-ubuntu-latest

Escaped Mutant for Mutator "Plus": --- Original +++ New @@ @@ $this->currentToken = $this->tokenStack->top(); break; default: - $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_OPERATOR)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset + $length); + $this->currentToken[] = (new SqlToken())->type(SqlToken::TYPE_OPERATOR)->content(is_string($content) ? $content : $this->substring($length))->startOffset($this->offset)->endOffset($this->offset - $length); break; } return true;
break;
}
$isKeyword = $this->isKeyword($this->buffer, $content);
$this->currentToken[] = (new SqlToken())
->type($isKeyword ? SqlToken::TYPE_KEYWORD : SqlToken::TYPE_TOKEN)

Check warning on line 428 in src/AbstractTokenizer.php

GitHub Actions / PHP 8-sqlite-ubuntu-latest

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ return; } $isKeyword = $this->isKeyword($this->buffer, $content); - $this->currentToken[] = (new SqlToken())->type($isKeyword ? SqlToken::TYPE_KEYWORD : SqlToken::TYPE_TOKEN)->content(is_string($content) ? $content : $this->buffer)->startOffset($this->offset - mb_strlen($this->buffer, 'UTF-8'))->endOffset($this->offset); + $this->currentToken[] = (new SqlToken())->type($isKeyword ? SqlToken::TYPE_TOKEN : SqlToken::TYPE_KEYWORD)->content(is_string($content) ? $content : $this->buffer)->startOffset($this->offset - mb_strlen($this->buffer, 'UTF-8'))->endOffset($this->offset); $this->buffer = ''; } /**
->content(is_string($content) ? $content : $this->buffer)
->startOffset($this->offset - mb_strlen($this->buffer, 'UTF-8'))

Check warning on line 430 in src/AbstractTokenizer.php

GitHub Actions / PHP 8-sqlite-ubuntu-latest

Escaped Mutant for Mutator "MBString": --- Original +++ New @@ @@ return; } $isKeyword = $this->isKeyword($this->buffer, $content); - $this->currentToken[] = (new SqlToken())->type($isKeyword ? SqlToken::TYPE_KEYWORD : SqlToken::TYPE_TOKEN)->content(is_string($content) ? $content : $this->buffer)->startOffset($this->offset - mb_strlen($this->buffer, 'UTF-8'))->endOffset($this->offset); + $this->currentToken[] = (new SqlToken())->type($isKeyword ? SqlToken::TYPE_KEYWORD : SqlToken::TYPE_TOKEN)->content(is_string($content) ? $content : $this->buffer)->startOffset($this->offset - strlen($this->buffer))->endOffset($this->offset); $this->buffer = ''; } /**
->endOffset($this->offset);
$this->buffer = '';
*/
private function advance(int $length): void
{
if ($length <= 0) {

Check warning on line 443 in src/AbstractTokenizer.php

GitHub Actions / PHP 8-sqlite-ubuntu-latest

Escaped Mutant for Mutator "LessThanOrEqualTo": --- Original +++ New @@ @@ */ private function advance(int $length) : void { - if ($length <= 0) { + if ($length < 0) { throw new InvalidArgumentException('Length must be greater than 0.'); } $this->offset += $length;
throw new InvalidArgumentException('Length must be greater than 0.');
}
*/
private function isEof(): bool
{
return $this->offset >= $this->length;

Check warning on line 456 in src/AbstractTokenizer.php

GitHub Actions / PHP 8-sqlite-ubuntu-latest

Escaped Mutant for Mutator "GreaterThanOrEqualTo": --- Original +++ New @@ @@ */ private function isEof() : bool { - return $this->offset >= $this->length; + return $this->offset > $this->length; } }
}
}
public function asString(): string
{
$format = match ($this->getTypeCategory()) {

Check warning on line 38 in src/Column.php

GitHub Actions / PHP 8-sqlite-ubuntu-latest

Escaped Mutant for Mutator "MatchArmRemoval": --- Original +++ New @@ @@ public function asString() : string { $format = match ($this->getTypeCategory()) { - self::TYPE_CATEGORY_PK => '{type}{check}{append}', self::TYPE_CATEGORY_NUMERIC => '{type}{length}{unsigned}{notnull}{unique}{check}{default}{append}', self::TYPE_CATEGORY_UUID => '{type}{notnull}{unique}{default}{check}{comment}{append}', self::TYPE_CATEGORY_UUID_PK => '{type}{notnull}{default}{check}{comment}{append}',
self::TYPE_CATEGORY_PK => '{type}{check}{append}',
self::TYPE_CATEGORY_NUMERIC => '{type}{length}{unsigned}{notnull}{unique}{check}{default}{append}',
self::TYPE_CATEGORY_UUID => '{type}{notnull}{unique}{default}{check}{comment}{append}',