auraphp/Aura.SqlQuery

REPLACE sql command

pavarnos opened this issue · 2 comments

Hi

Would you accept a pull request that allowed the hard-coded "INSERT" statement in */Insert.php to be swapped for "REPLACE" when we need to do a REPLACE INTO query? (supported by sqlite, mysql)

Would probably implement it like this:

private $insertCommand = 'INSERT';

public function useReplace() 
{
    $this->insertCommand = 'REPLACE';
}

protected function build()
{
        return $this->insertCommand
            . $this->buildFlags()
            . $this->buildInto()
            . $this->buildValuesForInsert()
            . $this->buildValuesForUpdateOnDuplicateKey()
            . $this->buildReturning();
}

I prefer this approach over onDuplicateKeyUpdate() because it allows my tests to run unchanged on sqlite while using mysql on the live server. On Duplicate Key update is mysql only?

I'd be happy to look at a PR for this, if you're willing to submit one! I'd figure it should use a flag on the useReplace() method so it could be switched back and forth. E.g., $insert->useReplace(false) would put it back to a regular insert.

Also, it should probably be on the db-specific INSERT classes, not the common one.