Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] SqlServer2012 grammar file #7568

Closed
crissi opened this issue Feb 23, 2015 · 4 comments
Closed

[Proposal] SqlServer2012 grammar file #7568

crissi opened this issue Feb 23, 2015 · 4 comments

Comments

@crissi
Copy link
Contributor

crissi commented Feb 23, 2015

That implements limit and offset with sql server 2012's: OFFSET AND FETCH instead of row_number() over

@GrahamCampbell
Copy link
Member

Any thoughts?

@stevenobird
Copy link

Well, that "should" be pretty easy.

In SqlServerGrammar.php:

    protected function compileOffset(Builder $query, $offset)
    {
        return "OFFSET {$offset} ROWS";
    }

    protected function compileLimit(Builder $query, $limit)
    {
        return "FETCH {$limit} ROWS ONLY";
    }

The thing is, that OFFSET can be used alone, but FETCH needs a leading OFFSET Clause in order to work.

Also, the used SQL Server Version should be specified in the Database.php config file in order to avoid conflicts, since this OFFSET Syntax has just been introduced in SQL Server 2012 (which is in version terms, 11.0).

@GrahamCampbell
Copy link
Member

We're open to PRs.

@yansern
Copy link

yansern commented Feb 15, 2018

I attempted to implement OFFSET...FETCH but it only take effect when ->orderBy is used. Otherwise it will fallback to ROW_NUMBER().

Gist: https://gist.github.com/yansern/4d7017351314eb37fa0df284ccd51c40
Feel free to diff it yourself to see what's changed.

This is for the file: src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php.

Perhaps this can be a starting point for others to follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants