Skip to content

Commit

Permalink
[10.x] Revert 47763 fix sql server (#47792)
Browse files Browse the repository at this point in the history
* Revert "Fix sql server paging problems (#47763)"

This reverts commit 53b02b3.

* Removed unused functions

* Re-enabled sql server workflow
  • Loading branch information
dunhamjared committed Jul 24, 2023
1 parent 5daff2c commit 289298e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
86 changes: 43 additions & 43 deletions .github/workflows/databases.yml
Expand Up @@ -181,46 +181,46 @@ jobs:
DB_CONNECTION: pgsql
DB_PASSWORD: password

# mssql:
# runs-on: ubuntu-20.04

# services:
# sqlsrv:
# image: mcr.microsoft.com/mssql/server:2019-latest
# env:
# ACCEPT_EULA: Y
# SA_PASSWORD: Forge123
# ports:
# - 1433:1433

# strategy:
# fail-fast: true

# name: SQL Server 2019

# steps:
# - name: Checkout code
# uses: actions/checkout@v3

# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: 8.1
# extensions: dom, curl, libxml, mbstring, zip, pcntl, sqlsrv, pdo, pdo_sqlsrv, odbc, pdo_odbc
# tools: composer:v2
# coverage: none

# - name: Install dependencies
# uses: nick-fields/retry@v2
# with:
# timeout_minutes: 5
# max_attempts: 5
# command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

# - name: Execute tests
# run: vendor/bin/phpunit tests/Integration/Database
# env:
# DB_CONNECTION: sqlsrv
# DB_DATABASE: master
# DB_USERNAME: SA
# DB_PASSWORD: Forge123
mssql:
runs-on: ubuntu-20.04

services:
sqlsrv:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: Forge123
ports:
- 1433:1433

strategy:
fail-fast: true

name: SQL Server 2019

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, sqlsrv, pdo, pdo_sqlsrv, odbc, pdo_odbc
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Database
env:
DB_CONNECTION: sqlsrv
DB_DATABASE: master
DB_USERNAME: SA
DB_PASSWORD: Forge123
Expand Up @@ -48,7 +48,7 @@ class SqlServerGrammar extends Grammar
public function compileSelect(Builder $query)
{
// An order by clause is required for SQL Server offset to function...
if (($query->offset || $query->limit) && empty($query->orders)) {
if ($query->offset && empty($query->orders)) {
$query->orders[] = ['sql' => '(SELECT 0)'];
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Database/DatabaseQueryBuilderTest.php
Expand Up @@ -2690,7 +2690,7 @@ public function testAggregateFunctions()
public function testSqlServerExists()
{
$builder = $this->getSqlServerBuilder();
$builder->getConnection()->shouldReceive('select')->once()->with('select top 1 1 [exists] from [users] order by (SELECT 0)', [], true)->andReturn([['exists' => 1]]);
$builder->getConnection()->shouldReceive('select')->once()->with('select top 1 1 [exists] from [users]', [], true)->andReturn([['exists' => 1]]);
$results = $builder->from('users')->exists();
$this->assertTrue($results);
}
Expand Down Expand Up @@ -3856,7 +3856,7 @@ public function testSqlServerLimitsAndOffsets()
{
$builder = $this->getSqlServerBuilder();
$builder->select('*')->from('users')->take(10);
$this->assertSame('select top 10 * from [users] order by (SELECT 0)', $builder->toSql());
$this->assertSame('select top 10 * from [users]', $builder->toSql());

$builder = $this->getSqlServerBuilder();
$builder->select('*')->from('users')->skip(10)->orderBy('email', 'desc');
Expand All @@ -3875,7 +3875,7 @@ public function testSqlServerLimitsAndOffsets()
return $query->select('created_at')->from('logins')->where('users.name', 'nameBinding')->whereColumn('user_id', 'users.id')->limit(1);
};
$builder->select('*')->from('users')->where('email', 'emailBinding')->orderBy($subQuery)->skip(10)->take(10);
$this->assertSame('select * from [users] where [email] = ? order by (select top 1 [created_at] from [logins] where [users].[name] = ? and [user_id] = [users].[id] order by (SELECT 0)) asc offset 10 rows fetch next 10 rows only', $builder->toSql());
$this->assertSame('select * from [users] where [email] = ? order by (select top 1 [created_at] from [logins] where [users].[name] = ? and [user_id] = [users].[id]) asc offset 10 rows fetch next 10 rows only', $builder->toSql());
$this->assertEquals(['emailBinding', 'nameBinding'], $builder->getBindings());

$builder = $this->getSqlServerBuilder();
Expand Down

0 comments on commit 289298e

Please sign in to comment.