Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/BaseTokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* ```php
* $tokenizer = new SqlTokenizer("SELECT * FROM user WHERE id = 1");
* $root = $tokeinzer->tokenize();
* $root = $tokenizer->tokenize();
* $sqlTokens = $root->getChildren();
* ```
*
Expand Down Expand Up @@ -57,11 +57,11 @@ abstract class BaseTokenizer
private SplStack $tokenStack;

/**
* @var SqlToken|SqlToken[] active token. It's usually a top of the token stack.
* @psalm-var SqlToken|SqlToken[] active token. It's usually a top of the token stack.
*
* @psalm-suppress PropertyNotSetInConstructor
*/
private $currentToken;
private array|SqlToken $currentToken;

/**
* @var string[] cached substrings.
Expand Down Expand Up @@ -223,7 +223,7 @@ public function setSql(string $sql): void
* Returns whether the longest common prefix equals to the SQL code of the same length at the current offset.
*
* @param array $with strings to be tested. The method `will` modify this parameter to speed up lookups.
* @param bool $caseSensitive whether to perform a case sensitive comparison.
* @param bool $caseSensitive whether to perform a case-sensitive comparison.
* @param int $length length of the matched string.
* @param string|null $content matched string.
*
Expand Down Expand Up @@ -272,7 +272,7 @@ protected function startsWithAnyLongest(
* Returns a string of the given length starting with the specified offset.
*
* @param int $length string length to be returned.
* @param bool $caseSensitive if it's `false`, the string will be uppercased.
* @param bool $caseSensitive if it's `false`, the string will be uppercase.
* @param int|null $offset SQL code offset, defaults to current if `null` is passed.
*
* @return string result string, it may be empty if there's nothing to return.
Expand Down
15 changes: 5 additions & 10 deletions src/ColumnSchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@ protected function buildUnsignedString(): string

public function __toString(): string
{
switch ($this->getTypeCategory()) {
case self::CATEGORY_PK:
$format = '{type}{check}{append}';
break;
case self::CATEGORY_NUMERIC:
$format = '{type}{length}{unsigned}{notnull}{unique}{check}{default}{append}';
break;
default:
$format = '{type}{length}{notnull}{unique}{check}{default}{append}';
}
$format = match ($this->getTypeCategory()) {
self::CATEGORY_PK => '{type}{check}{append}',
self::CATEGORY_NUMERIC => '{type}{length}{unsigned}{notnull}{unique}{check}{default}{append}',
default => '{type}{length}{notnull}{unique}{check}{default}{append}',
};

return $this->buildCompleteString($format);
}
Expand Down
26 changes: 17 additions & 9 deletions src/Condition/InConditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Query\Conditions\InConditionBuilder as BaseInConditionBuilder;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\Query\QueryBuilderInterface;

use function implode;
use function is_array;
use function strpos;
use function str_contains;

final class InConditionBuilder extends BaseInConditionBuilder
{
Expand All @@ -29,15 +29,19 @@ public function __construct(private QueryBuilderInterface $queryBuilder)
*
* @param string $operator
* @param array|string $columns
* @param Query $values
* @param ExpressionInterface $values
* @param array $params
*
* @throws Exception|InvalidArgumentException|InvalidConfigException|NotSupportedException
*
* @return string SQL.
*/
protected function buildSubqueryInCondition(string $operator, $columns, Query $values, array &$params = []): string
{
protected function buildSubqueryInCondition(
string $operator,
array|string $columns,
ExpressionInterface $values,
array &$params = []
): string {
if (is_array($columns)) {
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}
Expand All @@ -55,13 +59,17 @@ protected function buildSubqueryInCondition(string $operator, $columns, Query $v
*
* @return string SQL.
*/
protected function buildCompositeInCondition(?string $operator, $columns, $values, array &$params = []): string
{
protected function buildCompositeInCondition(
?string $operator,
Traversable|array $columns,
$values,
array &$params = []
): string {
$quotedColumns = [];

/** @psalm-var array<array-key, string>|Traversable $columns */
/** @psalm-var string[]|Traversable $columns */
foreach ($columns as $i => $column) {
$quotedColumns[$i] = strpos($column, '(') === false
$quotedColumns[$i] = !str_contains($column, '(')
? $this->queryBuilder->quoter()->quoteColumnName($column) : $column;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Condition/LikeConditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class LikeConditionBuilder extends BaseLikeConditionBuilder
{
protected ?string $escapeCharacter = '\\';

public function __construct(private QueryBuilderInterface $queryBuilder)
public function __construct(QueryBuilderInterface $queryBuilder)
{
parent::__construct($queryBuilder);
}
Expand Down
50 changes: 50 additions & 0 deletions src/DDLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Yiisoft\Db\Sqlite;

use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Query\DDLQueryBuilder as AbstractDDLQueryBuilder;
use Yiisoft\Db\Query\QueryBuilderInterface;
Expand All @@ -15,21 +17,33 @@ public function __construct(private QueryBuilderInterface $queryBuilder)
parent::__construct($queryBuilder);
}

/**
* @throws NotSupportedException
*/
public function addCheck(string $name, string $table, string $expression): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function addCommentOnColumn(string $table, string $column, string $comment): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function addCommentOnTable(string $table, string $comment): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function addForeignKey(
string $name,
string $table,
Expand All @@ -42,16 +56,25 @@ public function addForeignKey(
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function addPrimaryKey(string $name, string $table, array|string $columns): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function addUnique(string $name, string $table, array|string $columns): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function alterColumn(string $table, string $column, string $type): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
Expand All @@ -62,6 +85,9 @@ public function checkIntegrity(string $schema = '', string $table = '', bool $ch
return 'PRAGMA foreign_keys=' . (int) $check;
}

/**
* @throws Exception|InvalidArgumentException
*/
public function createIndex(string $name, string $table, array|string $columns, bool $unique = false): string
{
$tableParts = explode('.', $table);
Expand All @@ -78,26 +104,41 @@ public function createIndex(string $name, string $table, array|string $columns,
. ' (' . $this->queryBuilder->buildColumns($columns) . ')';
}

/**
* @throws NotSupportedException
*/
public function dropCheck(string $name, string $table): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function dropColumn(string $table, string $column): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function dropCommentFromColumn(string $table, string $column): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function dropCommentFromTable(string $table): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function dropForeignKey(string $name, string $table): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
Expand All @@ -108,16 +149,25 @@ public function dropIndex(string $name, string $table): string
return 'DROP INDEX ' . $this->queryBuilder->quoter()->quoteTableName($name);
}

/**
* @throws NotSupportedException
*/
public function dropPrimaryKey(string $name, string $table): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function dropUnique(string $name, string $table): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
}

/**
* @throws NotSupportedException
*/
public function renameColumn(string $table, string $oldName, string $newName): string
{
throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
Expand Down
13 changes: 12 additions & 1 deletion src/DMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

namespace Yiisoft\Db\Sqlite;

use InvalidArgumentException;
use JsonException;
use Throwable;
use Yiisoft\Db\Constraint\Constraint;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Query\DMLQueryBuilder as AbstractDMLQueryBuilder;
Expand All @@ -19,6 +24,9 @@ public function __construct(private QueryBuilderInterface $queryBuilder)
parent::__construct($queryBuilder);
}

/**
* @throws Exception|Throwable
*/
public function resetSequence(string $tableName, mixed $value = null): string
{
$table = $this->queryBuilder->schema()->getTableSchema($tableName);
Expand All @@ -43,6 +51,9 @@ public function resetSequence(string $tableName, mixed $value = null): string
throw new InvalidArgumentException("There is not sequence associated with table '$tableName'.'");
}

/**
* @throws Exception|InvalidArgumentException|InvalidConfigException|JsonException|NotSupportedException
*/
public function upsert(string $table, Query|array $insertColumns, bool|array $updateColumns, array &$params): string
{
/** @var Constraint[] $constraints */
Expand Down
3 changes: 3 additions & 0 deletions src/PDO/ConnectionPDOSqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public function getPDO(): ?PDO
return $this->pdo;
}

/**
* @throws Exception|InvalidConfigException
*/
public function getQueryBuilder(): QueryBuilderInterface
{
if ($this->queryBuilder === null) {
Expand Down
Loading