def max_parameter_substitution():
if os.path.isfile(SQLITE_VARIABLE_FILE_CACHE):<EOL><INDENT>return<EOL><DEDENT>conn = sqlite3.connect('<STR_LIT>')<EOL>low = <NUM_LIT:1><EOL>high = <NUM_LIT:1000>  <EOL>conn.execute('<STR_LIT>')<EOL>while low < high - <NUM_LIT:1>:<EOL><INDENT>guess = (low + high) // <NUM_LIT:2><EOL>try:<EOL><INDENT>statement = '<STR_LIT>' % '<STR_LIT:U+002C>'.join(['<STR_LIT:?>' for _ in range(guess)])<EOL>values = [i for i in range(guess)]<EOL>conn.execute(statement, values)<EOL><DEDENT>except sqlite3.DatabaseError as ex:<EOL><INDENT>if '<STR_LIT>' in str(ex):<EOL><INDENT>high = guess<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>else:<EOL><INDENT>low = guess<EOL><DEDENT><DEDENT>conn.close()<EOL>with open(SQLITE_VARIABLE_FILE_CACHE, '<STR_LIT:w>') as file:<EOL><INDENT>file.write(str(low))<EOL><DEDENT>
SQLite has a limit on the max number of variables allowed for parameter substitution. This limit is usually 999, but
can be compiled to a different number. This function calculates what the max is for the sqlite version running on the device.
We use the calculated value to chunk our SQL bulk insert statements when deserializing from the store to the app layer.