forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[10.x] Add toRawSql for query builders
- Loading branch information
Showing
14 changed files
with
218 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
name: databases | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- '*.x' | ||
pull_request: | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
mysql_57: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
name: facades | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- '*.x' | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
update: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
name: static analysis | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- '*.x' | ||
pull_request: | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
types: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ class Builder implements BuilderContract | |
'raw', | ||
'rawValue', | ||
'sum', | ||
'toRawSql', | ||
'toSql', | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Database; | ||
|
||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Query\Grammars\MySqlGrammar; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DatabaseMySqlQueryGrammarTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testToRawSql() | ||
{ | ||
$connection = m::mock(Connection::class); | ||
$connection->shouldReceive('escape')->with('foo', false)->andReturn("'foo'"); | ||
$grammar = new MySqlGrammar; | ||
$grammar->setConnection($connection); | ||
|
||
$query = $grammar->makeRawSql( | ||
'select * from "users" where \'Hello\\\'World?\' IS NOT NULL AND "email" = ?', | ||
['foo'], | ||
); | ||
|
||
$this->assertSame('select * from "users" where \'Hello\\\'World?\' IS NOT NULL AND "email" = \'foo\'', $query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Database; | ||
|
||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Query\Grammars\PostgresGrammar; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DatabasePostgresQueryGrammarTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testToRawSql() | ||
{ | ||
$connection = m::mock(Connection::class); | ||
$connection->shouldReceive('escape')->with('foo', false)->andReturn("'foo'"); | ||
$grammar = new PostgresGrammar; | ||
$grammar->setConnection($connection); | ||
|
||
$query = $grammar->makeRawSql( | ||
'select * from "users" where \'{}\' ?? \'Hello\\\'\\\'World?\' AND "email" = ?', | ||
['foo'], | ||
); | ||
|
||
$this->assertSame('select * from "users" where \'{}\' ? \'Hello\\\'\\\'World?\' AND "email" = \'foo\'', $query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Database; | ||
|
||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Query\Grammars\SQLiteGrammar; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DatabaseSQLiteQueryGrammarTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testToRawSql() | ||
{ | ||
$connection = m::mock(Connection::class); | ||
$connection->shouldReceive('escape')->with('foo', false)->andReturn("'foo'"); | ||
$grammar = new SQLiteGrammar; | ||
$grammar->setConnection($connection); | ||
|
||
$query = $grammar->makeRawSql( | ||
'select * from "users" where \'Hello\'\'World?\' IS NOT NULL AND "email" = ?', | ||
['foo'], | ||
); | ||
|
||
$this->assertSame('select * from "users" where \'Hello\'\'World?\' IS NOT NULL AND "email" = \'foo\'', $query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Database; | ||
|
||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Query\Grammars\SqlServerGrammar; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DatabaseSqlServerQueryGrammarTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testToRawSql() | ||
{ | ||
$connection = m::mock(Connection::class); | ||
$connection->shouldReceive('escape')->with('foo', false)->andReturn("'foo'"); | ||
$grammar = new SqlServerGrammar; | ||
$grammar->setConnection($connection); | ||
|
||
$query = $grammar->makeRawSql( | ||
"select * from [users] where 'Hello''World?' IS NOT NULL AND [email] = ?", | ||
['foo'], | ||
); | ||
|
||
$this->assertSame("select * from [users] where 'Hello''World?' IS NOT NULL AND [email] = 'foo'", $query); | ||
} | ||
} |