Skip to content

Commit

Permalink
Make compatible with SQLITE_DSQ=0
Browse files Browse the repository at this point in the history
Fix SQL query errors when running against an SQLite build compiled with
`-DSQLITE_DSQ=0`, which makes SQLite behave like PostgreSQL and expect that
double quotes are only used to denote column name identifiers and never for
string literals.

So far as I can see, the only place we ever used double-quoted strings was in
initializing or querying the `meta` table; the "regular" queries mapped to the
`Operations` enum are all quote-free.

Closes #12.
  • Loading branch information
mqudsi committed Jan 30, 2023
1 parent 08636ad commit 9f38c2d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions SqliteCache/SqliteCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static bool CheckExistingDb(DbConnection db, ILogger logger)
}

// Check for correct version
using (var cmd = new DbCommand(@"SELECT value FROM meta WHERE key = ""version""", db))
using (var cmd = new DbCommand("SELECT value FROM meta WHERE key = 'version'", db))
{
var result = (long)cmd.ExecuteScalar()!;
if (result != SchemaVersion)
Expand Down Expand Up @@ -185,8 +185,8 @@ private static void Initialize(SqliteCacheOptions config, DbConnection db, ILogg
using (var cmd = new DbCommand(
$"INSERT INTO meta (key, value) " +
$"VALUES " +
$@"(""version"", {SchemaVersion}), " +
$@"(""created"", {DateTimeOffset.UtcNow.Ticks})", db))
$"('version', {SchemaVersion}), " +
$"('created', {DateTimeOffset.UtcNow.Ticks})", db))
{
cmd.Transaction = transaction;
cmd.ExecuteNonQuery();
Expand Down Expand Up @@ -215,7 +215,7 @@ private async Task<bool> CheckExistingDbAsync(DbConnection db, CancellationToken
}

// Check for correct version
using (var cmd = new DbCommand(@"SELECT value FROM meta WHERE key = ""version""", db))
using (var cmd = new DbCommand("SELECT value FROM meta WHERE key = 'version'", db))
{
var result = (long)await cmd.ExecuteScalarAsync(cancel);
if (result != SchemaVersion)
Expand Down Expand Up @@ -290,8 +290,8 @@ private async Task InitializeAsync(CancellationToken cancel)
using (var cmd = new DbCommand(
$"INSERT INTO meta (key, value) " +
$"VALUES " +
$@"(""version"", {SchemaVersion}), " +
$@"(""created"", {DateTimeOffset.UtcNow.Ticks})" , _db))
$"('version', {SchemaVersion}), " +
$"('created', {DateTimeOffset.UtcNow.Ticks})" , _db))
{
cmd.Transaction = transaction;
await cmd.ExecuteNonQueryAsync(cancel);
Expand Down

0 comments on commit 9f38c2d

Please sign in to comment.