def initialize_sqlcipher_db(opts, on_init=None, check_same_thread=True): """ Initialize a SQLCipher database. :param opts: :type opts: SQLCipherOptions :param on_init: a tuple of queries to be executed on initialization :type on_init: tuple :return: pysqlcipher.dbapi2.Connection """ # Note: There seemed to be a bug in sqlite 3.5.9 (with python2.6) # where without re-opening the database on Windows, it # doesn't see the transaction that was just committed # Removing from here now, look at the pysqlite implementation if the # bug shows up in windows. if not os.path.isfile(opts.path) and not opts.create: raise u1db_errors.DatabaseDoesNotExist() conn = sqlcipher_dbapi2.connect(opts.path, check_same_thread=check_same_thread) pragmas.set_init_pragmas(conn, opts, extra_queries=on_init) return conn