Skip to content

Commit

Permalink
Return and deprecate getTypecastValue() method and $table parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Oct 31, 2023
1 parent 70cd177 commit ee4b859
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/QueryBuilder/AbstractDMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\Schema\ColumnSchemaInterface;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;

Expand Down Expand Up @@ -55,7 +56,7 @@ public function batchInsert(string $table, array $columns, iterable $rows, array
}

$values = [];
$columns = $this->getNormalizeColumnNames($columns);
$columns = $this->getNormalizeColumnNames('', $columns);
$columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? [];

foreach ($rows as $row) {
Expand Down Expand Up @@ -208,7 +209,7 @@ protected function prepareInsertValues(string $table, array|QueryInterface $colu

$names = [];
$placeholders = [];
$columns = $this->normalizeColumnNames($columns);
$columns = $this->normalizeColumnNames('', $columns);
$columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? [];

foreach ($columns as $name => $value) {
Expand Down Expand Up @@ -241,7 +242,7 @@ protected function prepareInsertValues(string $table, array|QueryInterface $colu
protected function prepareUpdateSets(string $table, array $columns, array $params = []): array
{
$sets = [];
$columns = $this->normalizeColumnNames($columns);
$columns = $this->normalizeColumnNames('', $columns);
$columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? [];

foreach ($columns as $name => $value) {
Expand Down Expand Up @@ -285,7 +286,7 @@ protected function prepareUpsertColumns(
if ($insertColumns instanceof QueryInterface) {
[$insertNames] = $this->prepareInsertSelectSubQuery($insertColumns);
} else {
$insertNames = $this->getNormalizeColumnNames(array_keys($insertColumns));
$insertNames = $this->getNormalizeColumnNames('', array_keys($insertColumns));

$insertNames = array_map(
[$this->quoter, 'quoteColumnName'],
Expand Down Expand Up @@ -386,32 +387,48 @@ static function (Constraint $constraint) use ($quoter, $columns, &$columnNames):
return array_unique($columnNames);
}

/**
* @return mixed The typecast value of the given column.
*
* @deprecated will be removed in version 2.0.0
*/
protected function getTypecastValue(mixed $value, ColumnSchemaInterface $columnSchema = null): mixed
{
if ($columnSchema) {
return $columnSchema->dbTypecast($value);
}

return $value;
}

/**
* Normalizes the column names.
*
* @param string $table Not used. Could be empty string. Will be removed in version 2.0.0.
* @param array $columns The column data (name => value).
*
* @return array The normalized column names (name => value).
*
* @psalm-return array<string, mixed>
*/
protected function normalizeColumnNames(array $columns): array
protected function normalizeColumnNames(string $table, array $columns): array
{
/** @var string[] $columnNames */
$columnNames = array_keys($columns);
$normalizedNames = $this->getNormalizeColumnNames($columnNames);
$normalizedNames = $this->getNormalizeColumnNames('', $columnNames);

return array_combine($normalizedNames, $columns);
}

/**
* Get normalized column names
*
* @param string $table Not used. Could be empty string. Will be removed in version 2.0.0.
* @param string[] $columns The column names.
*
* @return string[] Normalized column names.
*/
protected function getNormalizeColumnNames(array $columns): array
protected function getNormalizeColumnNames(string $table, array $columns): array
{
$normalizedNames = [];

Expand Down

0 comments on commit ee4b859

Please sign in to comment.