Skip to content

Commit

Permalink
fix stan ii
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 22, 2022
1 parent 9c0715a commit 528fc0b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/Persistence/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ protected function insertRaw(Model $model, array $dataRaw)

$insert->setMulti($dataRaw);

$st = null;
try {
$model->hook(self::HOOK_BEFORE_INSERT_QUERY, [$insert]);
$st = $insert->executeStatement();
Expand Down Expand Up @@ -584,7 +583,6 @@ protected function updateRaw(Model $model, $idRaw, array $dataRaw): void

$model->hook(self::HOOK_BEFORE_UPDATE_QUERY, [$update]);

$st = null;
try {
$st = $update->executeStatement();
} catch (SqlException $e) {
Expand Down
22 changes: 17 additions & 5 deletions src/Persistence/Sql/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,29 @@ public function connection()
}

/**
* Execute Expression by using this connection.
* Execute Expression by using this connection and return result.
*/
public function executeQuery(Expression $expr): DbalResult
{
if ($this->connection === null) {
throw new Exception('DBAL connection is not set');
}

return $expr->executeQuery($this->connection);
}

/**
* Execute Expression by using this connection and return affected rows.
*
* @return DbalResult|int
* @phpstan-return int<0, max>
*/
public function execute(Expression $expr, bool $fromExecuteStatement)
public function executeStatement(Expression $expr): int
{
if ($this->connection === null) {
throw new Exception('Queries cannot be executed through this connection');
throw new Exception('DBAL connection is not set');
}

return $expr->execute($this->connection, $fromExecuteStatement);
return $expr->executeStatement($this->connection);
}

/**
Expand Down
24 changes: 18 additions & 6 deletions src/Persistence/Sql/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,18 +531,28 @@ function ($matches) use ($params, &$numParams, &$i, &$j) {
/**
* @param DbalConnection|Connection $connection
*
* @return DbalResult|int
* @return DbalResult|int<0, max>
*
* @deprecated Expression::execute() is deprecated, use Expression::executeQuery() or Expression::executeStatement() instead
* @deprecated Expression::execute() is deprecated and will be removed in v4.0, use Expression::executeQuery() or Expression::executeStatement() instead
*/
public function execute(object $connection = null, bool $fromExecuteStatement)
public function execute(object $connection = null, bool $fromExecuteStatement = null)
{
if ($connection === null) {
$connection = $this->connection;
}

if ($fromExecuteStatement === null) {
'trigger_error'('Method is deprecated. Use executeQuery() or executeStatement() instead', \E_USER_DEPRECATED);

$fromExecuteStatement = false;
}

if (!$connection instanceof DbalConnection) {
return $connection->execute($this, $fromExecuteStatement);
if ($fromExecuteStatement) {
return $connection->executeStatement($this);
}

return $connection->executeQuery($this);
}

[$query, $params] = $this->updateRenderBeforeExecute($this->render());
Expand Down Expand Up @@ -630,15 +640,17 @@ public function execute(object $connection = null, bool $fromExecuteStatement)
*/
public function executeQuery(object $connection = null): DbalResult
{
return $this->execute($connection, false);
return $this->execute($connection, false); // @phpstan-ignore-line
}

/**
* @param DbalConnection|Connection $connection
*
* @phpstan-return int<0, max>
*/
public function executeStatement(object $connection = null): int
{
return $this->execute($connection, true);
return $this->execute($connection, true); // @phpstan-ignore-line
}

// {{{ Result Querying
Expand Down

0 comments on commit 528fc0b

Please sign in to comment.