def max_columns():
    db = sqlite3.connect(':memory:')
low = 1
high = 32767
while low < high - 1:
    guess = (low + high) // 2
try:
    db.execute('CREATE TABLE T%d (%s)' % (guess, ','.join('C%d' % i for i in
        range(guess))))
except sqlite3.DatabaseError as ex:
    if 'too many columns' in str(ex):
        high = guess
Determine maximum number of columns from sqlite3