Skip to content

Commit

Permalink
Fix Statement instance creation in Sqlserver driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Apr 7, 2024
1 parent 7c311e7 commit f76adfa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
18 changes: 15 additions & 3 deletions src/Database/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,29 @@ public function prepare(Query|string $query): StatementInterface
);
}

$decorators = [];
/** @var \Cake\Database\StatementInterface */
return new (static::STATEMENT_CLASS)($statement, $this, $this->getResultSetDecorators($query));
}

/**
* Returns the decorators to be applied to the result set incase of a SelectQuery.
*
* @param \Cake\Database\Query|string $query The query to be decorated.
* @return array<\Closure>
*/
protected function getResultSetDecorators(Query|string $query): array
{
if ($query instanceof SelectQuery) {
$decorators = $query->getResultDecorators();
if ($query->isResultsCastingEnabled()) {
$typeConverter = new FieldTypeConverter($query->getSelectTypeMap(), $this);
array_unshift($decorators, Closure::fromCallable($typeConverter));
}

return $decorators;
}

/** @var \Cake\Database\StatementInterface */
return new (static::STATEMENT_CLASS)($statement, $this, $decorators);
return [];
}

/**
Expand Down
7 changes: 1 addition & 6 deletions src/Database/Driver/Sqlserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,8 @@ public function prepare(Query|string $query): StatementInterface
]
);

$typeMap = null;
if ($query instanceof SelectQuery && $query->isResultsCastingEnabled()) {
$typeMap = $query->getSelectTypeMap();
}

/** @var \Cake\Database\StatementInterface */
return new (static::STATEMENT_CLASS)($statement, $this, $typeMap);
return new (static::STATEMENT_CLASS)($statement, $this, $this->getResultSetDecorators($query));
}

/**
Expand Down

0 comments on commit f76adfa

Please sign in to comment.