-
Notifications
You must be signed in to change notification settings - Fork 2
/
Insert.php
262 lines (217 loc) · 4.13 KB
/
Insert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
namespace Harp\Query;
use Harp\Query\Compiler;
use Harp\Query\SQL;
/**
* @author Ivan Kerin <ikerin@gmail.com>
* @copyright (c) 2014 Clippings Ltd.
* @license http://spdx.org/licenses/BSD-3-Clause
*/
class Insert extends AbstractQuery
{
/**
* @var SQL\Aliased|null
*/
protected $table;
/**
* @var SQL\Columns|null
*/
protected $columns;
/**
* @var SQL\Set[]|null
*/
protected $set;
/**
* @var SQL\Values[]|null
*/
protected $values;
/**
* @var Select|null
*/
protected $select;
/**
* @return SQL\Aliased|null
*/
public function getTable()
{
return $this->table;
}
/**
* @param SQL\Aliased $table
*/
public function setTable(SQL\Aliased $table)
{
$this->table = $table;
return $this;
}
/**
* @return Insert $this
*/
public function clearTable()
{
$this->table = null;
return $this;
}
/**
* @return SQL\Columns|null
*/
public function getColumns()
{
return $this->columns;
}
/**
* @param SQL\Columns $columns
*/
public function setColumns(SQL\Columns $columns)
{
$this->columns = $columns;
return $this;
}
/**
* @return Insert
*/
public function clearColumns()
{
$this->columns = null;
return $this;
}
/**
* @return SQL\Values[]|null
*/
public function getValues()
{
return $this->values;
}
/**
* @param SQL\Values[] $values
*/
public function setValues(array $values)
{
$this->values = $values;
return $this;
}
/**
* @return Insert $this
*/
public function clearValues()
{
$this->values = null;
return $this;
}
/**
* @return SQL\Set[]|null
*/
public function getSet()
{
return $this->set;
}
/**
* @param SQL\Set[] $set
*/
public function setSet(array $set)
{
$this->set = $set;
return $this;
}
/**
* @return Insert $this
*/
public function clearSet()
{
$this->set = null;
return $this;
}
/**
* @return Select|null
*/
public function getSelect()
{
return $this->select;
}
/**
* @param Select $select
*/
public function setSelect(Select $select)
{
$this->select = $select;
return $this;
}
/**
* @return Insert
*/
public function clearSelect()
{
$this->select = null;
return $this;
}
/**
* @param string $table
* @return Insert $this
*/
public function into($table)
{
$this->table = new SQL\Aliased($table);
return $this;
}
/**
* @param array $columns
* @return Insert $this
*/
public function columns(array $columns)
{
$this->columns = new SQL\Columns($columns);
return $this;
}
/**
* @param array $values
* @return Insert $this
*/
public function values(array $values)
{
$this->values []= new SQL\Values($values);
return $this;
}
/**
* @param array $values
* @return Insert $this
*/
public function set(array $values)
{
foreach ($values as $column => $value) {
$this->set []= new SQL\Set($column, $value);
}
return $this;
}
/**
* @param Select $select
* @return Insert $this
*/
public function select(Select $select)
{
$this->select = $select;
return $this;
}
/**
* Calls lastInsertId method on the parent PDO object
*
* @return string
*/
public function getLastInsertId()
{
return $this->getDb()->getLastInsertId();
}
/**
* @return string
*/
public function sql()
{
return Compiler\Insert::render($this);
}
/**
* @return array
*/
public function getParameters()
{
return Compiler\Insert::parameters($this);
}
}