Skip to content

Commit

Permalink
修改DB事务回滚BUG (swoft-cloud/swoft-component#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo authored and huangzhhui committed Aug 9, 2018
1 parent c51130a commit 00eee11
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Driver/Mysql/MysqlConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ public function execute(array $params = [])
public function receive()
{
$result = $this->connection->recv();
$this->recv = true;

if ($result === false) {
throw new MysqlException('Mysql recv error,connectError=' . $this->connection->connect_error . ' error=' . $this->connection->error);
}
$this->connection->setDefer(false);

$this->recv = true;
$this->result = $result;

return $result;
Expand Down
31 changes: 31 additions & 0 deletions test/Cases/Mysql/SqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,35 @@ public function testUpdateByCo($id)
$this->testUpdate($id);
});
}

public function testErrorSql()
{
Db::beginTransaction();

try {
$user = new User();
$user->setName('limx');
$user->setSex(1);
$user->setAge(27);
$user->setDesc('Swoft');
$id = $user->save()->getResult();

$sql = 'SELECT des FROM `user` WHERE id = ?';
$res = Db::query($sql, [$id])->getResult();
$this->assertTrue(false);
Db::commit();
} catch (\Exception $ex) {
Db::rollback();

$user = User::findById($id)->getResult();
$this->assertNull($user);
}
}

public function testErrorSqlByCo()
{
go(function () {
$this->testErrorSql();
});
}
}

0 comments on commit 00eee11

Please sign in to comment.