Path: redb/redb.Export/Flat/Dialects/SqliteFlatDialect.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Export/Flat/Dialects/SqliteFlatDialect.cs ---- using System.Data; using System.Globalization; namespace redb.Export.Flat.Dialects; /// SQLite: rows go through a prepared parameterised INSERT. internal sealed class SqliteFlatDialect : IFlatDialect { public string Quote(string identifier) => "\"" + identifier.Replace("\"", "\"\"") + "\""; public string ColumnType(FlatStorageType type) => type switch { FlatStorageType.Int64 or FlatStorageType.Int32 or FlatStorageType.Int16 or FlatStorageType.Byte => "INTEGER", FlatStorageType.Boolean => "INTEGER", FlatStorageType.Double or FlatStorageType.Single => "REAL", FlatStorageType.Bytes => "BLOB", // Decimals, GUIDs and every date and time form are kept as text: exact and readable. _ => "TEXT" }; // SQLite cannot add a foreign key to an existing table. public bool InlineForeignKeys => true; public string BulkColumnName(string column) => Quote(column); public object ToDbValue(object value, FlatStorageType type) => value switch { bool flag => flag ? 1L : 0L, decimal number => number.ToString(CultureInfo.InvariantCulture), Guid guid => guid.ToString("D").ToUpperInvariant(), DateTime dateTime => dateTime.ToString("yyyy-MM-dd HH:mm:ss.FFFFFFF", CultureInfo.InvariantCulture), DateTimeOffset dateTimeOffset => dateTimeOffset.ToString("yyyy-MM-dd HH:mm:ss.FFFFFFFzzz", CultureInfo.InvariantCulture), DateOnly date => date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), TimeOnly time => time.ToString("HH:mm:ss.fffffff", CultureInfo.InvariantCulture), TimeSpan span => span.ToString("c", CultureInfo.InvariantCulture), char character => character.ToString(), _ => value }; // The only level SQLite has; a read transaction sees one snapshot of the file. public IsolationLevel SnapshotIsolation => IsolationLevel.Serializable; // SQLite has no sequences. An INTEGER PRIMARY KEY is the rowid, and a row inserted without it gets // the next free one of its own table: keys are generated, though per table, not database-wide. public string? CreateSequence(string sequence) => null; public string? RestartSequence(string sequence, long next) => null; public string? KeyDefault(string sequence) => null; public bool AllowsSelfCascade => true; // The sqlite3 shell prints the row. public string Report(string message) => $"SELECT '{message.Replace("'", "''")}' AS result"; }