Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 19, 2019
1 parent ca15be4 commit 46d7e96
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Expand Up @@ -2648,7 +2648,7 @@ public function insert(array $values)
}

/**
* Insert ignore a new record into the database.
* Insert a new record into the database while ignoring errors.
*
* @param array $values
* @return int
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Grammars/Grammar.php
Expand Up @@ -881,7 +881,7 @@ public function compileInsert(Builder $query, array $values)
*/
public function compileInsertOrIgnore(Builder $query, array $values)
{
throw new RuntimeException('This database engine does not support insert or ignore.');
throw new RuntimeException('This database engine does not support inserting while ignoring errors.');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Database\Query\Grammars;

use Illuminate\Support\Str;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JsonExpression;

Expand Down Expand Up @@ -63,7 +64,7 @@ public function compileSelect(Builder $query)
*/
public function compileInsertOrIgnore(Builder $query, array $values)
{
return substr_replace($this->compileInsert($query, $values), ' ignore', 6, 0);
return Str::replaceFirst('insert', 'insert ignore', $this->compileInsert($query, $values));
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Expand Up @@ -217,11 +217,7 @@ public function compileInsertOrIgnore(Builder $query, array $values)
*/
public function compileInsertGetId(Builder $query, $values, $sequence)
{
if (is_null($sequence)) {
$sequence = 'id';
}

return $this->compileInsert($query, $values).' returning '.$this->wrap($sequence);
return $this->compileInsert($query, $values).' returning '.$this->wrap($sequence ?: 'id');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php
Expand Up @@ -187,7 +187,7 @@ public function compileInsert(Builder $query, array $values)
*/
public function compileInsertOrIgnore(Builder $query, array $values)
{
return substr_replace($this->compileInsert($query, $values), ' or ignore', 6, 0);
return Str::replaceFirst('insert', 'insert or ignore', $this->compileInsert($query, $values));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/DatabaseQueryBuilderTest.php
Expand Up @@ -1870,7 +1870,7 @@ function (Builder $query) {
public function testInsertOrIgnoreMethod()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('This database engine does not support insert or ignore.');
$this->expectExceptionMessage('does not support');
$builder = $this->getBuilder();
$builder->from('users')->insertOrIgnore(['email' => 'foo']);
}
Expand Down Expand Up @@ -1902,7 +1902,7 @@ public function testSQLiteInsertOrIgnoreMethod()
public function testSqlServerInsertOrIgnoreMethod()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('This database engine does not support insert or ignore.');
$this->expectExceptionMessage('does not support');
$builder = $this->getSqlServerBuilder();
$builder->from('users')->insertOrIgnore(['email' => 'foo']);
}
Expand Down

0 comments on commit 46d7e96

Please sign in to comment.