1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace suda\database\statement; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class StatementConfig |
8
|
|
|
{ |
9
|
|
|
const WRITE = 0; |
10
|
|
|
const READ = 1; |
11
|
|
|
|
12
|
|
|
const FETCH_ONE = 0; |
13
|
|
|
const FETCH_ALL = 1; |
14
|
|
|
|
15
|
|
|
const RET_ROWS = 1; |
16
|
|
|
const RET_LAST_INSERT_ID = 2; |
17
|
|
|
const RET_BOOL = 3; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* 语句类型 |
21
|
|
|
* |
22
|
|
|
* @var int|null |
23
|
|
|
*/ |
24
|
|
|
protected $type = null; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* 获取类型 |
28
|
|
|
* |
29
|
|
|
* @var int |
30
|
|
|
*/ |
31
|
|
|
protected $fetch = null; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* 滚动 |
35
|
|
|
* |
36
|
|
|
* @var boolean|null |
37
|
|
|
*/ |
38
|
|
|
protected $scroll = null; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* 返回类型 |
43
|
|
|
* |
44
|
|
|
* @var int |
45
|
|
|
*/ |
46
|
|
|
protected $returnType = self::RET_BOOL; |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return bool |
52
|
|
|
*/ |
53
|
|
|
public function isRead(): bool |
54
|
|
|
{ |
55
|
|
|
return $this->type === self::READ; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
|
|
public function isWrite(): bool |
62
|
|
|
{ |
63
|
|
|
return $this->type === self::WRITE; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* 判断是否为一条 |
68
|
|
|
* |
69
|
|
|
* @param bool|null $set |
70
|
|
|
* @return boolean |
71
|
|
|
*/ |
72
|
|
|
public function isFetchOne(bool $set = null): bool |
73
|
|
|
{ |
74
|
|
|
if ($set !== null) { |
75
|
|
|
$this->fetch = self::FETCH_ONE; |
76
|
|
|
} |
77
|
|
|
return $this->fetch === self::FETCH_ONE; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* 判断是否为一条 |
82
|
|
|
* |
83
|
|
|
* @return boolean |
84
|
|
|
*/ |
85
|
|
|
public function isFetch(): bool |
86
|
|
|
{ |
87
|
|
|
return $this->fetch !== null; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param bool|null $scroll |
92
|
|
|
*/ |
93
|
|
|
public function setScroll(?bool $scroll): void |
94
|
|
|
{ |
95
|
|
|
$this->scroll = $scroll; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* 判断是否获取多条 |
100
|
|
|
* |
101
|
|
|
* @param bool|null $set |
102
|
|
|
* @return boolean |
103
|
|
|
*/ |
104
|
|
|
public function isFetchAll(bool $set = null): bool |
105
|
|
|
{ |
106
|
|
|
if ($set !== null) { |
107
|
|
|
$this->fetch = self::FETCH_ALL; |
108
|
|
|
} |
109
|
|
|
return $this->fetch === self::FETCH_ALL; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* 是否滚动 |
115
|
|
|
* |
116
|
|
|
* @param bool|null $set |
117
|
|
|
* @return boolean|null |
118
|
|
|
*/ |
119
|
|
|
public function isScroll(bool $set = null): ?bool |
120
|
|
|
{ |
121
|
|
|
if ($set !== null) { |
122
|
|
|
$this->scroll = true; |
123
|
|
|
} |
124
|
|
|
return $this->scroll; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get 返回类型 |
130
|
|
|
* |
131
|
|
|
* @return int |
132
|
|
|
*/ |
133
|
|
|
public function getReturnType() |
134
|
|
|
{ |
135
|
|
|
return $this->returnType; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Set 返回类型 |
140
|
|
|
* |
141
|
|
|
* @param int $returnType 返回类型 |
142
|
|
|
* @return $this |
143
|
|
|
*/ |
144
|
|
|
public function setReturnType(int $returnType) |
145
|
|
|
{ |
146
|
|
|
$this->returnType = $returnType; |
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param int|null $type |
152
|
|
|
*/ |
153
|
|
|
public function setType(?int $type): void |
154
|
|
|
{ |
155
|
|
|
$this->type = $type; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return int |
160
|
|
|
*/ |
161
|
|
|
public function getFetch(): int |
162
|
|
|
{ |
163
|
|
|
return $this->fetch; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return int|null |
168
|
|
|
*/ |
169
|
|
|
public function getType(): ?int |
170
|
|
|
{ |
171
|
|
|
return $this->type; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param int $fetch |
176
|
|
|
*/ |
177
|
|
|
public function setFetch(int $fetch): void |
178
|
|
|
{ |
179
|
|
|
$this->fetch = $fetch; |
180
|
|
|
} |
181
|
|
|
} |