Skip to content

Commit

Permalink
Move methods from command to abstract pdo command (#309)
Browse files Browse the repository at this point in the history
* Move methods from `Command` to `AbstractPdoCommand` class

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
Tigrov and StyleCIBot authored Nov 7, 2023
1 parent dcb2370 commit a289698
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Chg #297: Remove `QueryBuilder::getColumnType()` child method as legacy code (@Tigrov)
- Enh #300: Refactor insert default values (@Tigrov)
- Bug #302: Refactor `DMLQueryBuilder`, related with yiisoft/db#746 (@Tigrov)
- Enh #309: Move methods from `Command` to `AbstractPdoCommand` class (@Tigrov)

## 1.0.1 July 24, 2023

Expand Down
46 changes: 0 additions & 46 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

namespace Yiisoft\Db\Mysql;

use PDOException;
use Throwable;
use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand;
use Yiisoft\Db\Exception\ConvertException;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;

/**
* Implements a database command that can be executed with a PDO (PHP Data Object) database connection for MySQL,
Expand Down Expand Up @@ -51,46 +47,4 @@ public function showDatabases(): array

return $this->setSql($sql)->queryColumn();
}

protected function getQueryBuilder(): QueryBuilderInterface
{
return $this->db->getQueryBuilder();
}

/**
* @psalm-suppress UnusedClosureParam
*
* @throws Throwable
*/
protected function internalExecute(string|null $rawSql): void
{
$attempt = 0;

while (true) {
try {
if (
++$attempt === 1
&& $this->isolationLevel !== null
&& $this->db->getTransaction() === null
) {
$this->db->transaction(
function () use ($rawSql): void {
$this->internalExecute($rawSql);
},
$this->isolationLevel,
);
} else {
$this->pdoStatement?->execute();
}
break;
} catch (PDOException $e) {
$rawSql = $rawSql ?: $this->getRawSql();
$e = (new ConvertException($e, $rawSql))->run();

if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
throw $e;
}
}
}
}
}

0 comments on commit a289698

Please sign in to comment.