2022-08-21 16:08:20 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @noinspection PhpMissingReturnTypeInspection
|
|
|
|
|
* @noinspection PhpUnused
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2022-08-27 19:45:23 +08:00
|
|
|
namespace ZM\Store\Database;
|
2022-08-21 16:08:20 +08:00
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Driver\ResultStatement;
|
|
|
|
|
use Doctrine\DBAL\ForwardCompatibility\Result;
|
|
|
|
|
|
2022-08-27 19:45:23 +08:00
|
|
|
class DBStatementWrapper
|
2022-08-21 16:08:20 +08:00
|
|
|
{
|
2022-08-27 19:45:23 +08:00
|
|
|
public ?Result $stmt;
|
2022-08-21 16:08:20 +08:00
|
|
|
|
|
|
|
|
public function __construct(?Result $stmt)
|
|
|
|
|
{
|
|
|
|
|
$this->stmt = $stmt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取结果的迭代器
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @return ResultStatement
|
|
|
|
|
*/
|
|
|
|
|
public function getIterator()
|
|
|
|
|
{
|
|
|
|
|
return $this->stmt->getIterator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取列数
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function columnCount()
|
|
|
|
|
{
|
|
|
|
|
return $this->stmt->columnCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @return array|false|mixed
|
2022-09-09 18:59:46 +08:00
|
|
|
*@throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
|
|
|
|
public function fetchNumeric()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->fetchNumeric();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @return array|false|mixed
|
2022-09-09 18:59:46 +08:00
|
|
|
*@throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
|
|
|
|
public function fetchAssociative()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->fetchAssociative();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @return false|mixed
|
2022-09-09 18:59:46 +08:00
|
|
|
*@throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
|
|
|
|
public function fetchOne()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->fetchOne();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
2022-08-27 19:45:23 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
|
|
|
|
public function fetchAllNumeric(): array
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->fetchAllNumeric();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
2022-08-27 19:45:23 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
|
|
|
|
public function fetchAllAssociative(): array
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->fetchAllAssociative();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
2022-08-27 19:45:23 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
|
|
|
|
public function fetchAllKeyValue(): array
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->fetchAllKeyValue();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
2022-08-27 19:45:23 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
|
|
|
|
public function fetchAllAssociativeIndexed(): array
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->fetchAllAssociativeIndexed();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
2022-08-27 19:45:23 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
|
|
|
|
public function fetchFirstColumn(): array
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->fetchFirstColumn();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
2022-08-27 19:45:23 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
2022-11-03 10:18:17 +08:00
|
|
|
public function iterateNumeric(): \Traversable
|
2022-08-21 16:08:20 +08:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->iterateNumeric();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
2022-08-27 19:45:23 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
2022-11-03 10:18:17 +08:00
|
|
|
public function iterateAssociative(): \Traversable
|
2022-08-21 16:08:20 +08:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->iterateAssociative();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
2022-08-27 19:45:23 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
2022-11-03 10:18:17 +08:00
|
|
|
public function iterateKeyValue(): \Traversable
|
2022-08-21 16:08:20 +08:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->iterateKeyValue();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
2022-08-27 19:45:23 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
2022-11-03 10:18:17 +08:00
|
|
|
public function iterateAssociativeIndexed(): \Traversable
|
2022-08-21 16:08:20 +08:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->iterateAssociativeIndexed();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
2022-08-27 19:45:23 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
2022-11-03 10:18:17 +08:00
|
|
|
public function iterateColumn(): \Traversable
|
2022-08-21 16:08:20 +08:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->iterateColumn();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
* @return int
|
2022-09-09 18:59:46 +08:00
|
|
|
* @throws DBException
|
2022-08-21 16:08:20 +08:00
|
|
|
*/
|
|
|
|
|
public function rowCount()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return $this->stmt->rowCount();
|
2022-11-03 10:18:17 +08:00
|
|
|
} catch (\Throwable $e) {
|
2022-08-27 19:45:23 +08:00
|
|
|
throw new DBException($e->getMessage(), $e->getCode(), $e);
|
2022-08-21 16:08:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper method
|
|
|
|
|
*/
|
|
|
|
|
public function free(): void
|
|
|
|
|
{
|
|
|
|
|
$this->stmt->free();
|
|
|
|
|
}
|
|
|
|
|
}
|