Skip to content

Commit

Permalink
修复判断事务时Db实例错误 (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
NHZEX authored Jun 7, 2023
1 parent 47a8130 commit 80d1c6f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Db/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public function setOption($option): self
*/
public function getDb(): IDb
{
if (!$this->isInitDb)
{
$this->db = Db::getInstance($this->poolName, $this->queryType);
}

return $this->db;
}

Expand Down Expand Up @@ -886,15 +891,7 @@ protected function executeEx(string $sql, string $resultClass)
{
try
{
$db = &$this->db;
if (!$this->isInitDb)
{
$db = Db::getInstance($this->poolName, $this->queryType);
}
if (!$db)
{
return new $resultClass(false);
}
$db = $this->getDb();
$stmt = $db->prepare($sql);
$binds = $this->binds;
$this->binds = [];
Expand Down Expand Up @@ -971,7 +968,12 @@ public function setFieldDec(string $fieldName, float $decValue = 1): self
*/
protected function isInTransaction(): bool
{
return QueryType::WRITE === $this->queryType && Db::getInstance($this->poolName)->inTransaction();
if (QueryType::WRITE !== $this->queryType)
{
return false;
}

return $this->getDb()->inTransaction();
}

/**
Expand Down

0 comments on commit 80d1c6f

Please sign in to comment.