'Find the maximum VARCHAR width, up to 0xffffffff'

def configure_max_varchar(sql):

    lo = 0
    hi = (1 << 32)
    mid = (hi - 1)
    sql.config['max_varchar'] = str(mid)
    sql.drop_table_if_exists(('%stest_1' % sql.prefix))
    while True:
        sql.drop_table_if_exists(('%stest_1' % sql.prefix))
        try:
            sql.ddl(('CREATE    TABLE    %stest_1\n                                                                                                            (a    VARCHAR(%d),    b    VARCHAR(%d))' % (sql.prefix, mid, mid)))
            sql.sql(("INSERT    INTO    %stest_1    (a,    b)    VALUES    ('x',    'y')" % sql.prefix))
            row = sql.selectrow(('SELECT    a,    b    FROM    %stest_1' % sql.prefix))
            if ([x for x in row] == ['x', 'y']):
                lo = mid
            else:
                hi = mid
        except sql.module.DatabaseError as e:
            sql.rollback()
            hi = mid
        except Exception as e:
            sql.rollback()
            hi = mid
        if ((lo + 1) == hi):
            sql.config['max_varchar'] = str(lo)
            sql.log.info('max_varchar=%s', sql.config['max_varchar'])
            break
        mid = ((lo + hi) / 2)
    sql.drop_table_if_exists(('%stest_1' % sql.prefix))
