Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite max query parameters differs on Snow Leopard?

This is a minor question, but I'm kind of stumped.

sqlite has a hard limit on the number of query parameters, of 999. This is set in headers which are not part of the public header file, and the runtime gives you the ability to lower the limit, but not exceed the hard limit. The Python sqlite3 module on Snow Leopard (and Lion as well, apparently) allows more parameters than this, however, and I can't figure out for the life of me how this is possible.

I considered the possibility that the Python wrapper is doing the parameter substitution itself and passing full statements to sqlite3; but as far as I can tell from the source code, that's not happening. I also considered the possibility that the implementation of sqlite3 on Snow Leopard was compiled from slightly different source code; but it turns out that Apple publishes its open-source modifications (see http://opensource.apple.com/source/SQLite/SQLite-74.11/) and the parameter limit in their source is identical to the default.

If someone has an idea about how this might be happening (and I'm certain it's happening; I've created statements with 2000 parameters and they work fine), please chime in. For what it's worth, I encountered this oddity because the identical code breaks on Windows, due to the parameter limit.

like image 476
Sam Bayer Avatar asked Nov 13 '22 06:11

Sam Bayer


1 Answers

When building the full SQLite (C) sources, the preprocessor define

SQLITE_MAX_VARIABLE_NUMBER

controls the maximum number of "statement variables", the default value is 999.

More information can be found here: https://sqlite.org/limits.html

I would assume the python binding uses a custom build of SQLite with a higher number.


(Mandatory note about 999 parameters being more than plenty, and you are doing something weird - or unusual. Consider posting your use case and if there are suggestions for a mroe reasonable number of parameters.)

like image 121
peterchen Avatar answered Dec 08 '22 00:12

peterchen