tgriesser/knex — pull request #495 by demmer (2014-09-18 18:03:52+00:00)
Title: fix off-by-one error in sqlite insertChunked

I was looking into an issue with sqlite renaming columns and as part of that debugging I noticed that insertChunked for a table with a single row was inserting a batch with 0 entries in it.

It looks like this is due to a simple off-by-one logic error in the computation of when the reduce loop should end, since memo is incremented before the row is added to the batch, so when memo === result.length, there's still one row left to add to the batch.

I don't know this codebase well enough to craft a test for this, but by inspection it seems to me like the previous version would have dropped the last row every time, which seems like an egregious error that I'm surprised wasn't noticed previously.