1 | <?php |
||
20 | class Insert extends Common\Insert |
||
21 | { |
||
22 | /** |
||
23 | * |
||
24 | * Column values for ON DUPLICATE KEY UPDATE section of query; the key is |
||
25 | * the column name and the value is the column value. |
||
26 | * |
||
27 | * @param array |
||
28 | * |
||
29 | */ |
||
30 | protected $col_on_update_values; |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | * Adds or removes HIGH_PRIORITY flag. |
||
35 | * |
||
36 | * @param bool $enable Set or unset flag (default true). |
||
37 | * |
||
38 | * @return $this |
||
39 | * |
||
40 | */ |
||
41 | 1 | public function highPriority($enable = true) |
|
46 | |||
47 | /** |
||
48 | * |
||
49 | * Adds or removes LOW_PRIORITY flag. |
||
50 | * |
||
51 | * @param bool $enable Set or unset flag (default true). |
||
52 | * |
||
53 | * @return $this |
||
54 | * |
||
55 | */ |
||
56 | 1 | public function lowPriority($enable = true) |
|
61 | |||
62 | /** |
||
63 | * |
||
64 | * Adds or removes IGNORE flag. |
||
65 | * |
||
66 | * @param bool $enable Set or unset flag (default true). |
||
67 | * |
||
68 | * @return $this |
||
69 | * |
||
70 | */ |
||
71 | 1 | public function ignore($enable = true) |
|
76 | |||
77 | /** |
||
78 | * |
||
79 | * Adds or removes DELAYED flag. |
||
80 | * |
||
81 | * @param bool $enable Set or unset flag (default true). |
||
82 | * |
||
83 | * @return $this |
||
84 | * |
||
85 | */ |
||
86 | 1 | public function delayed($enable = true) |
|
91 | |||
92 | /** |
||
93 | * |
||
94 | * Sets one column value placeholder in ON DUPLICATE KEY UPDATE section; |
||
95 | * if an optional second parameter is passed, that value is bound to the |
||
96 | * placeholder. |
||
97 | * |
||
98 | * @param string $col The column name. |
||
99 | * |
||
100 | * @param mixed,... $val Optional: a value to bind to the placeholder. |
||
101 | * |
||
102 | * @return $this |
||
103 | * |
||
104 | */ |
||
105 | 1 | public function onDuplicateKeyUpdateCol($col) |
|
106 | { |
||
107 | 1 | $key = $this->quoter->quoteName($col); |
|
108 | 1 | $bind = $col . '__on_duplicate_key'; |
|
109 | 1 | $this->col_on_update_values[$key] = ":$bind"; |
|
110 | 1 | $args = func_get_args(); |
|
111 | 1 | if (count($args) > 1) { |
|
112 | 1 | $this->bindValue($bind, $args[1]); |
|
113 | } |
||
114 | 1 | return $this; |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * |
||
119 | * Sets multiple column value placeholders in ON DUPLICATE KEY UPDATE |
||
120 | * section. If an element is a key-value pair, the key is treated as the |
||
121 | * column name and the value is bound to that column. |
||
122 | * |
||
123 | * @param array $cols A list of column names, optionally as key-value |
||
124 | * pairs where the key is a column name and the value is a bind value for |
||
125 | * that column. |
||
126 | * |
||
127 | * @return $this |
||
128 | * |
||
129 | */ |
||
130 | 1 | public function onDuplicateKeyUpdateCols(array $cols) |
|
131 | { |
||
132 | 1 | foreach ($cols as $key => $val) { |
|
133 | 1 | if (is_int($key)) { |
|
134 | // integer key means the value is the column name |
||
135 | 1 | $this->onDuplicateKeyUpdateCol($val); |
|
136 | } else { |
||
137 | // the key is the column name and the value is a value to |
||
138 | // be bound to that column |
||
139 | 1 | $this->onDuplicateKeyUpdateCol($key, $val); |
|
140 | } |
||
141 | } |
||
142 | 1 | return $this; |
|
143 | } |
||
144 | |||
145 | /** |
||
146 | * |
||
147 | * Sets a column value directly in ON DUPLICATE KEY UPDATE section; the |
||
148 | * value will not be escaped, although fully-qualified identifiers in the |
||
149 | * value will be quoted. |
||
150 | * |
||
151 | * @param string $col The column name. |
||
152 | * |
||
153 | * @param string $value The column value expression. |
||
154 | * |
||
155 | * @return $this |
||
156 | * |
||
157 | */ |
||
158 | 1 | public function onDuplicateKeyUpdate($col, $value) |
|
159 | { |
||
160 | 1 | if ($value === null) { |
|
161 | 1 | $value = 'NULL'; |
|
162 | } |
||
163 | |||
164 | 1 | $key = $this->quoter->quoteName($col); |
|
165 | 1 | $value = $this->quoter->quoteNamesIn($value); |
|
166 | 1 | $this->col_on_update_values[$key] = $value; |
|
167 | 1 | return $this; |
|
168 | } |
||
169 | |||
170 | /** |
||
171 | * |
||
172 | * Builds this query object into a string. |
||
173 | * |
||
174 | * @return string |
||
175 | * |
||
176 | */ |
||
177 | 11 | protected function build() |
|
186 | |||
187 | /** |
||
188 | * |
||
189 | * Builds the UPDATE ON DUPLICATE KEY part of the statement. |
||
190 | * |
||
191 | * @return string |
||
192 | * |
||
193 | */ |
||
194 | 11 | protected function buildValuesForUpdateOnDuplicateKey() |
|
208 | } |
||
209 |
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.