Add ignore() method to to InsertQuery_mysql class

Created on 21 December 2013, over 10 years ago
Updated 31 January 2023, over 1 year ago

MySQL's insert query supports the IGNORE keyword, which is describe in the MySQL manual:

If you use the IGNORE keyword, errors that occur while executing the INSERT statement are ignored. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row still is not inserted, but no error occurs. Ignored errors may generate warnings instead, although duplicate-key errors do not.

Currently, one cannot use db_insert() with this keyword—no method exists for attaching it to the query string. I'd like to consider adding an ignore() method to InsertQuery_mysql which will append ' IGNORE' to the end of insert queries.

This has at least one drawback: it is only applicable to the mysql db engine. We'd only be adding it to the InsertQuery_mysql class, but the mere existence of this method for one db engine may cause module creators to inadvertently make modules dependent on the MySQL backend.

A number of links to places where people have requested this functionality:

Feature request
Status

Needs work

Version

10.1

Component
Database 

Last updated less than a minute ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇺🇸United States grasmash

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024