@@ 22-51 (lines=30) @@ | ||
19 | ||
20 | const QUERY_TEMPLATE = 'REPLACE INTO %s (%s) VALUES %s'; |
|
21 | ||
22 | protected function buildQuery(): string |
|
23 | { |
|
24 | $this->resetFields(); |
|
25 | $this->resetPreparedItems(); |
|
26 | ||
27 | $this->checkIsKeysOnTheBeginning(); |
|
28 | ||
29 | $queryParams = $this->iterateOverItems($this->getPreparedItems(), function ($iteration) { |
|
30 | $prepared = array_map(function ($field, $key) use ($iteration) { |
|
31 | if (in_array($field, $this->getIgnoredColumn(), true)) { |
|
32 | return $this->getPreparedItems()[$iteration][$field] ?? $this->getPreparedItems()[$iteration][$key]; |
|
33 | } |
|
34 | ||
35 | return ':'.$field.'_'.$iteration; |
|
36 | }, $this->getFields(), array_keys($this->getFields())); |
|
37 | ||
38 | return '('.implode(',', $prepared).')'; |
|
39 | }); |
|
40 | ||
41 | $fields = array_map(function ($field) { |
|
42 | return "`{$field}`"; |
|
43 | }, $this->getFields()); |
|
44 | ||
45 | return sprintf( |
|
46 | self::QUERY_TEMPLATE, |
|
47 | $this->getTable(), |
|
48 | implode(',', $fields), |
|
49 | implode(',', $queryParams) |
|
50 | ); |
|
51 | } |
|
52 | ||
53 | protected function bindValues(PDOStatement $statement) |
|
54 | { |
@@ 17-46 (lines=30) @@ | ||
14 | ||
15 | const QUERY_TEMPLATE = 'INSERT %s INTO %s (%s) VALUES %s %s'; |
|
16 | ||
17 | protected function buildQuery() : string |
|
18 | { |
|
19 | $this->resetFields(); |
|
20 | $this->resetPreparedItems(); |
|
21 | ||
22 | $queryParams = $this->iterateOverItems($this->getPreparedItems(), function ($iteration) { |
|
23 | $prepared = array_map(function ($field, $key) use ($iteration) { |
|
24 | if (in_array($field, $this->getIgnoredColumn(), true)) { |
|
25 | return $this->getPreparedItems()[$iteration][$field] ?? $this->getPreparedItems()[$iteration][$key]; |
|
26 | } |
|
27 | ||
28 | return ':'.$field.'_'.$iteration; |
|
29 | }, $this->getFields(), array_keys($this->getFields())); |
|
30 | ||
31 | return '('.implode(',', $prepared).')'; |
|
32 | }); |
|
33 | ||
34 | $fields = array_map(function ($field) { |
|
35 | return "`{$field}`"; |
|
36 | }, $this->getFields()); |
|
37 | ||
38 | return sprintf( |
|
39 | self::QUERY_TEMPLATE, |
|
40 | ($this->isIgnoreUsed() ? 'IGNORE' : ''), |
|
41 | $this->getTable(), |
|
42 | implode(',', $fields), |
|
43 | implode(',', $queryParams), |
|
44 | $this->getOnDuplicateUpdateRow() |
|
45 | ); |
|
46 | } |
|
47 | ||
48 | protected function bindValues(PDOStatement $statement) |
|
49 | { |