|
1
|
|
|
<?php |
|
2
|
|
|
namespace suda\database\struct; |
|
3
|
|
|
|
|
4
|
|
|
use ReflectionException; |
|
5
|
|
|
use suda\database\exception\SQLException; |
|
6
|
|
|
use suda\database\statement\QueryAccess; |
|
7
|
|
|
|
|
8
|
|
|
class QueryStatement extends \suda\database\statement\QueryStatement |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* 访问操作 |
|
12
|
|
|
* |
|
13
|
|
|
* @var QueryAccess |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $access; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct(QueryAccess $access, string $query, ...$parameter) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->access = $access; |
|
20
|
|
|
parent::__construct($query, ...$parameter); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* 取1 |
|
25
|
|
|
* |
|
26
|
|
|
* @param string|null $class |
|
27
|
|
|
* @param array $args |
|
28
|
|
|
* @return mixed |
|
29
|
|
|
* @throws SQLException |
|
30
|
|
|
* @throws ReflectionException |
|
31
|
|
|
*/ |
|
32
|
|
|
public function one(?string $class = null, array $args = []) |
|
33
|
|
|
{ |
|
34
|
|
|
$value = $this->access->run($this->wantOne($class, $args)); |
|
35
|
|
|
if (is_array($value)) { |
|
36
|
|
|
return $value; |
|
37
|
|
|
} |
|
38
|
|
|
return null; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* 取全部 |
|
43
|
|
|
* |
|
44
|
|
|
* @param string|null $class |
|
45
|
|
|
* @param array $args |
|
46
|
|
|
* @return array |
|
47
|
|
|
* @throws SQLException |
|
48
|
|
|
* @throws ReflectionException |
|
49
|
|
|
*/ |
|
50
|
|
|
public function all(?string $class = null, array $args = []):array |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->access->run($this->wantAll($class, $args)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* 取1 |
|
57
|
|
|
* |
|
58
|
|
|
* @param string|null $class |
|
59
|
|
|
* @param array $args |
|
60
|
|
|
* @return mixed |
|
61
|
|
|
* @throws SQLException |
|
62
|
|
|
* @throws ReflectionException |
|
63
|
|
|
*/ |
|
64
|
|
|
public function fetch(?string $class = null, array $args = []) |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->one($class, $args); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* 取全部 |
|
71
|
|
|
* |
|
72
|
|
|
* @param string|null $class |
|
73
|
|
|
* @param array $args |
|
74
|
|
|
* @return array |
|
75
|
|
|
* @throws SQLException |
|
76
|
|
|
* @throws ReflectionException |
|
77
|
|
|
*/ |
|
78
|
|
|
public function fetchAll(?string $class = null, array $args = []):array |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->all($class, $args); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get 访问操作 |
|
85
|
|
|
* |
|
86
|
|
|
* @return QueryAccess |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getAccess():QueryAccess |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->access; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|