1 | <?php |
||
21 | class Insert extends AbstractDmlQuery implements InsertInterface |
||
22 | { |
||
23 | /** |
||
24 | * |
||
25 | * The table to insert into. |
||
26 | * |
||
27 | * @var string |
||
28 | * |
||
29 | */ |
||
30 | protected $into; |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | * A map of fully-qualified `table.column` names to last-insert-id names. |
||
35 | * This is used to look up the right last-insert-id name for a given table |
||
36 | * and column. Generally useful only for extended tables in Posgres. |
||
37 | * |
||
38 | * @var array |
||
39 | * |
||
40 | */ |
||
41 | protected $last_insert_id_names; |
||
42 | |||
43 | /** |
||
44 | * |
||
45 | * The current row-number we are adding column values for. This comes into |
||
46 | * play only with bulk inserts. |
||
47 | * |
||
48 | * @var int |
||
49 | * |
||
50 | */ |
||
51 | protected $row = 0; |
||
52 | |||
53 | /** |
||
54 | * |
||
55 | * A collection of `$col_values` for previous rows in bulk inserts. |
||
56 | * |
||
57 | * @var array |
||
58 | * |
||
59 | */ |
||
60 | protected $col_values_bulk = array(); |
||
61 | |||
62 | /** |
||
63 | * |
||
64 | * A collection of `$bind_values` for previous rows in bulk inserts. |
||
65 | * |
||
66 | * @var array |
||
67 | * |
||
68 | */ |
||
69 | protected $bind_values_bulk = array(); |
||
70 | |||
71 | /** |
||
72 | * |
||
73 | * The order in which columns will be bulk-inserted; this is taken from the |
||
74 | * very first inserted row. |
||
75 | * |
||
76 | * @var array |
||
77 | * |
||
78 | */ |
||
79 | protected $col_order = array(); |
||
80 | |||
81 | /** |
||
82 | * |
||
83 | * Sets the map of fully-qualified `table.column` names to last-insert-id |
||
84 | * names. Generally useful only for extended tables in Posgres. |
||
85 | * |
||
86 | * @param array $last_insert_id_names The list of ID names. |
||
87 | * |
||
88 | */ |
||
89 | 76 | public function setLastInsertIdNames(array $last_insert_id_names) |
|
93 | |||
94 | /** |
||
95 | * |
||
96 | * Sets the table to insert into. |
||
97 | * |
||
98 | * @param string $into The table to insert into. |
||
99 | * |
||
100 | * @return $this |
||
101 | * |
||
102 | */ |
||
103 | 56 | public function into($into) |
|
109 | |||
110 | /** |
||
111 | * |
||
112 | * Builds this query object into a string. |
||
113 | * |
||
114 | * @return string |
||
115 | * |
||
116 | */ |
||
117 | 30 | protected function build() |
|
125 | |||
126 | /** |
||
127 | * |
||
128 | * Builds the INTO clause. |
||
129 | * |
||
130 | * @return string |
||
131 | * |
||
132 | */ |
||
133 | 41 | protected function buildInto() |
|
137 | |||
138 | /** |
||
139 | * |
||
140 | * Returns the proper name for passing to `PDO::lastInsertId()`. |
||
141 | * |
||
142 | * @param string $col The last insert ID column. |
||
143 | * |
||
144 | * @return mixed Normally null, since most drivers do not need a name; |
||
145 | * alternatively, a string from `$last_insert_id_names`. |
||
146 | * |
||
147 | */ |
||
148 | 10 | public function getLastInsertIdName($col) |
|
155 | |||
156 | /** |
||
157 | * |
||
158 | * Sets one column value placeholder; if an optional second parameter is |
||
159 | * passed, that value is bound to the placeholder. |
||
160 | * |
||
161 | * @param string $col The column name. |
||
162 | * |
||
163 | * @param mixed,... $val Optional: a value to bind to the placeholder. |
||
164 | * |
||
165 | * @return $this |
||
166 | * |
||
167 | */ |
||
168 | 20 | public function col($col) |
|
172 | |||
173 | /** |
||
174 | * |
||
175 | * Sets multiple column value placeholders. If an element is a key-value |
||
176 | * pair, the key is treated as the column name and the value is bound to |
||
177 | * that column. |
||
178 | * |
||
179 | * @param array $cols A list of column names, optionally as key-value |
||
180 | * pairs where the key is a column name and the value is a bind value for |
||
181 | * that column. |
||
182 | * |
||
183 | * @return $this |
||
184 | * |
||
185 | */ |
||
186 | 46 | public function cols(array $cols) |
|
190 | |||
191 | /** |
||
192 | * |
||
193 | * Sets a column value directly; the value will not be escaped, although |
||
194 | * fully-qualified identifiers in the value will be quoted. |
||
195 | * |
||
196 | * @param string $col The column name. |
||
197 | * |
||
198 | * @param string $value The column value expression. |
||
199 | * |
||
200 | * @return $this |
||
201 | * |
||
202 | */ |
||
203 | 31 | public function set($col, $value) |
|
207 | |||
208 | /** |
||
209 | * |
||
210 | * Gets the values to bind to placeholders. |
||
211 | * |
||
212 | * @return array |
||
213 | * |
||
214 | */ |
||
215 | 31 | public function getBindValues() |
|
219 | |||
220 | /** |
||
221 | * |
||
222 | * Adds multiple rows for bulk insert. |
||
223 | * |
||
224 | * @param array $rows An array of rows, where each element is an array of |
||
225 | * column key-value pairs. The values are bound to placeholders. |
||
226 | * |
||
227 | * @return $this |
||
228 | * |
||
229 | */ |
||
230 | 15 | public function addRows(array $rows) |
|
240 | |||
241 | /** |
||
242 | * |
||
243 | * Add one row for bulk insert; increments the row counter and optionally |
||
244 | * adds columns to the new row. |
||
245 | * |
||
246 | * When adding the first row, the counter is not incremented. |
||
247 | * |
||
248 | * After calling `addRow()`, you can further call `col()`, `cols()`, and |
||
249 | * `set()` to work with the newly-added row. Calling `addRow()` again will |
||
250 | * finish off the current row and start a new one. |
||
251 | * |
||
252 | * @param array $cols An array of column key-value pairs; the values are |
||
253 | * bound to placeholders. |
||
254 | * |
||
255 | * @return $this |
||
256 | * |
||
257 | */ |
||
258 | 30 | public function addRow(array $cols = array()) |
|
273 | |||
274 | /** |
||
275 | * |
||
276 | * Finishes off the current row in a bulk insert, collecting the bulk |
||
277 | * values and resetting for the next row. |
||
278 | * |
||
279 | * @return null |
||
280 | * |
||
281 | */ |
||
282 | 25 | protected function finishRow() |
|
295 | |||
296 | /** |
||
297 | * |
||
298 | * Finishes off a single column of the current row in a bulk insert. |
||
299 | * |
||
300 | * @param string $col The column to finish off. |
||
301 | * |
||
302 | * @return null |
||
303 | * |
||
304 | * @throws Exception on named column missing from row. |
||
305 | * |
||
306 | */ |
||
307 | 25 | protected function finishCol($col) |
|
334 | |||
335 | /** |
||
336 | * |
||
337 | * Builds the inserted columns and values of the statement. |
||
338 | * |
||
339 | * @return string |
||
340 | * |
||
341 | */ |
||
342 | 41 | protected function buildValuesForInsert() |
|
354 | |||
355 | /** |
||
356 | * |
||
357 | * Builds the bulk-inserted columns and values of the statement. |
||
358 | * |
||
359 | * @return string |
||
360 | * |
||
361 | */ |
||
362 | 20 | protected function buildValuesForBulkInsert() |
|
374 | } |
||
375 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.