fix(data): probe PRAGMA compile_options next to the SQLite version check
BRIEF §6.2 asks for the probe at startup. The options are read once per process from an in-memory connection, logged with the library version and added to the desktop diagnostics bundle; nothing depends on them (no FTS or JSON use). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+70
-2
No files matched your search
@@ -37,6 +37,7 @@ public sealed class SqliteDatabase : IDatabase
|
||||
internal const int BusyTimeoutMs = 5000;
|
||||
private const string LogCategory = "Data.Sqlite";
|
||||
private static readonly TimeSpan WriteLockTimeout = TimeSpan.FromSeconds(60);
|
||||
private static readonly Lazy<IReadOnlyList<string>> ProbedCompileOptions = new(ProbeCompileOptions);
|
||||
|
||||
private readonly string _filename;
|
||||
private readonly bool _memory;
|
||||
@@ -84,9 +85,24 @@ public sealed class SqliteDatabase : IDatabase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The library's <c>PRAGMA compile_options</c> (BRIEF §6.2), probed and logged once per process; empty when the
|
||||
/// probe fails. Informational only: Titano uses no optional feature (FTS, JSON), so nothing depends on it; it goes to
|
||||
/// the log and the diagnostics bundle.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<string> CompileOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureLibrary();
|
||||
return ProbedCompileOptions.Value;
|
||||
}
|
||||
}
|
||||
|
||||
internal static SqliteDatabase Open(SqliteSettings settings)
|
||||
{
|
||||
EnsureLibrary();
|
||||
_ = ProbedCompileOptions.Value;
|
||||
var database = new SqliteDatabase(settings);
|
||||
// The first connection validates the path, switches the file to WAL and keeps a memory database alive.
|
||||
database._idle.Push(database.CreateConnection());
|
||||
@@ -259,6 +275,37 @@ public sealed class SqliteDatabase : IDatabase
|
||||
throw new NotSupportedException($"SQLite {version / 1_000_000}.{version / 1000 % 1000}.{version % 1000} is too old; 3.31 or newer is required.");
|
||||
}
|
||||
|
||||
private static IReadOnlyList<string> ProbeCompileOptions()
|
||||
{
|
||||
var options = new List<string>();
|
||||
try
|
||||
{
|
||||
using var connection = SqliteConnection.Open(":memory:", isMemory: true, BusyTimeoutMs);
|
||||
var statement = connection.Rent("PRAGMA compile_options");
|
||||
try
|
||||
{
|
||||
var columns = statement.ReadColumns();
|
||||
int rc;
|
||||
while ((rc = statement.Step()) == SQLITE_ROW)
|
||||
{
|
||||
if (statement.ReadRow(columns).GetStringOrNull(0) is { Length: > 0 } option) options.Add(option);
|
||||
}
|
||||
if (rc != SQLITE_DONE) throw connection.Error(rc);
|
||||
}
|
||||
finally
|
||||
{
|
||||
connection.Return(statement);
|
||||
}
|
||||
}
|
||||
catch (SqliteException ex)
|
||||
{
|
||||
Log.Warning(LogCategory, "PRAGMA compile_options could not be read", ex);
|
||||
return [];
|
||||
}
|
||||
Log.Info(LogCategory, $"SQLite {LibraryVersion}; compile options: {string.Join(' ', options)}");
|
||||
return options;
|
||||
}
|
||||
|
||||
private static void Validate(string backupPath)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in new issue
Block a user