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

[Bug] SQLite multiple inserts need to be broken down to chunks of 100 #50

Closed
Anahkiasen opened this issue Jan 15, 2013 · 2 comments
Closed

Comments

@Anahkiasen
Copy link
Contributor

Currently SQLite multiple inserts only work with chunks of 100 entries. Above it, it throws the following exception : SQLSTATE[HY000]: General error: 1 too many SQL variables.
Something with array_chunk maybe.

This isn't a problem in most parts of the application since inserts can be manually splited but is hugh problem in seeds because even if you split the query and insert the first chunks beforehand, seeding empties the database before inserting the seeded values.


UPDATE : Apparently this isn't as much a matter of entries as a matter of placeholders. See the #9 of this page on the SQLite website for more details. So if you insert entries with 5 columns (id, name, description, created_at, updated_at) you can insert 999 / 5 = 199 entries.
Maybe check if the limit can be put higher via PHP.

@Anahkiasen
Copy link
Contributor Author

In the meantime for people having the same problem here is my temporary workaround :

In the problematic seed :

// Slice for SQLite
$slicer = floor(999 / sizeof($photos[0]));
$slices = array_chunk($photos, $slicer);
foreach ($slices as $slice) {
  DB::table('photos')->insert($slice);
}

return [$photos[0]];

And in the next seed:

// Run photos seeds again
DB::table('photos')->delete();
include 'photos.php';

@taylorotwell
Copy link
Member

Eh, I don't really know of a clean way to work around this unfortunately. Sounds like more of an upstream PHP issue.

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

2 participants