Files
zhamao-framework/src/ZM/Store/Database/DBStatementWrapper.php

238 lines
5.1 KiB
PHP
Raw Normal View History

2022-08-21 16:08:20 +08:00
<?php
/**
* @noinspection PhpMissingReturnTypeInspection
* @noinspection PhpUnused
*/
declare(strict_types=1);
namespace ZM\Store\Database;
2022-08-21 16:08:20 +08:00
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\ForwardCompatibility\Result;
class DBStatementWrapper
2022-08-21 16:08:20 +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();
} catch (\Throwable $e) {
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();
} catch (\Throwable $e) {
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();
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
2022-08-21 16:08:20 +08:00
}
}
/**
* wrapper method
* @throws DBException
2022-08-21 16:08:20 +08:00
*/
public function fetchAllNumeric(): array
{
try {
return $this->stmt->fetchAllNumeric();
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
2022-08-21 16:08:20 +08:00
}
}
/**
* wrapper method
* @throws DBException
2022-08-21 16:08:20 +08:00
*/
public function fetchAllAssociative(): array
{
try {
return $this->stmt->fetchAllAssociative();
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
2022-08-21 16:08:20 +08:00
}
}
/**
* wrapper method
* @throws DBException
2022-08-21 16:08:20 +08:00
*/
public function fetchAllKeyValue(): array
{
try {
return $this->stmt->fetchAllKeyValue();
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
2022-08-21 16:08:20 +08:00
}
}
/**
* wrapper method
* @throws DBException
2022-08-21 16:08:20 +08:00
*/
public function fetchAllAssociativeIndexed(): array
{
try {
return $this->stmt->fetchAllAssociativeIndexed();
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
2022-08-21 16:08:20 +08:00
}
}
/**
* wrapper method
* @throws DBException
2022-08-21 16:08:20 +08:00
*/
public function fetchFirstColumn(): array
{
try {
return $this->stmt->fetchFirstColumn();
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
2022-08-21 16:08:20 +08:00
}
}
/**
* wrapper method
* @throws DBException
2022-08-21 16:08:20 +08:00
*/
public function iterateNumeric(): \Traversable
2022-08-21 16:08:20 +08:00
{
try {
return $this->stmt->iterateNumeric();
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
2022-08-21 16:08:20 +08:00
}
}
/**
* wrapper method
* @throws DBException
2022-08-21 16:08:20 +08:00
*/
public function iterateAssociative(): \Traversable
2022-08-21 16:08:20 +08:00
{
try {
return $this->stmt->iterateAssociative();
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
2022-08-21 16:08:20 +08:00
}
}
/**
* wrapper method
* @throws DBException
2022-08-21 16:08:20 +08:00
*/
public function iterateKeyValue(): \Traversable
2022-08-21 16:08:20 +08:00
{
try {
return $this->stmt->iterateKeyValue();
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
2022-08-21 16:08:20 +08:00
}
}
/**
* wrapper method
* @throws DBException
2022-08-21 16:08:20 +08:00
*/
public function iterateAssociativeIndexed(): \Traversable
2022-08-21 16:08:20 +08:00
{
try {
return $this->stmt->iterateAssociativeIndexed();
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
2022-08-21 16:08:20 +08:00
}
}
/**
* wrapper method
* @throws DBException
2022-08-21 16:08:20 +08:00
*/
public function iterateColumn(): \Traversable
2022-08-21 16:08:20 +08:00
{
try {
return $this->stmt->iterateColumn();
} catch (\Throwable $e) {
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();
} catch (\Throwable $e) {
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();
}
}