Feature Request #4384

Add Database Insert ignore()

Added by Gah Gneh 4 months ago. Updated 4 months ago.

Status:Feedback Start date:01/04/2012
Priority:Normal Due date:
Assignee:Woody Gilk % Done:

0%

Category:-
Target version:-
Resolution:wontfix Points:1

Description

I'm using MYSQL, and sometimes I use the INSERT IGNORE so it won't trigger any exceptions on a duplicate, usually when adding item pairs through the administration panel on websites I build, for a many-to-many relationship table.
I've extended the base query builder for insert, but I'm having to replicate the entire compile function, because the $query variable is local. Would like to see it in the next version. And possibly ON DUPLICATE KEY UPDATE as well

class Database_Query_Builder_Insert extends Kohana_Database_Query_Builder_Insert {
    protected $_ignore = false;

    /**
     * return Database_Query_Builder_Insert
     */
    function ignore($ignore)
    {
        $this->_ignore = $ignore;
        return $this;
    }

    public function compile(Database $db)
    {
        // Start an insertion query
        $query = 'INSERT '.($this->_ignore?'IGNORE':'').' INTO '.$db->quote_table($this->_table);
        [...]

History

Updated by Woody Gilk 4 months ago

  • Status changed from New to Closed
  • Assignee set to Woody Gilk
  • Resolution set to wontfix

We don't support database-specific features.

BTW, have you considered copying the Insert class and making a REPLACE INTO builder? That was my solution when I needed to do this kind of query.

Updated by Gah Gneh 4 months ago

  • Status changed from Closed to Feedback

could, at least the compile() function be decoupled, so I can call parent::compile() without having to manually copy and paste the entire function?

I don't use REPLACE INTO because it's a DELETE and INSERT action, bad thing when updating a table that has millions of rows. and plus, it doesn't go well with FOREIGN KEY constraints and triggers

Updated by Chris Smith 4 months ago

Gah Gneh wrote:

could, at least the compile() function be decoupled, so I can call parent::compile() without having to manually copy and paste the entire function?

Yeah, extending the query builder is a PITA currently.

Also available in: Atom PDF