Repository: dotnet/efcore
File: src/Microsoft.Data.Sqlite.Core/SqliteConnectionInternal.cs (C#)

Code before:
                filename = Path.Combine(dataDirectory, filename);
            }
        }

        var vfs = !string.IsNullOrWhiteSpace(connectionOptions.Vfs)
            ? connectionOptions.Vfs
            : null;
        var rc = sqlite3_open_v2(filename, out _db, flags, vfs: vfs);
        try
        {
            SqliteException.ThrowExceptionForRC(rc, _db);

            if (connectionOptions.Password.Length != 0)
            {
                if (SQLitePCLExtensions.EncryptionSupported(out var libraryName) == false)
                {
                    throw new InvalidOperationException(Resources.EncryptionNotSupported(libraryName));
                }

                // NB: SQLite doesn't support parameters in PRAGMA statements, so we escape the value using the
                //     quote function before concatenating.
                var quotedPassword = string.Empty;
                using (var inMemoryConnection = new SqliteConnection("Filename=:memory:"))
                {
                    inMemoryConnection.Open();
                    quotedPassword = ExecuteScalar(
                        "SELECT quote($password);",
                    connectionOptions.Password,
                    connectionOptions.DefaultTimeout);
                }
                ExecuteNonQuery(
                    "PRAGMA key = " + quotedPassword + ";",
                    connectionOptions.DefaultTimeout);

                if (SQLitePCLExtensions.EncryptionSupported() != false)
                {
                    // NB: Forces decryption. Throws when the key is incorrect.
                    ExecuteNonQuery(
                        "SELECT COUNT(*) FROM sqlite_master;",
                        connectionOptions.DefaultTimeout);
                }
            }

            if (connectionOptions.ForeignKeys.HasValue)
            {
                ExecuteNonQuery(
                    "PRAGMA foreign_keys = " + (connectionOptions.ForeignKeys.Value ? "1" : "0") + ";",
                    connectionOptions.DefaultTimeout);
            }

            if (connectionOptions.RecursiveTriggers)

Review comment (suggestion):
`ExecuteScalar` will not use `inMemoryConnection` here. (It uses `_db`)

Code after:
                filename = Path.Combine(dataDirectory, filename);
            }
        }

        var vfs = !string.IsNullOrWhiteSpace(connectionOptions.Vfs)
            ? connectionOptions.Vfs
            : null;
        var rc = sqlite3_open_v2(filename, out _db, flags, vfs: vfs);
        try
        {
            SqliteException.ThrowExceptionForRC(rc, _db);

            if (connectionOptions.Password.Length != 0)
            {
                if (SQLitePCLExtensions.EncryptionSupported(out var libraryName) == false)
                {
                    throw new InvalidOperationException(Resources.EncryptionNotSupported(libraryName));
                }

                // NB: SQLite doesn't support parameters in PRAGMA statements, so we escape the value using the
                //     quote function before concatenating.
                var quotedPassword = QuotePassword(connectionOptions.Password);
                ExecuteNonQuery(
                    "PRAGMA key = " + quotedPassword + ";",
                    connectionOptions.DefaultTimeout);

                if (SQLitePCLExtensions.EncryptionSupported() != false)
                {
                    // NB: Forces decryption. Throws when the key is incorrect.
                    ExecuteNonQuery(
                        "SELECT COUNT(*) FROM sqlite_master;",
                        connectionOptions.DefaultTimeout);
                }
            }

            if (connectionOptions.ForeignKeys.HasValue)
            {
                ExecuteNonQuery(
                    "PRAGMA foreign_keys = " + (connectionOptions.ForeignKeys.Value ? "1" : "0") + ";",
                    connectionOptions.DefaultTimeout);
            }

            if (connectionOptions.RecursiveTriggers)
            {
                ExecuteNonQuery(
                    "PRAGMA recursive_triggers = 1;",
                    connectionOptions.DefaultTimeout);
            }
        }
        catch
        {