# Escape key in community version

**URL:** https://discuss.zetetic.net/t/escape-key-in-community-version/6912
**Category:** SQLCipher
**Created:** [May 8, 2025, 1:04am UTC](https://discuss.zetetic.net/t/escape-key-in-community-version/6912 "2025-05-08T01:04:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mtissington](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@mtissington](https://discuss.zetetic.net/u/mtissington)
#### Post date: [May 8, 2025, 1:04am UTC](https://discuss.zetetic.net/t/escape-key-in-community-version/6912/1 "2025-05-08T01:04:10Z")

</div>

I’m trying to escape the key before using it in `PRAGMA key = `  
I’ve seen comments that I can use something like  
`SELECT quote($password)` passing password as a parameter.

However this generates an error “File is not a database” because `PRAGMA key` is not the first statement.

How do I build a community version that lets me do the `SELECT quote(..)` first?

(which is basically what Microsoft.Data.SQLite is doing)

---

<div class="post-metadata">

### Author: ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)
#### Post date: [May 8, 2025, 2:19pm UTC](https://discuss.zetetic.net/t/escape-key-in-community-version/6912/2 "2025-05-08T14:19:04Z")

</div>

Hello @mtissington,

With the [SQLCipher 4.7.0 release](https://www.zetetic.net/blog/2025/03/25/sqlcipher-4.7.0-release/), the library updated the baseline of SQLite to 3.49.1. There were several notable changes from the upstream in that release that include:

- `SELECT` statements (including schema independent queries like `SELECT 1`) cannot be executed prior to setting the database key on encrypted database

This explains the behavior you are seeing. One possible workaround would be to open a separate connection using the `:memory:` identifier as the filename and performing your `SELECT quote(...)` operation, then closing that connection.

---

<div class="post-metadata">

### Author: ![mtissington](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@mtissington](https://discuss.zetetic.net/u/mtissington)
#### Post date: [May 8, 2025, 6:07pm UTC](https://discuss.zetetic.net/t/escape-key-in-community-version/6912/3 "2025-05-08T18:07:08Z")

</div>

Hmm, this is a section of the Open code from the current release of Microsoft.Data.SQLite.Core which obviously I can’t change.

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

---

<div class="post-metadata">

### Author: ![mtissington](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@mtissington](https://discuss.zetetic.net/u/mtissington)
#### Post date: [May 8, 2025, 7:04pm UTC](https://discuss.zetetic.net/t/escape-key-in-community-version/6912/4 "2025-05-08T19:04:38Z")

</div>

Never mind I see this issue reported  
[https://github.com/dotnet/efcore/issues/35760](https://github.com/dotnet/efcore/issues/35760)
