@@ -216,12 +216,22 @@ public function parse(Parser $parser, TokensList $list)
216
216
if ($ list ->getNextOfTypeAndValue (Token::TYPE_KEYWORD , 'ON ' )) {
217
217
// (-1) because getNextOfTypeAndValue returned ON and increased the index.
218
218
$ idxOfOn = $ list ->idx - 1 ;
219
- // Index of the last parsed token will be the token before the ON Keyword, therefore $idxOfOn - 1.
220
- $ idxOfLastParsedToken = $ idxOfOn - 1 ;
221
- // The length of the expression tokens would be the difference
222
- // between the first unrelated token `ON` and the idx
223
- // before skipping the CTE tokens.
224
- $ lengthOfExpressionTokens = $ idxOfOn - $ idxBeforeSearch ;
219
+ // We want to make sure that it's `ON DUPLICATE KEY UPDATE`
220
+ $ dubplicateToken = $ list ->getNext ();
221
+ $ keyToken = $ list ->getNext ();
222
+ $ updateToken = $ list ->getNext ();
223
+ if (
224
+ $ dubplicateToken && $ dubplicateToken ->keyword === 'DUPLICATE '
225
+ && ($ keyToken && $ keyToken ->keyword === 'KEY ' )
226
+ && ($ updateToken && $ updateToken ->keyword === 'UPDATE ' )
227
+ ) {
228
+ // Index of the last parsed token will be the token before the ON Keyword
229
+ $ idxOfLastParsedToken = $ idxOfOn - 1 ;
230
+ // The length of the expression tokens would be the difference
231
+ // between the first unrelated token `ON` and the idx
232
+ // before skipping the CTE tokens.
233
+ $ lengthOfExpressionTokens = $ idxOfOn - $ idxBeforeSearch ;
234
+ }
225
235
}
226
236
227
237
// Restore the index
0 commit comments