rogerbinns / apsw

Another Python SQLite wrapper
https://rogerbinns.github.io/apsw/
Other
733 stars 97 forks source link

Incorrect values in `colUsed` #513

Closed betodealmeida closed 5 months ago

betodealmeida commented 5 months ago

I'm trying to query a virtual table that has 76 columns, but when I try to select any column past the 64th the indexes in index_info.colUsed seems to cap at 63.

There's special logic for virtual tables with more than 63 columns:

If the table has at least 64 columns and any column to the right of the first 63 is required, then bit 63 of colUsed is also set. In other words, column iCol may be required if the expression (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to non-zero.

It looks like this logic is not being applied when colUsed is converted from a mask into a set of integers.

rogerbinns commented 5 months ago

Unfortunately the behaviour is as documented. You need to deal with more than 63 columns in your own code. APSW does do it where possible - for example index_info_to_dict does it here if you provide the column names.

The reason the set can't automatically be expanded is because the relevant code doesn't know how many columns there are! The only way I could find out the number of columns would be by parsing the SQL returned in the Create/Connect method.

betodealmeida commented 5 months ago

The reason the set can't automatically be expanded is because the relevant code doesn't know how many columns there are!

Ah, I see! I thought it knew the number of columns. No worries, I'll fix it in my own code. Thanks for the quick response!