2021-07-09 01:38:30 +08:00
|
|
|
<?php
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2021-09-01 14:14:00 +08:00
|
|
|
/**
|
|
|
|
|
* @noinspection PhpUnused
|
|
|
|
|
*/
|
2021-07-09 01:38:30 +08:00
|
|
|
|
|
|
|
|
namespace ZM\MySQL;
|
|
|
|
|
|
2021-09-01 14:14:00 +08:00
|
|
|
use Closure;
|
|
|
|
|
use Doctrine\DBAL\Cache\QueryCacheProfile;
|
|
|
|
|
use Doctrine\DBAL\Connection;
|
|
|
|
|
use Doctrine\DBAL\DriverManager;
|
|
|
|
|
use Doctrine\DBAL\ParameterType;
|
|
|
|
|
use Throwable;
|
|
|
|
|
use Traversable;
|
|
|
|
|
use ZM\Exception\DbException;
|
2021-07-09 01:38:30 +08:00
|
|
|
|
|
|
|
|
class MySQLWrapper
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
private $connection;
|
2021-07-09 01:38:30 +08:00
|
|
|
|
2021-09-01 14:14:00 +08:00
|
|
|
/**
|
|
|
|
|
* MySQLWrapper constructor.
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
2022-03-15 18:05:33 +08:00
|
|
|
$this->connection = DriverManager::getConnection(['driverClass' => MySQLDriver::class]);
|
2021-09-01 14:14:00 +08:00
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
public function __destruct()
|
|
|
|
|
{
|
|
|
|
|
$this->connection->close();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 14:14:00 +08:00
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function getDatabase(): string
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->getDatabase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function isAutoCommit(): bool
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->isAutoCommit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $autoCommit
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function setAutoCommit($autoCommit)
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
$this->connection->setAutoCommit($autoCommit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
2022-03-15 18:05:33 +08:00
|
|
|
* @return array|false
|
2021-09-01 14:14:00 +08:00
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function fetchAssociative(string $query, array $params = [], array $types = [])
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->fetchAssociative($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
2022-03-15 18:05:33 +08:00
|
|
|
* @return array|false
|
2021-09-01 14:14:00 +08:00
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function fetchNumeric(string $query, array $params = [], array $types = [])
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->fetchNumeric($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws DbException
|
2022-03-15 18:05:33 +08:00
|
|
|
* @return false|mixed
|
2021-09-01 14:14:00 +08:00
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function fetchOne(string $query, array $params = [], array $types = [])
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->fetchOne($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function isTransactionActive(): bool
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->isTransactionActive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $table
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function delete($table, array $criteria, array $types = []): int
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->delete($table, $criteria, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $level
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function setTransactionIsolation($level): int
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->setTransactionIsolation($level);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function getTransactionIsolation(): ?int
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->getTransactionIsolation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $table
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function update($table, array $data, array $criteria, array $types = []): int
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->update($table, $data, $criteria, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $table
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function insert($table, array $data, array $types = []): int
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->insert($table, $data, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $str
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function quoteIdentifier($str): string
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->quoteIdentifier($str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $value
|
2022-03-15 18:05:33 +08:00
|
|
|
* @param int $type
|
2021-09-01 14:14:00 +08:00
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function quote($value, $type = ParameterType::STRING)
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->quote($value, $type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function fetchAllNumeric(string $query, array $params = [], array $types = []): array
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->fetchAllNumeric($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function fetchAllAssociative(string $query, array $params = [], array $types = []): array
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->fetchAllAssociative($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function fetchAllKeyValue(string $query, array $params = [], array $types = []): array
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->fetchAllKeyValue($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function fetchAllAssociativeIndexed(string $query, array $params = [], array $types = []): array
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->fetchAllAssociativeIndexed($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function fetchFirstColumn(string $query, array $params = [], array $types = []): array
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->fetchFirstColumn($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function iterateNumeric(string $query, array $params = [], array $types = []): Traversable
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->iterateNumeric($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function iterateAssociative(string $query, array $params = [], array $types = []): Traversable
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->iterateAssociative($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function iterateKeyValue(string $query, array $params = [], array $types = []): Traversable
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->iterateKeyValue($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function iterateAssociativeIndexed(string $query, array $params = [], array $types = []): Traversable
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->iterateAssociativeIndexed($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function iterateColumn(string $query, array $params = [], array $types = []): Traversable
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->iterateColumn($query, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $sql
|
2022-03-15 18:05:33 +08:00
|
|
|
* @param array $types
|
2021-09-01 14:14:00 +08:00
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheProfile $qcp = null): MySQLStatementWrapper
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
$query = $this->connection->executeQuery($sql, $params, $types, $qcp);
|
|
|
|
|
return new MySQLStatementWrapper($query);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $sql
|
|
|
|
|
* @param $params
|
|
|
|
|
* @param $types
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp): MySQLStatementWrapper
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
$query = $this->connection->executeCacheQuery($sql, $params, $types, $qcp);
|
|
|
|
|
return new MySQLStatementWrapper($query);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $sql
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function executeStatement($sql, array $params = [], array $types = []): int
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->executeStatement($sql, $params, $types);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function getTransactionNestingLevel(): int
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->getTransactionNestingLevel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param null $name
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function lastInsertId($name = null): string
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->lastInsertId($name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* overwrite method to $this->connection->transactional()
|
|
|
|
|
* @throws DbException
|
2022-03-15 18:05:33 +08:00
|
|
|
* @return mixed
|
2021-09-01 14:14:00 +08:00
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function transactional(Closure $func)
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
$this->beginTransaction();
|
|
|
|
|
try {
|
|
|
|
|
$res = $func($this);
|
|
|
|
|
$this->commit();
|
|
|
|
|
return $res;
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
$this->rollBack();
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $nestTransactionsWithSavepoints
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints)
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
$this->connection->setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function getNestTransactionsWithSavepoints(): bool
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->getNestTransactionsWithSavepoints();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function beginTransaction(): bool
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection->beginTransaction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function commit(): bool
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->commit();
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function rollBack(): bool
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->rollBack();
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $savepoint
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function createSavepoint($savepoint)
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
$this->connection->createSavepoint($savepoint);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $savepoint
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function releaseSavepoint($savepoint)
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
$this->connection->releaseSavepoint($savepoint);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @param $savepoint
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function rollbackSavepoint($savepoint)
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
$this->connection->rollbackSavepoint($savepoint);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function setRollbackOnly()
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
$this->connection->setRollbackOnly();
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function isRollbackOnly(): bool
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
try {
|
|
|
|
|
return $this->connection->isRollbackOnly();
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* overwrite method to $this->connection->createQueryBuilder
|
|
|
|
|
*/
|
2022-03-15 18:05:33 +08:00
|
|
|
public function createQueryBuilder(): MySQLQueryBuilder
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return new MySQLQueryBuilder($this);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
public function getConnection(): Connection
|
|
|
|
|
{
|
2021-09-01 14:14:00 +08:00
|
|
|
return $this->connection;
|
2021-07-09 01:38:30 +08:00
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
}
|