Skip to content

[Proposal] Throwing exception upon negative chunk size in Builder #16337

Closed
@jstoone

Description

@jstoone
  • Laravel Version: 5.3.22
  • PHP Version: 7.0.12
  • Database Driver & Version: mysql v5.7.16

Description:

I made the following PR a while ago, and @vlakoff mentioned applying the same logic to the Query\Builder and Eloquent\Builder chunk() and chunkById().

I then see that @taylorotwell has removed the exception part here, 46ebd7f, so wanted to throw this out there before creating a PR with the solution below, or better yet something else if anything seems more appropriate.

Steps To Reproduce:

// using Query\Builder
DB::table('users')->chunk(-1, function(){});

// usingEloquent\Builder
User::query()->chunk(-1, function(){});

Produces:

Illuminate\Database\QueryException with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1 (SQL: select * from `users` offset 0)'

Solution

Throwing a proper InvalidArgumentException when $count < 0, I think would be a good solution. Please do tell what you think

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions