i'm not at a real computer, and can't check the sqlite docs. i agree this looks kinda janky, but is probably fine.
the sqlite thing i want to check is about how virtual tables are invoked. i think there's a create vs call convention. we don't use that, and i wonder if the source of this bug is the lack of utilization of the create routine.