Table of Contents

Class DatabaseUtils

Namespace
WitShells.MapView

Centralized utility for creating and ensuring proper database schema. All code should use EnsureDatabaseWithSchema instead of ad-hoc CreateTable calls.

public static class DatabaseUtils
Inheritance
DatabaseUtils
Inherited Members

Methods

CreateReadOnlyConnection(string)

Creates or opens a read-only database connection with minimal pragmas. Used for background read queries where we don't need to modify schema.

public static SQLiteConnection CreateReadOnlyConnection(string dbPath)

Parameters

dbPath string

Full path to the database file

Returns

SQLiteConnection

SQLiteConnection for read operations, or null on failure

EnsureDatabaseWithSchema(string)

Creates or opens a database connection with proper schema and unique constraints. This is the single method all code should use for database creation.

public static SQLiteConnection EnsureDatabaseWithSchema(string dbPath)

Parameters

dbPath string

Full path to the database file

Returns

SQLiteConnection

Configured SQLiteConnection with proper schema, or null on failure

SafeCloseConnection(SQLiteConnection, bool)

Safely closes and disposes a database connection with optional WAL checkpoint.

public static void SafeCloseConnection(SQLiteConnection connection, bool checkpoint = false)

Parameters

connection SQLiteConnection

Connection to close

checkpoint bool

Whether to perform WAL checkpoint before closing