-
-
Notifications
You must be signed in to change notification settings - Fork 116
Bug when first record contains fewer columns than subsequent records #145
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
Labels
bug
Something isn't working
Comments
Note: had to adjust the test above because trying to exhaust a |
simonwiles
added a commit
to simonwiles/sqlite-utils
that referenced
this issue
Aug 30, 2020
This was referenced Aug 30, 2020
simonwiles
added a commit
to simonwiles/sqlite-utils
that referenced
this issue
Sep 6, 2020
simonwiles
added a commit
to simonwiles/sqlite-utils
that referenced
this issue
Sep 7, 2020
simonwiles
added a commit
to simonwiles/sqlite-utils
that referenced
this issue
Sep 8, 2020
simonwiles
added a commit
to simonwiles/sqlite-utils
that referenced
this issue
Sep 8, 2020
simonw
pushed a commit
that referenced
this issue
Sep 8, 2020
…a columns Refs #145. * Extract build_insert_queries_and_params * Extract insert_chunk so it can be called recursively Thanks, @simonwiles
Fixed in PR #146. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
insert_all()
selects the maximum batch size based on the number of fields in the first record. If the first record has fewer fields than subsequent records (andalter=True
is passed), this can result in SQL statements with more than the maximum permitted number of host parameters. This situation is perhaps unlikely to occur, but could happen if the first record had, say, 10 columns, such thatbatch_size
(based onSQLITE_MAX_VARIABLE_NUMBER = 999
) would be 99. If the next 98 rows had 11 columns, the resulting SQL statement for the first batch would have10 * 1 + 11 * 98 = 1088
host parameters (and subsequent batches, if the data were consistent from thereon out, would have99 * 11 = 1089
).I suspect that this bug is masked somewhat by the fact that while:
it is common that it is increased at compile time. Debian-based systems, for example, seem to ship with a version of sqlite compiled with
SQLITE_MAX_VARIABLE_NUMBER
set to 250,000, and I believe this is the case for homebrew installations too.A test for this issue might look like this:
The best solution, I think, is simply to process all the records when determining columns, column types, and the batch size. In my tests this doesn't seem to be particularly costly at all, and cuts out a lot of complications (including obviating my implementation of #139 at #142). I'll raise a PR for your consideration.
The text was updated successfully, but these errors were encountered: