using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using System.Data.Common; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.Data.Sqlite.Properties; using Microsoft.Data.Sqlite.Utilities; using SQLitePCL; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: InternalsVisibleTo("Microsoft.Data.Sqlite.e_sqlcipher.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.Data.Sqlite.e_sqlite3mc.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.Data.Sqlite.sqlite3.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.Data.Sqlite.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.Data.Sqlite.winsqlite3.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")] [assembly: AssemblyMetadata("CommitHash", "a612c2a1056fe3265387ae3ff7c94eba1505caf9")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: AssemblyCompany("Microsoft Corporation")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")] [assembly: AssemblyDescription("Microsoft.Data.Sqlite is a lightweight ADO.NET provider for SQLite. This package does not include a copy of the native SQLite library.\r\n\r\nCommonly Used Types:\r\nMicrosoft.Data.Sqlite.SqliteCommand\r\nMicrosoft.Data.Sqlite.SqliteConnection\r\nMicrosoft.Data.Sqlite.SqliteConnectionStringBuilder\r\nMicrosoft.Data.Sqlite.SqliteDataReader\r\nMicrosoft.Data.Sqlite.SqliteException\r\nMicrosoft.Data.Sqlite.SqliteFactory\r\nMicrosoft.Data.Sqlite.SqliteParameter\r\nMicrosoft.Data.Sqlite.SqliteTransaction")] [assembly: AssemblyFileVersion("10.0.526.15411")] [assembly: AssemblyInformationalVersion("10.0.5")] [assembly: AssemblyProduct("Microsoft Entity Framework Core")] [assembly: AssemblyTitle("Microsoft.Data.Sqlite")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/dotnet/dotnet")] [assembly: NeutralResourcesLanguage("en-US")] [assembly: AssemblyVersion("10.0.5.0")] [module: RefSafetyRules(11)] [module: System.Runtime.CompilerServices.NullablePublicOnly(true)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class IsReadOnlyAttribute : Attribute { } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class NullablePublicOnlyAttribute : Attribute { public readonly bool IncludesInternals; public NullablePublicOnlyAttribute(bool P_0) { IncludesInternals = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace System { internal static class TypeExtensions { public static Type UnwrapEnumType(this Type type) { if (!type.IsEnum) { return type; } return Enum.GetUnderlyingType(type); } public static Type UnwrapNullableType(this Type type) { return Nullable.GetUnderlyingType(type) ?? type; } } } namespace System.Diagnostics.CodeAnalysis { [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)] internal sealed class AllowNullAttribute : Attribute { } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] internal sealed class MemberNotNullAttribute : Attribute { public string[] Members { get; } public MemberNotNullAttribute(string member) { Members = new string[1] { member }; } public MemberNotNullAttribute(params string[] members) { Members = members; } } } namespace SQLitePCL { internal static class SQLitePCLExtensions { private static readonly Dictionary _knownLibraries = new Dictionary { { "e_sqlcipher", true }, { "e_sqlite3", false }, { "e_sqlite3mc", true }, { "sqlcipher", true }, { "sqlite3mc", true }, { "winsqlite3", false } }; public static bool? EncryptionSupported() { string libraryName; return EncryptionSupported(out libraryName); } public static bool? EncryptionSupported(out string libraryName) { libraryName = raw.GetNativeLibraryName(); if (!_knownLibraries.TryGetValue(libraryName, out var value)) { return null; } return value; } } } namespace Microsoft.Data.Sqlite { internal static class SqliteConnectionExtensions { public static int ExecuteNonQuery(this SqliteConnection connection, string commandText, params SqliteParameter[] parameters) { using SqliteCommand sqliteCommand = connection.CreateCommand(); sqliteCommand.CommandText = commandText; sqliteCommand.Parameters.AddRange(parameters); return sqliteCommand.ExecuteNonQuery(); } public static T ExecuteScalar(this SqliteConnection connection, string commandText, params SqliteParameter[] parameters) { return (T)connection.ExecuteScalar(commandText, parameters); } private static object ExecuteScalar(this SqliteConnection connection, string commandText, params SqliteParameter[] parameters) { using SqliteCommand sqliteCommand = connection.CreateCommand(); sqliteCommand.CommandText = commandText; sqliteCommand.Parameters.AddRange(parameters); return sqliteCommand.ExecuteScalar(); } } public class SqliteBlob : Stream { private sqlite3_blob _blob; private readonly SqliteConnection _connection; private long _position; public override bool CanRead => true; public override bool CanWrite { get; } public override bool CanSeek => true; public override long Length { get; } public override long Position { get { return _position; } set { if (value < 0) { throw new ArgumentOutOfRangeException("value", value, null); } _position = value; } } public SqliteBlob(SqliteConnection connection, string tableName, string columnName, long rowid, bool readOnly = false) : this(connection, "main", tableName, columnName, rowid, readOnly) { } public SqliteBlob(SqliteConnection connection, string databaseName, string tableName, string columnName, long rowid, bool readOnly = false) { if (connection == null || connection.State != ConnectionState.Open) { throw new InvalidOperationException(Resources.SqlBlobRequiresOpenConnection); } if (tableName == null) { throw new ArgumentNullException("tableName"); } if (columnName == null) { throw new ArgumentNullException("columnName"); } _connection = connection; CanWrite = !readOnly; SqliteException.ThrowExceptionForRC(raw.sqlite3_blob_open(_connection.Handle, databaseName, tableName, columnName, rowid, (!readOnly) ? 1 : 0, ref _blob), _connection.Handle); Length = raw.sqlite3_blob_bytes(_blob); } public override int Read(byte[] buffer, int offset, int count) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", offset, null); } if (count < 0) { throw new ArgumentOutOfRangeException("count", count, null); } if (offset + count > buffer.Length) { throw new ArgumentException(Resources.InvalidOffsetAndCount); } return Read(buffer.AsSpan(offset, count)); } public new virtual int Read(Span buffer) { if (_blob == null) { throw new ObjectDisposedException(null); } long num = _position; if (num > Length) { num = Length; } int num2 = buffer.Length; if (num + num2 > Length) { num2 = (int)(Length - num); } if (num2 > 0) { SqliteException.ThrowExceptionForRC(raw.sqlite3_blob_read(_blob, buffer.Slice(0, num2), (int)num), _connection.Handle); } _position += num2; return num2; } public override void Write(byte[] buffer, int offset, int count) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", offset, null); } if (count < 0) { throw new ArgumentOutOfRangeException("count", count, null); } if (offset + count > buffer.Length) { throw new ArgumentException(Resources.InvalidOffsetAndCount); } if (_blob == null) { throw new ObjectDisposedException(null); } Write(buffer.AsSpan(offset, count)); } public new virtual void Write(ReadOnlySpan buffer) { if (!CanWrite) { throw new NotSupportedException(Resources.WriteNotSupported); } long num = _position; if (num > Length) { num = Length; } int length = buffer.Length; if (num + length > Length) { throw new NotSupportedException(Resources.ResizeNotSupported); } if (length > 0) { SqliteException.ThrowExceptionForRC(raw.sqlite3_blob_write(_blob, buffer.Slice(0, length), (int)num), _connection.Handle); } _position += length; } public override long Seek(long offset, SeekOrigin origin) { long num = origin switch { SeekOrigin.Begin => offset, SeekOrigin.Current => _position + offset, SeekOrigin.End => Length + offset, _ => throw new ArgumentException(Resources.InvalidEnumValue(typeof(SeekOrigin), origin), "origin"), }; if (num < 0) { throw new IOException(Resources.SeekBeforeBegin); } return _position = num; } protected override void Dispose(bool disposing) { if (_blob != null) { ((SafeHandle)(object)_blob).Dispose(); _blob = null; } } public override void Flush() { } public override void SetLength(long value) { throw new NotSupportedException(Resources.ResizeNotSupported); } } public enum SqliteCacheMode { Default, Private, Shared } public class SqliteCommand : DbCommand { [CompilerGenerated] private sealed class <>c__DisplayClass54_0 { public string name; internal bool b__0(SqliteParameter p) { return p.ParameterName == name; } } [CompilerGenerated] private sealed class d__54 : IEnumerable, IEnumerable, IEnumerator, IEnumerator, IDisposable { private int <>1__state; private sqlite3_stmt <>2__current; private int <>l__initialThreadId; public SqliteCommand <>4__this; private IEnumerator<(sqlite3_stmt Statement, int ParamCount)> <>7__wrap1; sqlite3_stmt IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__54(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <>7__wrap1 = null; <>1__state = -2; } private bool MoveNext() { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) try { int num = <>1__state; SqliteCommand sqliteCommand = <>4__this; switch (num) { default: return false; case 0: { <>1__state = -1; IEnumerable<(sqlite3_stmt Statement, int ParamCount)> enumerable; if (sqliteCommand._prepared) { IEnumerable<(sqlite3_stmt, int)> preparedStatements = sqliteCommand._preparedStatements; enumerable = preparedStatements; } else { enumerable = sqliteCommand.PrepareAndEnumerateStatements(); } <>7__wrap1 = enumerable.GetEnumerator(); <>1__state = -3; break; } case 1: <>1__state = -3; break; } if (<>7__wrap1.MoveNext()) { (sqlite3_stmt Statement, int ParamCount) current = <>7__wrap1.Current; sqlite3_stmt item = current.Statement; int item2 = current.ParamCount; int num2 = sqliteCommand._parameters?.Bind(item, sqliteCommand.Connection.Handle) ?? 0; if (item2 != num2) { List list = new List(); for (int i = 1; i <= item2; i++) { <>c__DisplayClass54_0 CS$<>8__locals0 = new <>c__DisplayClass54_0(); utf8z val = raw.sqlite3_bind_parameter_name(item, i); CS$<>8__locals0.name = ((utf8z)(ref val)).utf8_to_string(); if (sqliteCommand._parameters != null && !sqliteCommand._parameters.Cast().Any((SqliteParameter p) => p.ParameterName == CS$<>8__locals0.name)) { list.Add(CS$<>8__locals0.name); } } if (raw.sqlite3_libversion_number() < 3028000 || raw.sqlite3_stmt_isexplain(item) == 0) { throw new InvalidOperationException(Resources.MissingParameters(string.Join(", ", list))); } } <>2__current = item; <>1__state = 1; return true; } <>m__Finally1(); <>7__wrap1 = null; return false; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap1 != null) { <>7__wrap1.Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { d__54 result; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; result = this; } else { result = new d__54(0) { <>4__this = <>4__this }; } return result; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__64 : IEnumerable<(sqlite3_stmt Statement, int ParamCount)>, IEnumerable, IEnumerator<(sqlite3_stmt Statement, int ParamCount)>, IEnumerator, IDisposable { private int <>1__state; private (sqlite3_stmt Statement, int ParamCount) <>2__current; private int <>l__initialThreadId; public SqliteCommand <>4__this; private int 5__2; private byte[] 5__3; private TimeSpan 5__4; private int 5__5; (sqlite3_stmt, int) IEnumerator<(sqlite3_stmt, int)>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__64(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { 5__3 = null; <>1__state = -2; } private bool MoveNext() { int num = <>1__state; SqliteCommand sqliteCommand = <>4__this; if (num != 0) { if (num != 1) { return false; } <>1__state = -1; goto IL_018f; } <>1__state = -1; sqliteCommand.DisposePreparedStatements(disposing: false); 5__2 = Encoding.UTF8.GetByteCount(sqliteCommand._commandText); 5__3 = new byte[5__2 + 1]; Encoding.UTF8.GetBytes(sqliteCommand._commandText, 0, sqliteCommand._commandText.Length, 5__3, 0); 5__4 = TimeSpan.Zero; 5__5 = 0; goto IL_0087; IL_0087: SharedStopwatch sharedStopwatch = SharedStopwatch.StartNew(); int rc; sqlite3_stmt val = default(sqlite3_stmt); ReadOnlySpan readOnlySpan = default(ReadOnlySpan); while (IsBusy(rc = raw.sqlite3_prepare_v2(sqliteCommand._connection.Handle, (ReadOnlySpan)5__3.AsSpan(5__5), ref val, ref readOnlySpan)) && (sqliteCommand.CommandTimeout == 0 || !((5__4 + sharedStopwatch.Elapsed).TotalMilliseconds >= (double)((long)sqliteCommand.CommandTimeout * 1000L)))) { Thread.Sleep(150); } 5__4 += sharedStopwatch.Elapsed; 5__5 = 5__3.Length - readOnlySpan.Length; SqliteException.ThrowExceptionForRC(rc, sqliteCommand._connection.Handle); if (((SafeHandle)(object)val).IsInvalid) { if (5__5 < 5__2) { goto IL_018f; } goto IL_01a0; } int item = raw.sqlite3_bind_parameter_count(val); (sqlite3_stmt, int) item2 = (val, item); sqliteCommand._preparedStatements.Add(item2); <>2__current = item2; <>1__state = 1; return true; IL_018f: if (5__5 < 5__2) { goto IL_0087; } goto IL_01a0; IL_01a0: sqliteCommand._prepared = true; return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<(sqlite3_stmt Statement, int ParamCount)> IEnumerable<(sqlite3_stmt, int)>.GetEnumerator() { d__64 result; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; result = this; } else { result = new d__64(0) { <>4__this = <>4__this }; } return result; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<(sqlite3_stmt, int)>)this).GetEnumerator(); } } private SqliteParameterCollection _parameters; private readonly List<(sqlite3_stmt Statement, int ParamCount)> _preparedStatements = new List<(sqlite3_stmt, int)>(1); private SqliteConnection _connection; private string _commandText = string.Empty; private bool _prepared; private int? _commandTimeout; public override CommandType CommandType { get { return CommandType.Text; } set { if (value != CommandType.Text) { throw new ArgumentException(Resources.InvalidCommandType(value)); } } } public override string CommandText { get { return _commandText; } [param: AllowNull] set { if (DataReader != null) { throw new InvalidOperationException(Resources.SetRequiresNoOpenReader("CommandText")); } if (value != _commandText) { DisposePreparedStatements(); _commandText = value ?? string.Empty; } } } public new virtual SqliteConnection? Connection { get { return _connection; } set { if (DataReader != null) { throw new InvalidOperationException(Resources.SetRequiresNoOpenReader("Connection")); } if (value != _connection) { DisposePreparedStatements(); _connection?.RemoveCommand(this); _connection = value; value?.AddCommand(this); } } } protected override DbConnection? DbConnection { get { return Connection; } set { Connection = (SqliteConnection)value; } } public new virtual SqliteTransaction? Transaction { get; set; } protected override DbTransaction? DbTransaction { get { return Transaction; } set { Transaction = (SqliteTransaction)value; } } public new virtual SqliteParameterCollection Parameters => _parameters ?? (_parameters = new SqliteParameterCollection()); protected override DbParameterCollection DbParameterCollection => Parameters; public override int CommandTimeout { get { return _commandTimeout ?? _connection?.DefaultTimeout ?? 30; } set { _commandTimeout = value; } } public override bool DesignTimeVisible { get; set; } public override UpdateRowSource UpdatedRowSource { get; set; } protected internal virtual SqliteDataReader? DataReader { get; set; } public SqliteCommand() { } public SqliteCommand(string? commandText) { CommandText = commandText; } public SqliteCommand(string? commandText, SqliteConnection? connection) : this(commandText) { Connection = connection; } public SqliteCommand(string? commandText, SqliteConnection? connection, SqliteTransaction? transaction) : this(commandText, connection) { Transaction = transaction; } protected override void Dispose(bool disposing) { DisposePreparedStatements(disposing); if (disposing) { _connection?.RemoveCommand(this); } base.Dispose(disposing); } public new virtual SqliteParameter CreateParameter() { return new SqliteParameter(); } protected override DbParameter CreateDbParameter() { return CreateParameter(); } public override void Prepare() { SqliteConnection connection = _connection; if (connection == null || connection.State != ConnectionState.Open) { throw new InvalidOperationException(Resources.CallRequiresOpenConnection("Prepare")); } if (_prepared) { return; } using IEnumerator<(sqlite3_stmt, int)> enumerator = PrepareAndEnumerateStatements().GetEnumerator(); while (enumerator.MoveNext()) { } } public new virtual SqliteDataReader ExecuteReader() { return ExecuteReader(CommandBehavior.Default); } public new virtual SqliteDataReader ExecuteReader(CommandBehavior behavior) { if (DataReader != null) { throw new InvalidOperationException(Resources.DataReaderOpen); } SqliteConnection connection = _connection; if (connection == null || connection.State != ConnectionState.Open) { throw new InvalidOperationException(Resources.CallRequiresOpenConnection("ExecuteReader")); } if (Transaction != _connection.Transaction) { throw new InvalidOperationException((Transaction == null) ? Resources.TransactionRequired : Resources.TransactionConnectionMismatch); } SqliteTransaction? transaction = _connection.Transaction; if (transaction != null && transaction.ExternalRollback) { throw new InvalidOperationException(Resources.TransactionCompleted); } bool closeConnection = behavior.HasFlag(CommandBehavior.CloseConnection); SqliteDataReader sqliteDataReader = new SqliteDataReader(this, GetStatements(), closeConnection); sqliteDataReader.NextResult(); return DataReader = sqliteDataReader; } [IteratorStateMachine(typeof(d__54))] private IEnumerable GetStatements() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__54(-2) { <>4__this = this }; } protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { return ExecuteReader(behavior); } public new virtual Task ExecuteReaderAsync() { return ExecuteReaderAsync(CommandBehavior.Default, CancellationToken.None); } public new virtual Task ExecuteReaderAsync(CancellationToken cancellationToken) { return ExecuteReaderAsync(CommandBehavior.Default, cancellationToken); } public new virtual Task ExecuteReaderAsync(CommandBehavior behavior) { return ExecuteReaderAsync(behavior, CancellationToken.None); } public new virtual Task ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); return Task.FromResult(ExecuteReader(behavior)); } protected override async Task ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) { return await ExecuteReaderAsync(behavior, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); } public override int ExecuteNonQuery() { SqliteConnection connection = _connection; if (connection == null || connection.State != ConnectionState.Open) { throw new InvalidOperationException(Resources.CallRequiresOpenConnection("ExecuteNonQuery")); } SqliteDataReader sqliteDataReader = ExecuteReader(); sqliteDataReader.Dispose(); return sqliteDataReader.RecordsAffected; } public override object? ExecuteScalar() { SqliteConnection connection = _connection; if (connection == null || connection.State != ConnectionState.Open) { throw new InvalidOperationException(Resources.CallRequiresOpenConnection("ExecuteScalar")); } using SqliteDataReader sqliteDataReader = ExecuteReader(); return sqliteDataReader.Read() ? sqliteDataReader.GetValue(0) : null; } public override void Cancel() { } [IteratorStateMachine(typeof(d__64))] private IEnumerable<(sqlite3_stmt Statement, int ParamCount)> PrepareAndEnumerateStatements() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__64(-2) { <>4__this = this }; } private void DisposePreparedStatements(bool disposing = true) { if (disposing && DataReader != null) { DataReader.Dispose(); DataReader = null; } if (_preparedStatements != null) { foreach (var preparedStatement in _preparedStatements) { ((SafeHandle)(object)preparedStatement.Statement).Dispose(); } _preparedStatements.Clear(); } _prepared = false; } private static bool IsBusy(int rc) { if ((uint)(rc - 5) <= 1u || rc == 262) { return true; } return false; } } public class SqliteConnection : DbConnection { private sealed class AggregateDefinition { public string Name { get; } public TAccumulate Seed { get; } public Func Func { get; } public Func ResultSelector { get; } public AggregateDefinition(string name, TAccumulate seed, Func func, Func resultSelector) { Name = name; Seed = seed; Func = func; ResultSelector = resultSelector; base..ctor(); } } private sealed class AggregateContext { public T Accumulate { get; set; } public Exception Exception { get; set; } public AggregateContext(T seed) { Accumulate = seed; base..ctor(); } } private sealed class FunctionsKeyComparer : IEqualityComparer<(string name, int arity)> { public static readonly FunctionsKeyComparer Instance = new FunctionsKeyComparer(); public bool Equals((string name, int arity) x, (string name, int arity) y) { if (StringComparer.OrdinalIgnoreCase.Equals(x.name, y.name)) { return x.arity == y.arity; } return false; } public int GetHashCode((string name, int arity) obj) { int hashCode = StringComparer.OrdinalIgnoreCase.GetHashCode(obj.name); int hashCode2 = obj.arity.GetHashCode(); return (((hashCode << 5) | (hashCode >>> 27)) + hashCode) ^ hashCode2; } } [Serializable] [CompilerGenerated] private sealed class <>c__162 { public static readonly <>c__162 <>9 = new <>c__162(); public static delegate_function_aggregate_step <>9__162_0; public static delegate_function_aggregate_final <>9__162_1; internal void b__162_0(sqlite3_context ctx, object user_data, sqlite3_value[] args) { AggregateDefinition aggregateDefinition = (AggregateDefinition)user_data; if (ctx.state == null) { ctx.state = new AggregateContext(aggregateDefinition.Seed); } AggregateContext aggregateContext = (AggregateContext)ctx.state; if (aggregateContext.Exception != null) { return; } SqliteParameterReader arg = new SqliteParameterReader(aggregateDefinition.Name, args); try { aggregateContext.Accumulate = aggregateDefinition.Func(aggregateContext.Accumulate, arg); } catch (Exception exception) { aggregateContext.Exception = exception; } } internal void b__162_1(sqlite3_context ctx, object user_data) { AggregateDefinition aggregateDefinition = (AggregateDefinition)user_data; if (ctx.state == null) { ctx.state = new AggregateContext(aggregateDefinition.Seed); } AggregateContext aggregateContext = (AggregateContext)ctx.state; if (aggregateContext.Exception == null) { try { TResult val = aggregateDefinition.ResultSelector(aggregateContext.Accumulate); new SqliteResultBinder(ctx, val).Bind(); } catch (Exception exception) { aggregateContext.Exception = exception; } } if (aggregateContext.Exception != null) { raw.sqlite3_result_error(ctx, aggregateContext.Exception.Message); if (aggregateContext.Exception is SqliteException ex) { raw.sqlite3_result_error_code(ctx, ex.SqliteErrorCode); } } } } [CompilerGenerated] private sealed class d__154 : IEnumerable, IEnumerable, IEnumerator, IEnumerator, IDisposable { private int <>1__state; private string <>2__current; private int <>l__initialThreadId; private string file; public string <>3__file; private bool 5__2; private string[] <>7__wrap2; private int <>7__wrap3; private string 5__5; string IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__154(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { <>7__wrap2 = null; 5__5 = null; <>1__state = -2; } private bool MoveNext() { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = file; <>1__state = 1; return true; case 1: <>1__state = -1; if (!string.IsNullOrEmpty(Path.GetDirectoryName(file))) { return false; } 5__2 = !file.StartsWith("lib", StringComparison.Ordinal) && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows); if (5__2) { <>2__current = "lib" + file; <>1__state = 2; return true; } goto IL_00b1; case 2: <>1__state = -1; goto IL_00b1; case 3: <>1__state = -1; if (5__2) { <>2__current = Path.Combine(5__5, "lib" + file); <>1__state = 4; return true; } goto IL_014c; case 4: { <>1__state = -1; goto IL_014c; } IL_00b1: if (NativeDllSearchDirectories == null) { NativeDllSearchDirectories = GetNativeDllSearchDirectories(); } <>7__wrap2 = NativeDllSearchDirectories; <>7__wrap3 = 0; break; IL_014c: 5__5 = null; <>7__wrap3++; break; } if (<>7__wrap3 < <>7__wrap2.Length) { 5__5 = <>7__wrap2[<>7__wrap3]; <>2__current = Path.Combine(5__5, file); <>1__state = 3; return true; } <>7__wrap2 = null; return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { d__154 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__154(0); } d__.file = <>3__file; return d__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } } internal const string MainDatabaseName = "main"; private const int SQLITE_WIN32_DATA_DIRECTORY_TYPE = 1; private const int SQLITE_WIN32_TEMP_DIRECTORY_TYPE = 2; private readonly List> _commands = new List>(); private Dictionary _collations; private Dictionary<(string name, int arity), (int flags, object state, delegate_function_scalar func)> _functions; private Dictionary<(string name, int arity), (int flags, object state, delegate_function_aggregate_step func_step, delegate_function_aggregate_final func_final)> _aggregates; private HashSet<(string file, string proc)> _extensions; private string _connectionString; private ConnectionState _state; private SqliteConnectionInternal _innerConnection; private bool _extensionsEnabled; private int? _defaultTimeout; private static readonly StateChangeEventArgs _fromClosedToOpenEventArgs; private static readonly StateChangeEventArgs _fromOpenToClosedEventArgs; private static string[] NativeDllSearchDirectories; public virtual sqlite3? Handle => _innerConnection?.Handle; public override string ConnectionString { get { return _connectionString; } [MemberNotNull(new string[] { "_connectionString", "PoolGroup" })] [param: AllowNull] set { if (State != 0) { throw new InvalidOperationException(Resources.ConnectionStringRequiresClosedConnection); } _connectionString = value ?? string.Empty; PoolGroup = SqliteConnectionFactory.Instance.GetPoolGroup(_connectionString); } } internal SqliteConnectionPoolGroup PoolGroup { get; set; } internal SqliteConnectionStringBuilder ConnectionOptions => PoolGroup.ConnectionOptions; public override string Database => "main"; public override string DataSource { get { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) string text = null; if (State == ConnectionState.Open) { utf8z val = raw.sqlite3_db_filename(Handle, "main"); text = ((utf8z)(ref val)).utf8_to_string(); } return text ?? ConnectionOptions.DataSource; } } public virtual int DefaultTimeout { get { return _defaultTimeout ?? ConnectionOptions.DefaultTimeout; } set { _defaultTimeout = value; } } public override string ServerVersion { get { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) utf8z val = raw.sqlite3_libversion(); return ((utf8z)(ref val)).utf8_to_string(); } } public override ConnectionState State => _state; protected override DbProviderFactory DbProviderFactory => SqliteFactory.Instance; protected internal virtual SqliteTransaction? Transaction { get; set; } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 0, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a)), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 1, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 2, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 3, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 4, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 5, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 6, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 7, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 8, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 9, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 10, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 11, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 12, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 13, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 14, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 15, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13), r.GetFieldValue(14))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, -1, default(TAccumulate), IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, GetValues(r))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 0, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a)), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 1, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 2, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 3, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 4, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 5, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 6, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 7, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 8, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 9, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 10, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 11, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 12, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 13, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 14, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 15, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13), r.GetFieldValue(14))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, -1, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, GetValues(r))), (TAccumulate a) => a, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 0, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a)), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 1, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 2, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 3, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 4, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 5, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 6, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 7, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 8, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 9, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 10, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 11, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 12, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 13, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 14, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, 15, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13), r.GetFieldValue(14))), resultSelector, isDeterministic); } public virtual void CreateAggregate(string name, TAccumulate seed, Func? func, Func? resultSelector, bool isDeterministic = false) { Func func2 = func; CreateAggregateCore(name, -1, seed, IfNotNull(func2, (TAccumulate a, SqliteValueReader r) => func2(a, GetValues(r))), resultSelector, isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 0, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2()), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 1, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 2, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 3, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 4, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 5, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 6, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 7, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 8, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 9, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 10, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 11, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 12, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 13, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 14, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 15, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13), r.GetFieldValue(14))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 16, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13), r.GetFieldValue(14), r.GetFieldValue(15))), isDeterministic); } public virtual void CreateFunction(string name, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, -1, null, IfNotNull(function2, (object s, SqliteValueReader r) => function2(GetValues(r))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 0, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s)), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 1, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 2, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 3, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 4, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 5, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 6, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 7, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 8, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 9, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 10, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 11, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 12, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 13, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 14, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, 15, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, r.GetFieldValue(0), r.GetFieldValue(1), r.GetFieldValue(2), r.GetFieldValue(3), r.GetFieldValue(4), r.GetFieldValue(5), r.GetFieldValue(6), r.GetFieldValue(7), r.GetFieldValue(8), r.GetFieldValue(9), r.GetFieldValue(10), r.GetFieldValue(11), r.GetFieldValue(12), r.GetFieldValue(13), r.GetFieldValue(14))), isDeterministic); } public virtual void CreateFunction(string name, TState state, Func? function, bool isDeterministic = false) { Func function2 = function; CreateFunctionCore(name, -1, state, IfNotNull(function2, (TState s, SqliteValueReader r) => function2(s, GetValues(r))), isDeterministic); } static SqliteConnection() { _fromClosedToOpenEventArgs = new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open); _fromOpenToClosedEventArgs = new StateChangeEventArgs(ConnectionState.Open, ConnectionState.Closed); Type.GetType("SQLitePCL.Batteries_V2, SQLitePCLRaw.batteries_v2")?.GetRuntimeMethod("Init", Type.EmptyTypes)?.Invoke(null, null); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return; } Type type = null; Type type2 = null; try { type = Type.GetType("Windows.Storage.ApplicationData, Windows, ContentType=WindowsRuntime") ?? Type.GetType("Windows.Storage.ApplicationData, Microsoft.Windows.SDK.NET"); type2 = Type.GetType("Windows.Storage.StorageFolder, Windows, ContentType=WindowsRuntime") ?? Type.GetType("Windows.Storage.StorageFolder, Microsoft.Windows.SDK.NET"); } catch { } object obj2 = null; try { obj2 = type?.GetRuntimeProperty("Current")?.GetValue(null); } catch (TargetInvocationException) { } if (obj2 != null) { object obj3 = type?.GetRuntimeProperty("LocalFolder")?.GetValue(obj2); string text = (string)type2?.GetRuntimeProperty("Path")?.GetValue(obj3); if (text != null) { raw.sqlite3_win32_set_directory(1, text); } object obj4 = type?.GetRuntimeProperty("TemporaryFolder")?.GetValue(obj2); string text2 = (string)type2?.GetRuntimeProperty("Path")?.GetValue(obj4); if (text2 != null) { raw.sqlite3_win32_set_directory(2, text2); } } } public SqliteConnection() : this(null) { } public SqliteConnection(string? connectionString) { ConnectionString = connectionString; } public static void ClearAllPools() { SqliteConnectionFactory.Instance.ClearPools(); } public static void ClearPool(SqliteConnection connection) { connection.PoolGroup.Clear(); } public override void Open() { if (State == ConnectionState.Open) { return; } _innerConnection = SqliteConnectionFactory.Instance.GetConnection(this); _state = ConnectionState.Open; try { if (ConnectionOptions.ForeignKeys.HasValue) { this.ExecuteNonQuery("PRAGMA foreign_keys = " + (ConnectionOptions.ForeignKeys.Value ? "1" : "0") + ";"); } if (ConnectionOptions.RecursiveTriggers) { this.ExecuteNonQuery("PRAGMA recursive_triggers = 1;"); } if (_collations != null) { foreach (KeyValuePair collation in _collations) { SqliteException.ThrowExceptionForRC(raw.sqlite3_create_collation(Handle, collation.Key, collation.Value.Item1, collation.Value.Item2), Handle); } } if (_functions != null) { foreach (KeyValuePair<(string, int), (int, object, delegate_function_scalar)> function in _functions) { SqliteException.ThrowExceptionForRC(raw.sqlite3_create_function(Handle, function.Key.Item1, function.Key.Item2, function.Value.Item2, function.Value.Item3), Handle); } } if (_aggregates != null) { foreach (KeyValuePair<(string, int), (int, object, delegate_function_aggregate_step, delegate_function_aggregate_final)> aggregate in _aggregates) { SqliteException.ThrowExceptionForRC(raw.sqlite3_create_function(Handle, aggregate.Key.Item1, aggregate.Key.Item2, aggregate.Value.Item2, aggregate.Value.Item3, aggregate.Value.Item4), Handle); } } if (_extensions != null && _extensions.Count != 0) { int num = default(int); SqliteException.ThrowExceptionForRC(raw.sqlite3_db_config(Handle, 1005, 1, ref num), Handle); foreach (var extension in _extensions) { LoadExtensionCore(extension.file, extension.proc); } } if (_extensionsEnabled) { SqliteException.ThrowExceptionForRC(raw.sqlite3_enable_load_extension(Handle, _extensionsEnabled ? 1 : 0), Handle); } } catch { _innerConnection.Close(); _innerConnection = null; _state = ConnectionState.Closed; throw; } OnStateChange(_fromClosedToOpenEventArgs); } public override void Close() { if (State != ConnectionState.Open) { return; } Transaction?.Dispose(); List> commands = _commands; for (int num = commands.Count - 1; num >= 0; num--) { if (commands[num].TryGetTarget(out var target)) { target.Dispose(); } } _commands.Clear(); _innerConnection.Close(); _innerConnection = null; _state = ConnectionState.Closed; OnStateChange(_fromOpenToClosedEventArgs); } internal void Deactivate() { if (_collations != null) { foreach (string key in _collations.Keys) { SqliteException.ThrowExceptionForRC(raw.sqlite3_create_collation(Handle, key, (object)null, (strdelegate_collation)null), Handle); } } if (_functions != null) { foreach (var (text, num) in _functions.Keys) { SqliteException.ThrowExceptionForRC(raw.sqlite3_create_function(Handle, text, num, (object)null, (delegate_function_scalar)null), Handle); } } if (_aggregates != null) { foreach (var (text2, num2) in _aggregates.Keys) { SqliteException.ThrowExceptionForRC(raw.sqlite3_create_function(Handle, text2, num2, (object)null, (delegate_function_aggregate_step)null, (delegate_function_aggregate_final)null), Handle); } } if (_extensionsEnabled) { SqliteException.ThrowExceptionForRC(raw.sqlite3_enable_load_extension(Handle, 0), Handle); } } protected override void Dispose(bool disposing) { if (disposing) { Close(); } base.Dispose(disposing); } public new virtual SqliteCommand CreateCommand() { return new SqliteCommand { Connection = this, CommandTimeout = DefaultTimeout, Transaction = Transaction }; } protected override DbCommand CreateDbCommand() { return CreateCommand(); } internal void AddCommand(SqliteCommand command) { _commands.Add(new WeakReference(command)); } internal void RemoveCommand(SqliteCommand command) { for (int num = _commands.Count - 1; num >= 0; num--) { WeakReference weakReference = _commands[num]; if (weakReference != null && weakReference.TryGetTarget(out var target) && target == command) { _commands.RemoveAt(num); } } } public virtual void CreateCollation(string name, Comparison? comparison) { Comparison comparison2 = comparison; CreateCollation(name, null, (comparison2 != null) ? ((Func)((object _, string s1, string s2) => comparison2(s1, s2))) : null); } public virtual void CreateCollation(string name, T state, Func? comparison) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) Func comparison2 = comparison; if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } strdelegate_collation val = ((comparison2 == null) ? ((strdelegate_collation)null) : ((strdelegate_collation)((object v, string s1, string s2) => comparison2((T)v, s1, s2)))); if (State == ConnectionState.Open) { SqliteException.ThrowExceptionForRC(raw.sqlite3_create_collation(Handle, name, (object)state, val), Handle); } if (_collations == null) { _collations = new Dictionary(StringComparer.OrdinalIgnoreCase); } _collations[name] = (state, val); } public new virtual SqliteTransaction BeginTransaction() { return BeginTransaction(IsolationLevel.Unspecified); } public virtual SqliteTransaction BeginTransaction(bool deferred) { return BeginTransaction(IsolationLevel.Unspecified, deferred); } protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) { return BeginTransaction(isolationLevel); } public new virtual SqliteTransaction BeginTransaction(IsolationLevel isolationLevel) { return BeginTransaction(isolationLevel, isolationLevel == IsolationLevel.ReadUncommitted); } public virtual SqliteTransaction BeginTransaction(IsolationLevel isolationLevel, bool deferred) { if (State != ConnectionState.Open) { throw new InvalidOperationException(Resources.CallRequiresOpenConnection("BeginTransaction")); } if (Transaction != null) { throw new InvalidOperationException(Resources.ParallelTransactionsNotSupported); } return Transaction = new SqliteTransaction(this, isolationLevel, deferred); } public override void ChangeDatabase(string databaseName) { throw new NotSupportedException(); } public virtual void EnableExtensions(bool enable = true) { if (State == ConnectionState.Open) { SqliteException.ThrowExceptionForRC(raw.sqlite3_enable_load_extension(Handle, enable ? 1 : 0), Handle); } _extensionsEnabled = enable; } public virtual void LoadExtension(string file, string? proc = null) { if (State == ConnectionState.Open) { if (!_extensionsEnabled) { int num = default(int); SqliteException.ThrowExceptionForRC(raw.sqlite3_db_config(Handle, 1005, 1, ref num), Handle); } LoadExtensionCore(file, proc); } if (_extensions == null) { _extensions = new HashSet<(string, string)>(); } _extensions.Add((file, proc)); } private void LoadExtensionCore(string file, string proc) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) SqliteException ex = null; utf8z val = default(utf8z); foreach (string loadExtensionPath in GetLoadExtensionPaths(file)) { int num = raw.sqlite3_load_extension(Handle, utf8z.FromString(loadExtensionPath), utf8z.FromString(proc), ref val); if (num == 0) { return; } if (ex == null) { ex = new SqliteException(Resources.SqliteNativeError(num, ((utf8z)(ref val)).utf8_to_string()), num, num); } } if (ex != null) { throw ex; } } [IteratorStateMachine(typeof(d__154))] private static IEnumerable GetLoadExtensionPaths(string file) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__154(-2) { <>3__file = file }; } private static string[] GetNativeDllSearchDirectories() { string text = AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES") as string; if (!string.IsNullOrEmpty(text)) { return text.Split(new char[1] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries); } return Array.Empty(); } public virtual void BackupDatabase(SqliteConnection destination) { BackupDatabase(destination, "main", "main"); } public virtual void BackupDatabase(SqliteConnection destination, string destinationName, string sourceName) { if (State != ConnectionState.Open) { throw new InvalidOperationException(Resources.CallRequiresOpenConnection("BackupDatabase")); } if (destination == null) { throw new ArgumentNullException("destination"); } bool flag = false; if (destination.State != ConnectionState.Open) { destination.Open(); flag = true; } try { sqlite3_backup val = raw.sqlite3_backup_init(destination.Handle, destinationName, Handle, sourceName); try { if (((SafeHandle)(object)val).IsInvalid) { SqliteException.ThrowExceptionForRC(raw.sqlite3_errcode(destination.Handle), destination.Handle); } SqliteException.ThrowExceptionForRC(raw.sqlite3_backup_step(val, -1), destination.Handle); } finally { ((IDisposable)val)?.Dispose(); } } finally { if (flag) { destination.Close(); } } } public override DataTable GetSchema() { return GetSchema(DbMetaDataCollectionNames.MetaDataCollections); } public override DataTable GetSchema(string collectionName) { return GetSchema(collectionName, Array.Empty()); } public override DataTable GetSchema(string collectionName, string?[] restrictionValues) { if (restrictionValues != null && restrictionValues.Length != 0) { throw new ArgumentException(Resources.TooManyRestrictions(collectionName)); } if (string.Equals(collectionName, DbMetaDataCollectionNames.MetaDataCollections, StringComparison.OrdinalIgnoreCase)) { DataTable dataTable = new DataTable(DbMetaDataCollectionNames.MetaDataCollections); dataTable.Columns.Add(DbMetaDataColumnNames.CollectionName); dataTable.Columns.Add(DbMetaDataColumnNames.NumberOfRestrictions, typeof(int)); dataTable.Columns.Add(DbMetaDataColumnNames.NumberOfIdentifierParts, typeof(int)); dataTable.Rows.Add(DbMetaDataCollectionNames.MetaDataCollections, 0, 0); dataTable.Rows.Add(DbMetaDataCollectionNames.ReservedWords, 0, 0); return dataTable; } if (string.Equals(collectionName, DbMetaDataCollectionNames.ReservedWords, StringComparison.OrdinalIgnoreCase)) { DataTable dataTable2 = new DataTable(DbMetaDataCollectionNames.ReservedWords) { Columns = { DbMetaDataColumnNames.ReservedWord } }; int num = raw.sqlite3_keyword_count(); string text = default(string); for (int i = 0; i < num; i++) { SqliteException.ThrowExceptionForRC(raw.sqlite3_keyword_name(i, ref text), null); dataTable2.Rows.Add(text); } return dataTable2; } throw new ArgumentException(Resources.UnknownCollection(collectionName)); } private void CreateFunctionCore(string name, int arity, TState state, Func function, bool isDeterministic) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown if (name == null) { throw new ArgumentNullException("name"); } delegate_function_scalar val = null; if (function != null) { val = (delegate_function_scalar)delegate(sqlite3_context ctx, object user_data, sqlite3_value[] args) { SqliteParameterReader arg = new SqliteParameterReader(name, args); try { TResult val2 = function((TState)user_data, arg); new SqliteResultBinder(ctx, val2).Bind(); } catch (Exception ex) { raw.sqlite3_result_error(ctx, ex.Message); if (ex is SqliteException ex2) { raw.sqlite3_result_error_code(ctx, ex2.SqliteErrorCode); } } }; } int num = (isDeterministic ? 2048 : 0); if (State == ConnectionState.Open) { SqliteException.ThrowExceptionForRC(raw.sqlite3_create_function(Handle, name, arity, num, (object)state, val), Handle); } if (_functions == null) { _functions = new Dictionary<(string, int), (int, object, delegate_function_scalar)>(FunctionsKeyComparer.Instance); } _functions[(name, arity)] = (num, state, val); } private void CreateAggregateCore(string name, int arity, TAccumulate seed, Func func, Func resultSelector, bool isDeterministic) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown if (name == null) { throw new ArgumentNullException("name"); } delegate_function_aggregate_step val = null; if (func != null) { object obj = <>c__162.<>9__162_0; if (obj == null) { delegate_function_aggregate_step val2 = delegate(sqlite3_context ctx, object user_data, sqlite3_value[] args) { AggregateDefinition aggregateDefinition3 = (AggregateDefinition)user_data; if (ctx.state == null) { ctx.state = new AggregateContext(aggregateDefinition3.Seed); } AggregateContext aggregateContext2 = (AggregateContext)ctx.state; if (aggregateContext2.Exception != null) { return; } SqliteParameterReader arg = new SqliteParameterReader(aggregateDefinition3.Name, args); try { aggregateContext2.Accumulate = aggregateDefinition3.Func(aggregateContext2.Accumulate, arg); } catch (Exception exception2) { aggregateContext2.Exception = exception2; } }; <>c__162.<>9__162_0 = val2; obj = (object)val2; } val = (delegate_function_aggregate_step)obj; } delegate_function_aggregate_final val3 = null; if (resultSelector != null) { object obj2 = <>c__162.<>9__162_1; if (obj2 == null) { delegate_function_aggregate_final val4 = delegate(sqlite3_context ctx, object user_data) { AggregateDefinition aggregateDefinition2 = (AggregateDefinition)user_data; if (ctx.state == null) { ctx.state = new AggregateContext(aggregateDefinition2.Seed); } AggregateContext aggregateContext = (AggregateContext)ctx.state; if (aggregateContext.Exception == null) { try { TResult val5 = aggregateDefinition2.ResultSelector(aggregateContext.Accumulate); new SqliteResultBinder(ctx, val5).Bind(); } catch (Exception exception) { aggregateContext.Exception = exception; } } if (aggregateContext.Exception != null) { raw.sqlite3_result_error(ctx, aggregateContext.Exception.Message); if (aggregateContext.Exception is SqliteException ex) { raw.sqlite3_result_error_code(ctx, ex.SqliteErrorCode); } } }; <>c__162.<>9__162_1 = val4; obj2 = (object)val4; } val3 = (delegate_function_aggregate_final)obj2; } int num = (isDeterministic ? 2048 : 0); AggregateDefinition aggregateDefinition = new AggregateDefinition(name, seed, func, resultSelector); if (State == ConnectionState.Open) { SqliteException.ThrowExceptionForRC(raw.sqlite3_create_function(Handle, name, arity, num, (object)aggregateDefinition, val, val3), Handle); } if (_aggregates == null) { _aggregates = new Dictionary<(string, int), (int, object, delegate_function_aggregate_step, delegate_function_aggregate_final)>(FunctionsKeyComparer.Instance); } _aggregates[(name, arity)] = (num, aggregateDefinition, val, val3); } private static Func IfNotNull(object x, Func value) { if (x == null) { return null; } return value; } private static object[] GetValues(SqliteValueReader reader) { object[] array = new object[reader.FieldCount]; reader.GetValues(array); return array; } } internal class SqliteConnectionFactory { public static readonly SqliteConnectionFactory Instance = new SqliteConnectionFactory(); private readonly Timer _pruneTimer; private readonly List _idlePoolGroups = new List(); private readonly List _poolsToRelease = new List(); private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(); private Dictionary _poolGroups = new Dictionary(); protected SqliteConnectionFactory() { AppDomain.CurrentDomain.DomainUnload += delegate { ClearPools(); }; AppDomain.CurrentDomain.ProcessExit += delegate { ClearPools(); }; _pruneTimer = new Timer(PruneCallback, null, TimeSpan.FromMinutes(4.0), TimeSpan.FromSeconds(30.0)); } public SqliteConnectionInternal GetConnection(SqliteConnection outerConnection) { SqliteConnectionPoolGroup sqliteConnectionPoolGroup = outerConnection.PoolGroup; if (sqliteConnectionPoolGroup != null && sqliteConnectionPoolGroup.IsDisabled && !sqliteConnectionPoolGroup.IsNonPooled) { sqliteConnectionPoolGroup = (outerConnection.PoolGroup = GetPoolGroup(sqliteConnectionPoolGroup.ConnectionString)); } SqliteConnectionPool pool = sqliteConnectionPoolGroup.GetPool(); SqliteConnectionInternal obj = ((pool == null) ? new SqliteConnectionInternal(outerConnection.ConnectionOptions) : pool.GetConnection()); obj.Activate(outerConnection); return obj; } public SqliteConnectionPoolGroup GetPoolGroup(string connectionString) { _lock.EnterUpgradeableReadLock(); try { if (!_poolGroups.TryGetValue(connectionString, out var value) || (value.IsDisabled && !value.IsNonPooled)) { SqliteConnectionStringBuilder sqliteConnectionStringBuilder = new SqliteConnectionStringBuilder(connectionString); _lock.EnterWriteLock(); try { if (!_poolGroups.TryGetValue(connectionString, out value)) { bool isNonPooled = sqliteConnectionStringBuilder.DataSource == ":memory:" || sqliteConnectionStringBuilder.Mode == SqliteOpenMode.Memory || sqliteConnectionStringBuilder.DataSource.Length == 0 || !sqliteConnectionStringBuilder.Pooling; value = new SqliteConnectionPoolGroup(sqliteConnectionStringBuilder, connectionString, isNonPooled); _poolGroups.Add(connectionString, value); } } finally { _lock.ExitWriteLock(); } } return value; } finally { _lock.ExitUpgradeableReadLock(); } } public void ReleasePool(SqliteConnectionPool pool, bool clearing) { pool.Shutdown(); lock (_poolsToRelease) { if (clearing) { pool.Clear(); } _poolsToRelease.Add(pool); } } public void ClearPools() { _lock.EnterWriteLock(); try { foreach (KeyValuePair poolGroup in _poolGroups) { poolGroup.Value.Clear(); } } finally { _lock.ExitWriteLock(); } } private void PruneCallback(object _) { lock (_poolsToRelease) { for (int num = _poolsToRelease.Count - 1; num >= 0; num--) { SqliteConnectionPool sqliteConnectionPool = _poolsToRelease[num]; sqliteConnectionPool.Clear(); if (sqliteConnectionPool.Count == 0) { _poolsToRelease.Remove(sqliteConnectionPool); } } } _lock.EnterWriteLock(); try { for (int num2 = _idlePoolGroups.Count - 1; num2 >= 0; num2--) { SqliteConnectionPoolGroup sqliteConnectionPoolGroup = _idlePoolGroups[num2]; if (!sqliteConnectionPoolGroup.Clear()) { _idlePoolGroups.Remove(sqliteConnectionPoolGroup); } } Dictionary dictionary = new Dictionary(); foreach (KeyValuePair poolGroup in _poolGroups) { SqliteConnectionPoolGroup value = poolGroup.Value; if (value.Prune()) { _idlePoolGroups.Add(value); } else { dictionary.Add(poolGroup.Key, value); } } _poolGroups = dictionary; } finally { _lock.ExitWriteLock(); } } } internal class SqliteConnectionInternal { private const string DataDirectoryMacro = "|DataDirectory|"; private readonly sqlite3 _db; private readonly WeakReference _outerConnection = new WeakReference(null); private SqliteConnectionPool _pool; private volatile bool _active; private volatile bool _canBePooled = true; public bool Leaked { get { SqliteConnection target; if (_active) { return !_outerConnection.TryGetTarget(out target); } return false; } } public bool CanBePooled { get { SqliteConnection target; if (_canBePooled) { return !_outerConnection.TryGetTarget(out target); } return false; } } public sqlite3? Handle => _db; public SqliteConnectionInternal(SqliteConnectionStringBuilder connectionOptions, SqliteConnectionPool? pool = null) { string text = connectionOptions.DataSource; int num = 0; if (text.StartsWith("file:", StringComparison.OrdinalIgnoreCase)) { num |= 0x40; } switch (connectionOptions.Mode) { case SqliteOpenMode.ReadOnly: num |= 1; break; case SqliteOpenMode.ReadWrite: num |= 2; break; case SqliteOpenMode.Memory: num |= 0x86; if ((num & 0x40) == 0) { num |= 0x40; text = "file:" + text; } break; default: num |= 6; break; } switch (connectionOptions.Cache) { case SqliteCacheMode.Shared: num |= 0x20000; break; case SqliteCacheMode.Private: num |= 0x40000; break; } string text2 = AppDomain.CurrentDomain.GetData("DataDirectory") as string; if (!string.IsNullOrEmpty(text2) && (num & 0x40) == 0 && !text.Equals(":memory:", StringComparison.OrdinalIgnoreCase)) { if (text.StartsWith("|DataDirectory|", StringComparison.InvariantCultureIgnoreCase)) { text = Path.Combine(text2, text.Substring("|DataDirectory|".Length)); } else if (!Path.IsPathRooted(text)) { text = Path.Combine(text2, text); } } string text3 = ((!string.IsNullOrWhiteSpace(connectionOptions.Vfs)) ? connectionOptions.Vfs : null); int rc = raw.sqlite3_open_v2(text, ref _db, num, text3); try { SqliteException.ThrowExceptionForRC(rc, _db); if (connectionOptions.Password.Length != 0) { if (SQLitePCLExtensions.EncryptionSupported(out string libraryName) == false) { throw new InvalidOperationException(Resources.EncryptionNotSupported(libraryName)); } string text4 = QuotePassword(connectionOptions.Password); ExecuteNonQuery("PRAGMA key = " + text4 + ";", connectionOptions.DefaultTimeout); if (SQLitePCLExtensions.EncryptionSupported() != false) { ExecuteNonQuery("SELECT COUNT(*) FROM sqlite_master;", connectionOptions.DefaultTimeout); } } if (connectionOptions.ForeignKeys.HasValue) { ExecuteNonQuery("PRAGMA foreign_keys = " + (connectionOptions.ForeignKeys.Value ? "1" : "0") + ";", connectionOptions.DefaultTimeout); } if (connectionOptions.RecursiveTriggers) { ExecuteNonQuery("PRAGMA recursive_triggers = 1;", connectionOptions.DefaultTimeout); } } catch { ((SafeHandle)(object)_db).Dispose(); throw; } _pool = pool; } public void DoNotPool() { _canBePooled = false; } public void Activate(SqliteConnection outerConnection) { _active = true; _outerConnection.SetTarget(outerConnection); } public void Close() { if (_pool != null) { _pool.Return(this); } else { Dispose(); } } public void Deactivate() { if (_outerConnection.TryGetTarget(out var target)) { target.Deactivate(); } _outerConnection.SetTarget(null); _active = false; } public void Dispose() { ((SafeHandle)(object)_db).Dispose(); _pool = null; } private string QuotePassword(string password) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) sqlite3 val = default(sqlite3); SqliteException.ThrowExceptionForRC(raw.sqlite3_open(":memory:", ref val), val); try { sqlite3_stmt val2 = default(sqlite3_stmt); SqliteException.ThrowExceptionForRC(raw.sqlite3_prepare_v2(val, "SELECT quote($password);", ref val2), val); try { raw.sqlite3_bind_text(val2, 1, password); SqliteException.ThrowExceptionForRC(raw.sqlite3_step(val2), val); utf8z val3 = raw.sqlite3_column_text(val2, 0); return ((utf8z)(ref val3)).utf8_to_string(); } finally { ((SafeHandle)(object)val2).Dispose(); } } finally { ((SafeHandle)(object)val).Dispose(); } } private void ExecuteNonQuery(string sql, int timeout) { RetryWhileBusy(() => raw.sqlite3_exec(_db, sql), timeout); } private string ExecuteScalar(string sql, string p1, int timeout) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) Stopwatch timer = Stopwatch.StartNew(); sqlite3_stmt stmt = null; RetryWhileBusy(() => raw.sqlite3_prepare_v2(_db, sql, ref stmt), timeout, timer); try { raw.sqlite3_bind_text(stmt, 1, p1); RetryWhileBusy(() => raw.sqlite3_step(stmt), delegate { raw.sqlite3_reset(stmt); }, timeout, timer); utf8z val = raw.sqlite3_column_text(stmt, 0); return ((utf8z)(ref val)).utf8_to_string(); } finally { ((SafeHandle)(object)stmt).Dispose(); } } private void RetryWhileBusy(Func action, int timeout, Stopwatch timer = null) { RetryWhileBusy(action, delegate { }, timeout, timer); } private void RetryWhileBusy(Func action, Action reset, int timeout, Stopwatch timer = null) { if (timer == null) { timer = Stopwatch.StartNew(); } int rc; while (IsBusy(rc = action()) && (timeout == 0 || timer.ElapsedMilliseconds < (long)timeout * 1000L)) { reset(); Thread.Sleep(150); } SqliteException.ThrowExceptionForRC(rc, _db); } private static bool IsBusy(int rc) { if ((uint)(rc - 5) <= 1u || rc == 262) { return true; } return false; } } internal class SqliteConnectionPool { private enum State { Active, Disabled } private static readonly Random _random = new Random(); private readonly SqliteConnectionStringBuilder _connectionOptions; private readonly List _connections = new List(); private readonly Stack _warmPool = new Stack(); private readonly Stack _coldPool = new Stack(); private Timer _pruneTimer; private State _state; public int Count => _connections.Count; public SqliteConnectionPool(SqliteConnectionStringBuilder connectionOptions) { lock (_random) { TimeSpan timeSpan = TimeSpan.FromSeconds(_random.Next(12, 24) * 10); _pruneTimer = new Timer(PruneCallback, null, timeSpan, timeSpan); } _connectionOptions = connectionOptions; } public void Shutdown() { _state = State.Disabled; _pruneTimer?.Dispose(); _pruneTimer = null; } public SqliteConnectionInternal GetConnection() { SqliteConnectionInternal connection = null; do { lock (_connections) { if (!TryPop(_warmPool, out connection) && !TryPop(_coldPool, out connection) && (Count % 2 == 1 || !ReclaimLeakedConnections())) { connection = new SqliteConnectionInternal(_connectionOptions, this); _connections.Add(connection); } } } while (connection == null); return connection; } private static bool TryPop(Stack stack, out SqliteConnectionInternal connection) { if (stack.Count > 0) { connection = stack.Pop(); return true; } connection = null; return false; } public void Return(SqliteConnectionInternal connection) { lock (_connections) { connection.Deactivate(); if (_state != State.Disabled && connection.CanBePooled) { _warmPool.Push(connection); } else { DisposeConnection(connection); } } } public void Clear() { lock (_connections) { foreach (SqliteConnectionInternal connection3 in _connections) { connection3.DoNotPool(); } SqliteConnectionInternal connection; while (TryPop(_warmPool, out connection)) { DisposeConnection(connection); } SqliteConnectionInternal connection2; while (TryPop(_coldPool, out connection2)) { DisposeConnection(connection2); } ReclaimLeakedConnections(); } } private void PruneCallback(object _) { lock (_connections) { SqliteConnectionInternal connection; while (TryPop(_coldPool, out connection)) { DisposeConnection(connection); } SqliteConnectionInternal connection2; while (TryPop(_warmPool, out connection2)) { _coldPool.Push(connection2); } } } private void DisposeConnection(SqliteConnectionInternal connection) { lock (_connections) { _connections.Remove(connection); } connection.Dispose(); } private bool ReclaimLeakedConnections() { bool result = false; List list; lock (_connections) { list = _connections.Where((SqliteConnectionInternal c) => c.Leaked).ToList(); } foreach (SqliteConnectionInternal item in list) { result = true; Return(item); } return result; } } internal class SqliteConnectionPoolGroup { private enum State { Active, Idle, Disabled } private SqliteConnectionPool _pool; private State _state; public SqliteConnectionStringBuilder ConnectionOptions { get; } public string ConnectionString { get; } public bool IsNonPooled { get; } public bool IsDisabled => _state == State.Disabled; public SqliteConnectionPoolGroup(SqliteConnectionStringBuilder connectionOptions, string connectionString, bool isNonPooled) { ConnectionOptions = connectionOptions; ConnectionString = connectionString; IsNonPooled = isNonPooled; base..ctor(); } public SqliteConnectionPool? GetPool() { if (IsNonPooled) { lock (this) { KeepAlive(); } return null; } if (_pool == null) { lock (this) { if (_pool == null && KeepAlive()) { _pool = new SqliteConnectionPool(ConnectionOptions); } } } return _pool; } public bool Clear() { lock (this) { if (_pool != null) { SqliteConnectionFactory.Instance.ReleasePool(_pool, clearing: true); _pool = null; } } return _pool != null; } public bool Prune() { lock (this) { SqliteConnectionPool pool = _pool; if (pool != null && pool.Count == 0) { SqliteConnectionFactory.Instance.ReleasePool(_pool, clearing: false); _pool = null; } if (_pool == null) { if (_state == State.Active) { _state = State.Idle; } else if (_state == State.Idle) { _state = State.Disabled; } } return _state == State.Disabled; } } private bool KeepAlive() { if (_state == State.Idle) { _state = State.Active; } return _state == State.Active; } } public class SqliteConnectionStringBuilder : DbConnectionStringBuilder { private enum Keywords { DataSource, Mode, Cache, Password, ForeignKeys, RecursiveTriggers, DefaultTimeout, Pooling, Vfs } private const string DataSourceKeyword = "Data Source"; private const string DataSourceNoSpaceKeyword = "DataSource"; private const string ModeKeyword = "Mode"; private const string CacheKeyword = "Cache"; private const string FilenameKeyword = "Filename"; private const string PasswordKeyword = "Password"; private const string ForeignKeysKeyword = "Foreign Keys"; private const string RecursiveTriggersKeyword = "Recursive Triggers"; private const string DefaultTimeoutKeyword = "Default Timeout"; private const string CommandTimeoutKeyword = "Command Timeout"; private const string PoolingKeyword = "Pooling"; private const string VfsKeyword = "Vfs"; private static readonly IReadOnlyList _validKeywords; private static readonly IReadOnlyDictionary _keywords; private string _dataSource = string.Empty; private SqliteOpenMode _mode; private SqliteCacheMode _cache; private string _password = string.Empty; private bool? _foreignKeys; private bool _recursiveTriggers; private int _defaultTimeout = 30; private bool _pooling = true; private string _vfs; public virtual string DataSource { get { return _dataSource; } [param: AllowNull] set { string obj = value ?? string.Empty; string value2 = obj; _dataSource = obj; base["Data Source"] = value2; } } public virtual SqliteOpenMode Mode { get { return _mode; } set { base["Mode"] = (_mode = value); } } public override ICollection Keys => new ReadOnlyCollection((string[])_validKeywords); public override ICollection Values { get { object[] array = new object[_validKeywords.Count]; for (int i = 0; i < _validKeywords.Count; i++) { array[i] = GetAt((Keywords)i); } return new ReadOnlyCollection(array); } } public virtual SqliteCacheMode Cache { get { return _cache; } set { base["Cache"] = (_cache = value); } } public string Password { get { return _password; } [param: AllowNull] set { string obj = value ?? string.Empty; string value2 = obj; _password = obj; base["Password"] = value2; } } public bool? ForeignKeys { get { return _foreignKeys; } set { base["Foreign Keys"] = (_foreignKeys = value); } } public bool RecursiveTriggers { get { return _recursiveTriggers; } set { base["Recursive Triggers"] = (_recursiveTriggers = value); } } public int DefaultTimeout { get { return _defaultTimeout; } set { base["Default Timeout"] = (_defaultTimeout = value); } } public bool Pooling { get { return _pooling; } set { base["Pooling"] = (_pooling = value); } } public string? Vfs { get { return _vfs; } set { base["Vfs"] = (_vfs = value); } } public override object? this[string keyword] { get { return GetAt(GetIndex(keyword)); } set { if (value == null) { Remove(keyword); return; } switch (GetIndex(keyword)) { case Keywords.DataSource: DataSource = Convert.ToString(value, CultureInfo.InvariantCulture); break; case Keywords.Mode: Mode = ConvertToEnum(value); break; case Keywords.Cache: Cache = ConvertToEnum(value); break; case Keywords.Password: Password = Convert.ToString(value, CultureInfo.InvariantCulture); break; case Keywords.ForeignKeys: ForeignKeys = ConvertToNullableBoolean(value); break; case Keywords.RecursiveTriggers: RecursiveTriggers = Convert.ToBoolean(value, CultureInfo.InvariantCulture); break; case Keywords.DefaultTimeout: DefaultTimeout = Convert.ToInt32(value); break; case Keywords.Pooling: Pooling = Convert.ToBoolean(value, CultureInfo.InvariantCulture); break; case Keywords.Vfs: Vfs = Convert.ToString(value, CultureInfo.InvariantCulture); break; } } } static SqliteConnectionStringBuilder() { _validKeywords = new string[9] { "Data Source", "Mode", "Cache", "Password", "Foreign Keys", "Recursive Triggers", "Default Timeout", "Pooling", "Vfs" }; _keywords = new Dictionary(12, StringComparer.OrdinalIgnoreCase) { ["Data Source"] = Keywords.DataSource, ["Mode"] = Keywords.Mode, ["Cache"] = Keywords.Cache, ["Password"] = Keywords.Password, ["Foreign Keys"] = Keywords.ForeignKeys, ["Recursive Triggers"] = Keywords.RecursiveTriggers, ["Default Timeout"] = Keywords.DefaultTimeout, ["Pooling"] = Keywords.Pooling, ["Vfs"] = Keywords.Vfs, ["Filename"] = Keywords.DataSource, ["DataSource"] = Keywords.DataSource, ["Command Timeout"] = Keywords.DefaultTimeout }; } public SqliteConnectionStringBuilder() { } public SqliteConnectionStringBuilder(string? connectionString) { base.ConnectionString = connectionString; } private static TEnum ConvertToEnum(object value) where TEnum : struct { if (value is string value2) { return (TEnum)Enum.Parse(typeof(TEnum), value2, ignoreCase: true); } TEnum val; if (value is TEnum) { val = (TEnum)value; } else { if (value.GetType().IsEnum) { throw new ArgumentException(Resources.ConvertFailed(value.GetType(), typeof(TEnum))); } val = (TEnum)Enum.ToObject(typeof(TEnum), value); } if (!Enum.IsDefined(typeof(TEnum), val)) { throw new ArgumentOutOfRangeException("value", value, Resources.InvalidEnumValue(typeof(TEnum), val)); } return val; } private static bool? ConvertToNullableBoolean(object value) { if ((value != null && (!(value is string text) || text.Length != 0)) || 1 == 0) { return Convert.ToBoolean(value, CultureInfo.InvariantCulture); } return null; } public override void Clear() { base.Clear(); for (int i = 0; i < _validKeywords.Count; i++) { Reset((Keywords)i); } } public override bool ContainsKey(string keyword) { return _keywords.ContainsKey(keyword); } public override bool Remove(string keyword) { if (!_keywords.TryGetValue(keyword, out var value) || !base.Remove(_validKeywords[(int)value])) { return false; } Reset(value); return true; } public override bool ShouldSerialize(string keyword) { if (_keywords.TryGetValue(keyword, out var value)) { return base.ShouldSerialize(_validKeywords[(int)value]); } return false; } public override bool TryGetValue(string keyword, out object? value) { if (!_keywords.TryGetValue(keyword, out var value2)) { value = null; return false; } value = GetAt(value2); return true; } private object GetAt(Keywords index) { return index switch { Keywords.DataSource => DataSource, Keywords.Mode => Mode, Keywords.Cache => Cache, Keywords.Password => Password, Keywords.ForeignKeys => ForeignKeys, Keywords.RecursiveTriggers => RecursiveTriggers, Keywords.DefaultTimeout => DefaultTimeout, Keywords.Pooling => Pooling, Keywords.Vfs => Vfs, _ => null, }; } private static Keywords GetIndex(string keyword) { if (_keywords.TryGetValue(keyword, out var value)) { return value; } throw new ArgumentException(Resources.KeywordNotSupported(keyword)); } private void Reset(Keywords index) { switch (index) { case Keywords.DataSource: _dataSource = string.Empty; break; case Keywords.Mode: _mode = SqliteOpenMode.ReadWriteCreate; break; case Keywords.Cache: _cache = SqliteCacheMode.Default; break; case Keywords.Password: _password = string.Empty; break; case Keywords.ForeignKeys: _foreignKeys = null; break; case Keywords.RecursiveTriggers: _recursiveTriggers = false; break; case Keywords.DefaultTimeout: _defaultTimeout = 30; break; case Keywords.Pooling: _pooling = true; break; case Keywords.Vfs: _vfs = null; break; } } } public class SqliteDataReader : DbDataReader { private readonly SqliteCommand _command; private readonly bool _closeConnection; private TimeSpan _totalElapsedTime; private IEnumerator _stmtEnumerator; private SqliteDataRecord _record; private bool _closed; private int _recordsAffected = -1; public override int Depth => 0; public override int FieldCount { get { if (!_closed) { return _record?.FieldCount ?? 0; } throw new InvalidOperationException(Resources.DataReaderClosed("FieldCount")); } } public virtual sqlite3_stmt? Handle => _record?.Handle; public override bool HasRows => _record?.HasRows ?? false; public override bool IsClosed => _closed; public override int RecordsAffected => _recordsAffected; public override object this[string name] { get { if (_record != null) { return _record[name]; } throw new InvalidOperationException(Resources.NoData); } } public override object this[int ordinal] { get { if (_record != null) { return _record[ordinal]; } throw new InvalidOperationException(Resources.NoData); } } internal SqliteDataReader(SqliteCommand command, IEnumerable stmts, bool closeConnection) { _command = command; _stmtEnumerator = stmts.GetEnumerator(); _closeConnection = closeConnection; } public override IEnumerator GetEnumerator() { return new DbEnumerator(this, closeReader: false); } public override bool Read() { if (!_closed) { return _record?.Read() ?? false; } throw new InvalidOperationException(Resources.DataReaderClosed("Read")); } public override bool NextResult() { if (_closed) { throw new InvalidOperationException(Resources.DataReaderClosed("NextResult")); } if (_record != null) { _record.Dispose(); _record = null; } while (_stmtEnumerator.MoveNext()) { try { sqlite3_stmt current = _stmtEnumerator.Current; SharedStopwatch sharedStopwatch = SharedStopwatch.StartNew(); int num; while (IsBusy(num = raw.sqlite3_step(current)) && (_command.CommandTimeout == 0 || !((_totalElapsedTime + sharedStopwatch.Elapsed).TotalMilliseconds >= (double)((long)_command.CommandTimeout * 1000L)))) { raw.sqlite3_reset(current); Thread.Sleep(150); } _totalElapsedTime += sharedStopwatch.Elapsed; SqliteException.ThrowExceptionForRC(num, _command.Connection.Handle); if (raw.sqlite3_column_count(current) != 0) { _record = new SqliteDataRecord(current, num != 101, _command.Connection, AddChanges); return true; } while (num != 101) { num = raw.sqlite3_step(current); SqliteException.ThrowExceptionForRC(num, _command.Connection.Handle); } raw.sqlite3_reset(current); int changes = raw.sqlite3_changes(_command.Connection.Handle); AddChanges(changes); } catch { raw.sqlite3_reset(_stmtEnumerator.Current); _stmtEnumerator.Dispose(); _stmtEnumerator = null; Dispose(); throw; } } return false; } private static bool IsBusy(int rc) { if ((uint)(rc - 5) <= 1u || rc == 262) { return true; } return false; } private void AddChanges(int changes) { if (_recordsAffected == -1) { _recordsAffected = changes; } else { _recordsAffected += changes; } } public override void Close() { Dispose(disposing: true); } protected override void Dispose(bool disposing) { if (!disposing || _closed) { return; } _command.DataReader = null; _record?.Dispose(); _record = null; if (_stmtEnumerator != null) { try { while (NextResult()) { } } catch { } } _stmtEnumerator?.Dispose(); _closed = true; if (_closeConnection) { _command.Connection.Close(); } } public override string GetName(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetName(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetName")); } public override int GetOrdinal(string name) { if (!_closed) { if (_record != null) { return _record.GetOrdinal(name); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetOrdinal")); } public override string GetDataTypeName(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetDataTypeName(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetDataTypeName")); } public override Type GetFieldType(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetFieldType(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetFieldType")); } public override bool IsDBNull(int ordinal) { if (!_closed) { if (_record != null) { return _record.IsDBNull(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("IsDBNull")); } public override bool GetBoolean(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetBoolean(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetBoolean")); } public override byte GetByte(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetByte(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetByte")); } public override char GetChar(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetChar(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetChar")); } public override DateTime GetDateTime(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetDateTime(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetDateTime")); } public virtual DateTimeOffset GetDateTimeOffset(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetDateTimeOffset(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetDateTimeOffset")); } public virtual TimeSpan GetTimeSpan(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetTimeSpan(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetTimeSpan")); } public override decimal GetDecimal(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetDecimal(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetDecimal")); } public override double GetDouble(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetDouble(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetDouble")); } public override float GetFloat(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetFloat(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetFloat")); } public override Guid GetGuid(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetGuid(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetGuid")); } public override short GetInt16(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetInt16(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetInt16")); } public override int GetInt32(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetInt32(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetInt32")); } public override long GetInt64(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetInt64(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetInt64")); } public override string GetString(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetString(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetString")); } public override long GetBytes(int ordinal, long dataOffset, byte[]? buffer, int bufferOffset, int length) { if (!_closed) { if (_record != null) { return _record.GetBytes(ordinal, dataOffset, buffer, bufferOffset, length); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetBytes")); } public override long GetChars(int ordinal, long dataOffset, char[]? buffer, int bufferOffset, int length) { if (!_closed) { if (_record != null) { return _record.GetChars(ordinal, dataOffset, buffer, bufferOffset, length); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetChars")); } public override Stream GetStream(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetStream(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetStream")); } public override TextReader GetTextReader(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetTextReader(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetTextReader")); } public override T GetFieldValue(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetFieldValue(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetFieldValue")); } public override object GetValue(int ordinal) { if (!_closed) { if (_record != null) { return _record.GetValue(ordinal); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetValue")); } public override int GetValues(object?[] values) { if (!_closed) { if (_record != null) { return _record.GetValues(values); } throw new InvalidOperationException(Resources.NoData); } throw new InvalidOperationException(Resources.DataReaderClosed("GetValues")); } public override DataTable GetSchemaTable() { //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_0342: Unknown result type (might be due to invalid IL or missing references) if (_closed) { throw new InvalidOperationException(Resources.DataReaderClosed("GetSchemaTable")); } if (_record == null) { throw new InvalidOperationException(Resources.NoData); } DataTable dataTable = new DataTable("SchemaTable"); DataColumn column = new DataColumn(SchemaTableColumn.ColumnName, typeof(string)); DataColumn column2 = new DataColumn(SchemaTableColumn.ColumnOrdinal, typeof(int)); DataColumn column3 = new DataColumn(SchemaTableColumn.ColumnSize, typeof(int)); DataColumn column4 = new DataColumn(SchemaTableColumn.NumericPrecision, typeof(short)); DataColumn column5 = new DataColumn(SchemaTableColumn.NumericScale, typeof(short)); DataColumn column6 = CreateDataTypeColumn(); DataColumn column7 = new DataColumn("DataTypeName", typeof(string)); DataColumn column8 = new DataColumn(SchemaTableColumn.IsLong, typeof(bool)); DataColumn column9 = new DataColumn(SchemaTableColumn.AllowDBNull, typeof(bool)); DataColumn column10 = new DataColumn(SchemaTableColumn.IsUnique, typeof(bool)); DataColumn column11 = new DataColumn(SchemaTableColumn.IsKey, typeof(bool)); DataColumn column12 = new DataColumn(SchemaTableOptionalColumn.IsAutoIncrement, typeof(bool)); DataColumn column13 = new DataColumn(SchemaTableOptionalColumn.BaseCatalogName, typeof(string)); DataColumn column14 = new DataColumn(SchemaTableColumn.BaseSchemaName, typeof(string)); DataColumn column15 = new DataColumn(SchemaTableColumn.BaseTableName, typeof(string)); DataColumn column16 = new DataColumn(SchemaTableColumn.BaseColumnName, typeof(string)); DataColumn column17 = new DataColumn(SchemaTableOptionalColumn.BaseServerName, typeof(string)); DataColumn column18 = new DataColumn(SchemaTableColumn.IsAliased, typeof(bool)); DataColumn column19 = new DataColumn(SchemaTableColumn.IsExpression, typeof(bool)); DataColumnCollection columns = dataTable.Columns; columns.Add(column); columns.Add(column2); columns.Add(column3); columns.Add(column4); columns.Add(column5); columns.Add(column10); columns.Add(column11); columns.Add(column17); columns.Add(column13); columns.Add(column16); columns.Add(column14); columns.Add(column15); columns.Add(column6); columns.Add(column7); columns.Add(column9); columns.Add(column18); columns.Add(column19); columns.Add(column12); columns.Add(column8); string text9 = default(string); string text10 = default(string); int num2 = default(int); int num3 = default(int); int num4 = default(int); for (int i = 0; i < FieldCount; i++) { DataRow dataRow = dataTable.NewRow(); dataRow[column] = GetName(i); dataRow[column2] = i; dataRow[column3] = -1; dataRow[column4] = DBNull.Value; dataRow[column5] = DBNull.Value; dataRow[column17] = _command.Connection.DataSource; utf8z val = raw.sqlite3_column_database_name(_record.Handle, i); string text2 = (string)(dataRow[column13] = ((utf8z)(ref val)).utf8_to_string()); val = raw.sqlite3_column_origin_name(_record.Handle, i); string text4 = (string)(dataRow[column16] = ((utf8z)(ref val)).utf8_to_string()); dataRow[column14] = DBNull.Value; val = raw.sqlite3_column_table_name(_record.Handle, i); string text6 = (string)(dataRow[column15] = ((utf8z)(ref val)).utf8_to_string()); dataRow[column6] = GetFieldType(i); string dataTypeName2 = (string)(dataRow[column7] = GetDataTypeName(i)); bool flag = text4 != GetName(i); dataRow[column18] = flag; dataRow[column19] = text4 == null; dataRow[column8] = DBNull.Value; bool flag2 = false; if (text6 != null && text4 != null) { using (SqliteCommand sqliteCommand = _command.Connection.CreateCommand()) { sqliteCommand.CommandText = new StringBuilder().AppendLine("SELECT COUNT(*)").AppendLine("FROM pragma_index_list($table) i, pragma_index_info(i.name) c").AppendLine("WHERE \"unique\" = 1 AND c.name = $column AND") .AppendLine("NOT EXISTS (SELECT * FROM pragma_index_info(i.name) c2 WHERE c2.name != c.name);") .ToString(); sqliteCommand.Parameters.AddWithValue("$table", text6); sqliteCommand.Parameters.AddWithValue("$column", text4); long num = (long)sqliteCommand.ExecuteScalar(); dataRow[column10] = !flag && num != 0; sqliteCommand.Parameters.Clear(); string text7 = "typeof(\"" + text4.Replace("\"", "\"\"") + "\")"; sqliteCommand.CommandText = new StringBuilder().AppendLine("SELECT " + text7).AppendLine("FROM \"" + text6.Replace("\"", "\"\"") + "\"").AppendLine("WHERE " + text7 + " != 'null'") .AppendLine("GROUP BY " + text7) .AppendLine("ORDER BY count() DESC") .AppendLine("LIMIT 1;") .ToString(); string text8 = (string)sqliteCommand.ExecuteScalar(); dataRow[column6] = ((text8 != null) ? SqliteDataRecord.GetFieldType(text8) : SqliteDataRecord.GetFieldTypeFromSqliteType(SqliteDataRecord.Sqlite3AffinityType(dataTypeName2))); sqliteCommand.CommandText = "SELECT COUNT(*) FROM sqlite_master WHERE name = $name AND type IN ('table', 'view')"; sqliteCommand.Parameters.AddWithValue("$name", text6); flag2 = (long)sqliteCommand.ExecuteScalar() == 0; } if (text2 != null && !flag2) { SqliteException.ThrowExceptionForRC(raw.sqlite3_table_column_metadata(_command.Connection.Handle, text2, text6, text4, ref text9, ref text10, ref num2, ref num3, ref num4), _command.Connection.Handle); dataRow[column11] = num3 != 0; dataRow[column9] = flag || num2 == 0; dataRow[column12] = num4 != 0; } } dataTable.Rows.Add(dataRow); } return dataTable; static DataColumn CreateDataTypeColumn() { return new DataColumn(SchemaTableColumn.DataType, typeof(Type)) { AllowDBNull = false }; } } } internal class SqliteDataRecord : SqliteValueReader, IDisposable { internal class RowIdInfo { public int Ordinal { get; set; } public string TableName { get; set; } public RowIdInfo(int ordinal, string tableName) { Ordinal = ordinal; TableName = tableName; base..ctor(); } } [CompilerGenerated] private SqliteConnection P; [CompilerGenerated] private Action P; private byte[][] _blobCache; private int?[] _typeCache; private Dictionary _columnNameOrdinalCache; private string[] _columnNameCache; private bool _stepped; private readonly Dictionary RowIds; private bool _alreadyThrown; private bool _alreadyAddedChanges; public virtual object this[string name] => GetValue(GetOrdinal(name)); public virtual object this[int ordinal] => GetValue(ordinal); public override int FieldCount => raw.sqlite3_column_count(Handle); public sqlite3_stmt Handle { get; } public bool HasRows { get; } public SqliteDataRecord(sqlite3_stmt stmt, bool hasRows, SqliteConnection connection, Action addChanges) { P = connection; P = addChanges; RowIds = new Dictionary(); Handle = stmt; HasRows = hasRows; base..ctor(); } public override bool IsDBNull(int ordinal) { if (_stepped && raw.sqlite3_data_count(Handle) != 0) { return base.IsDBNull(ordinal); } throw new InvalidOperationException(Resources.NoData); } public override object GetValue(int ordinal) { if (_stepped && raw.sqlite3_data_count(Handle) != 0) { return base.GetValue(ordinal); } throw new InvalidOperationException(Resources.NoData); } protected override double GetDoubleCore(int ordinal) { return raw.sqlite3_column_double(Handle, ordinal); } protected override long GetInt64Core(int ordinal) { return raw.sqlite3_column_int64(Handle, ordinal); } protected override string GetStringCore(int ordinal) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) utf8z val = raw.sqlite3_column_text(Handle, ordinal); return ((utf8z)(ref val)).utf8_to_string(); } public override T GetFieldValue(int ordinal) { if (typeof(T) == typeof(Stream)) { return (T)(object)GetStream(ordinal); } if (typeof(T) == typeof(TextReader)) { return (T)(object)GetTextReader(ordinal); } return base.GetFieldValue(ordinal); } protected override byte[] GetBlob(int ordinal) { return base.GetBlob(ordinal); } protected override byte[] GetBlobCore(int ordinal) { return raw.sqlite3_column_blob(Handle, ordinal).ToArray(); } protected override int GetSqliteType(int ordinal) { int num = raw.sqlite3_column_type(Handle, ordinal); if (num == 5 && (ordinal < 0 || ordinal >= FieldCount)) { throw new ArgumentOutOfRangeException("ordinal", ordinal, null); } return num; } protected override T GetNull(int ordinal) { if (!(typeof(T) == typeof(DBNull)) && !(typeof(T) == typeof(object))) { throw new InvalidOperationException(GetOnNullErrorMsg(ordinal)); } return (T)(object)DBNull.Value; } public virtual string GetName(int ordinal) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) string[] columnNameCache = _columnNameCache; object obj = ((columnNameCache != null) ? columnNameCache[ordinal] : null); if (obj == null) { utf8z val = raw.sqlite3_column_name(Handle, ordinal); obj = ((utf8z)(ref val)).utf8_to_string(); } string text = (string)obj; if (text == null && (ordinal < 0 || ordinal >= FieldCount)) { throw new ArgumentOutOfRangeException("ordinal", ordinal, null); } if (_columnNameCache == null) { _columnNameCache = new string[FieldCount]; } _columnNameCache[ordinal] = text; return text; } public virtual int GetOrdinal(string name) { if (_columnNameOrdinalCache == null) { _columnNameOrdinalCache = new Dictionary(); for (int i = 0; i < FieldCount; i++) { _columnNameOrdinalCache[GetName(i)] = i; } } if (_columnNameOrdinalCache.TryGetValue(name, out var value)) { return value; } KeyValuePair? keyValuePair = null; foreach (KeyValuePair item in _columnNameOrdinalCache) { if (string.Equals(name, item.Key, StringComparison.OrdinalIgnoreCase)) { if (keyValuePair.HasValue) { throw new InvalidOperationException(Resources.AmbiguousColumnName(name, keyValuePair.Value.Key, item.Key)); } keyValuePair = item; } } if (keyValuePair.HasValue) { _columnNameOrdinalCache.Add(name, keyValuePair.Value.Value); return keyValuePair.Value.Value; } throw new ArgumentOutOfRangeException("name", name, null); } public virtual string GetDataTypeName(int ordinal) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) utf8z val = raw.sqlite3_column_decltype(Handle, ordinal); string text = ((utf8z)(ref val)).utf8_to_string(); if (text != null) { int num = text.IndexOf('('); if (num != -1) { return text.Substring(0, num); } return text; } return GetSqliteType(ordinal) switch { 1 => "INTEGER", 2 => "REAL", 3 => "TEXT", _ => "BLOB", }; } public virtual Type GetFieldType(int ordinal) { int num = GetSqliteType(ordinal); if (num == 5) { int?[] typeCache = _typeCache; num = ((typeCache != null) ? typeCache[ordinal] : null) ?? Sqlite3AffinityType(GetDataTypeName(ordinal)); } else { if (_typeCache == null) { _typeCache = new int?[FieldCount]; } _typeCache[ordinal] = num; } return GetFieldTypeFromSqliteType(num); } internal static Type GetFieldTypeFromSqliteType(int sqliteType) { return sqliteType switch { 1 => typeof(long), 2 => typeof(double), 3 => typeof(string), _ => typeof(byte[]), }; } public static Type GetFieldType(string type) { return type switch { "integer" => typeof(long), "real" => typeof(double), "text" => typeof(string), _ => typeof(byte[]), }; } public virtual long GetBytes(int ordinal, long dataOffset, byte[]? buffer, int bufferOffset, int length) { using Stream stream = GetStream(ordinal); if (buffer == null) { return stream.Length; } stream.Position = dataOffset; return stream.Read(buffer, bufferOffset, length); } public virtual long GetChars(int ordinal, long dataOffset, char[]? buffer, int bufferOffset, int length) { using StreamReader streamReader = new StreamReader(GetStream(ordinal), Encoding.UTF8); if (buffer == null) { int num = 0; while (streamReader.Read() != -1) { num++; } return num; } for (int i = 0; i < dataOffset; i++) { if (streamReader.Read() == -1) { throw new ArgumentOutOfRangeException("dataOffset", dataOffset, null); } } return streamReader.Read(buffer, bufferOffset, length); } public virtual Stream GetStream(int ordinal) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) if (ordinal < 0 || ordinal >= FieldCount) { throw new ArgumentOutOfRangeException("ordinal", ordinal, null); } utf8z val = raw.sqlite3_column_database_name(Handle, ordinal); string text = ((utf8z)(ref val)).utf8_to_string(); val = raw.sqlite3_column_table_name(Handle, ordinal); string text2 = ((utf8z)(ref val)).utf8_to_string(); RowIdInfo value = null; string key = text + "_" + text2; if (!RowIds.TryGetValue(key, out value)) { long num = -1L; string a = default(string); string text6 = default(string); int num2 = default(int); int num3 = default(int); int num4 = default(int); for (int i = 0; i < FieldCount; i++) { if (i == ordinal) { continue; } val = raw.sqlite3_column_database_name(Handle, i); string text3 = ((utf8z)(ref val)).utf8_to_string(); if (text3 != text) { continue; } val = raw.sqlite3_column_table_name(Handle, i); string text4 = ((utf8z)(ref val)).utf8_to_string(); if (text4 != text2) { continue; } val = raw.sqlite3_column_origin_name(Handle, i); string text5 = ((utf8z)(ref val)).utf8_to_string(); if (text5 == "rowid") { value = new RowIdInfo(i, text4); RowIds.Add(key, value); break; } SqliteException.ThrowExceptionForRC(raw.sqlite3_table_column_metadata(P.Handle, text3, text4, text5, ref a, ref text6, ref num2, ref num3, ref num4), P.Handle); if (!string.Equals(a, "INTEGER", StringComparison.OrdinalIgnoreCase) || num3 == 0) { continue; } if (num < 0) { using SqliteCommand sqliteCommand = P.CreateCommand(); sqliteCommand.CommandText = "SELECT COUNT(*) FROM pragma_table_info($table) WHERE pk != 0;"; sqliteCommand.Parameters.AddWithValue("$table", text4); num = (long)sqliteCommand.ExecuteScalar(); } if (num == 1) { value = new RowIdInfo(i, text4); RowIds.Add(key, value); break; } } } if (value == null) { return new MemoryStream(GetCachedBlob(ordinal), writable: false); } val = raw.sqlite3_column_origin_name(Handle, ordinal); string columnName = ((utf8z)(ref val)).utf8_to_string(); long @int = GetInt64(value.Ordinal); return new SqliteBlob(P, text, text2, columnName, @int, readOnly: true); } public virtual TextReader GetTextReader(int ordinal) { if (!IsDBNull(ordinal)) { return new StreamReader(GetStream(ordinal), Encoding.UTF8); } return new StringReader(string.Empty); } public bool Read() { if (!_stepped) { _stepped = true; return HasRows; } if (raw.sqlite3_data_count(Handle) == 0) { return false; } int num; try { num = raw.sqlite3_step(Handle); SqliteException.ThrowExceptionForRC(num, P.Handle); } catch { _alreadyThrown = true; throw; } if (_blobCache != null) { Array.Clear(_blobCache, 0, _blobCache.Length); } if (num != 101) { return true; } AddChanges(); _alreadyAddedChanges = true; return false; } public void Dispose() { int rc = raw.sqlite3_reset(Handle); if (!_alreadyThrown) { SqliteException.ThrowExceptionForRC(rc, P.Handle); } if (!_alreadyAddedChanges) { AddChanges(); } } private void AddChanges() { if (raw.sqlite3_stmt_readonly(Handle) == 0) { int obj = raw.sqlite3_changes(P.Handle); P(obj); } } private byte[] GetCachedBlob(int ordinal) { if (ordinal < 0 || ordinal >= FieldCount) { throw new ArgumentOutOfRangeException("ordinal", ordinal, null); } byte[][] blobCache = _blobCache; byte[] array = ((blobCache != null) ? blobCache[ordinal] : null); if (array == null) { array = GetBlob(ordinal); if (_blobCache == null) { _blobCache = new byte[FieldCount][]; } _blobCache[ordinal] = array; } return array; } internal static int Sqlite3AffinityType(string dataTypeName) { string dataTypeName2 = dataTypeName; if (dataTypeName2 == null) { return 4; } return new Func[4] { (string name) => (!Contains(name, "INT")) ? null : new int?(1), (string name) => (!Contains(name, "CHAR") && !Contains(name, "CLOB") && !Contains(name, "TEXT")) ? null : new int?(3), (string name) => (!Contains(name, "BLOB")) ? null : new int?(4), (string name) => (!Contains(name, "REAL") && !Contains(name, "FLOA") && !Contains(name, "DOUB")) ? null : new int?(2) }.Select((Func r) => r(dataTypeName2)).FirstOrDefault((int? r) => r.HasValue).GetValueOrDefault(3); } private static bool Contains(string haystack, string needle) { return haystack.IndexOf(needle, StringComparison.OrdinalIgnoreCase) >= 0; } } public class SqliteException : DbException { public virtual int SqliteErrorCode { get; } public virtual int SqliteExtendedErrorCode { get; } public SqliteException(string? message, int errorCode) : this(message, errorCode, errorCode) { } public SqliteException(string? message, int errorCode, int extendedErrorCode) : base(message) { SqliteErrorCode = errorCode; SqliteExtendedErrorCode = extendedErrorCode; } public static void ThrowExceptionForRC(int rc, sqlite3? db) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) if ((rc == 0 || (uint)(rc - 100) <= 1u) ? true : false) { return; } utf8z val; string message; int extendedErrorCode; if (db == null || ((SafeHandle)(object)db).IsInvalid || rc != raw.sqlite3_errcode(db)) { val = raw.sqlite3_errstr(rc); message = ((utf8z)(ref val)).utf8_to_string() + " " + Resources.DefaultNativeError; extendedErrorCode = rc; } else { val = raw.sqlite3_errmsg(db); message = ((utf8z)(ref val)).utf8_to_string(); extendedErrorCode = raw.sqlite3_extended_errcode(db); } throw new SqliteException(Resources.SqliteNativeError(rc, message), rc, extendedErrorCode); } } public class SqliteFactory : DbProviderFactory { public static readonly SqliteFactory Instance = new SqliteFactory(); private SqliteFactory() { } public override DbCommand CreateCommand() { return new SqliteCommand(); } public override DbConnection CreateConnection() { return new SqliteConnection(); } public override DbConnectionStringBuilder CreateConnectionStringBuilder() { return new SqliteConnectionStringBuilder(); } public override DbParameter CreateParameter() { return new SqliteParameter(); } } public enum SqliteOpenMode { ReadWriteCreate, ReadWrite, ReadOnly, Memory } public class SqliteParameter : DbParameter { private string _parameterName = string.Empty; private object _value; private int? _size; private SqliteType? _sqliteType; private string _sourceColumn = string.Empty; private static readonly char[] _parameterPrefixes = new char[3] { '@', '$', ':' }; public override DbType DbType { get; set; } = DbType.String; public virtual SqliteType SqliteType { get { return _sqliteType ?? SqliteValueBinder.GetSqliteType(_value); } set { _sqliteType = value; } } public override ParameterDirection Direction { get { return ParameterDirection.Input; } set { if (value != ParameterDirection.Input) { throw new ArgumentException(Resources.InvalidParameterDirection(value)); } } } public override bool IsNullable { get; set; } public override string ParameterName { get { return _parameterName; } [param: AllowNull] set { _parameterName = value ?? string.Empty; } } public override int Size { get { int? size = _size; if (!size.HasValue) { if (!(_value is string text)) { if (!(_value is byte[] array)) { return 0; } return array.Length; } return text.Length; } return size.GetValueOrDefault(); } set { if (value < -1) { throw new ArgumentOutOfRangeException("value", value, null); } _size = value; } } public override string SourceColumn { get { return _sourceColumn; } [param: AllowNull] set { _sourceColumn = value ?? string.Empty; } } public override bool SourceColumnNullMapping { get; set; } public override object? Value { get { return _value; } set { _value = value; } } public SqliteParameter() { } public SqliteParameter(string? name, object? value) { ParameterName = name; Value = value; } public SqliteParameter(string? name, SqliteType type) { ParameterName = name; SqliteType = type; } public SqliteParameter(string? name, SqliteType type, int size) : this(name, type) { Size = size; } public SqliteParameter(string? name, SqliteType type, int size, string? sourceColumn) : this(name, type, size) { SourceColumn = sourceColumn; } public override void ResetDbType() { ResetSqliteType(); } public virtual void ResetSqliteType() { DbType = DbType.String; _sqliteType = null; } internal bool Bind(sqlite3_stmt stmt, sqlite3 handle) { if (string.IsNullOrEmpty(ParameterName)) { throw new InvalidOperationException(Resources.RequiresSet("ParameterName")); } int num = raw.sqlite3_bind_parameter_index(stmt, ParameterName); if (num == 0 && (num = FindPrefixedParameter(stmt)) == 0) { return false; } if (_value == null) { throw new InvalidOperationException(Resources.RequiresSet("Value")); } new SqliteParameterBinder(stmt, handle, num, _value, _size, _sqliteType).Bind(); return true; } private int FindPrefixedParameter(sqlite3_stmt stmt) { int num = 0; char[] parameterPrefixes = _parameterPrefixes; for (int i = 0; i < parameterPrefixes.Length; i++) { char c = parameterPrefixes[i]; if (ParameterName[0] == c) { return 0; } int num2 = raw.sqlite3_bind_parameter_index(stmt, c + ParameterName); if (num2 != 0) { if (num != 0) { throw new InvalidOperationException(Resources.AmbiguousParameterName(ParameterName)); } num = num2; } } return num; } } internal class SqliteParameterBinder : SqliteValueBinder { [CompilerGenerated] private sqlite3_stmt P; [CompilerGenerated] private sqlite3 P; [CompilerGenerated] private int P; [CompilerGenerated] private int? P; public SqliteParameterBinder(sqlite3_stmt stmt, sqlite3 handle, int index, object value, int? size, SqliteType? sqliteType) { P = stmt; P = handle; P = index; P = size; base..ctor(value, sqliteType); } protected override void BindBlob(byte[] value) { byte[] array = value; if (ShouldTruncate(value.Length)) { array = new byte[P.Value]; Array.Copy(value, array, P.Value); } SqliteException.ThrowExceptionForRC(raw.sqlite3_bind_blob(P, P, (ReadOnlySpan)array), P); } protected override void BindDoubleCore(double value) { SqliteException.ThrowExceptionForRC(raw.sqlite3_bind_double(P, P, value), P); } protected override void BindInt64(long value) { SqliteException.ThrowExceptionForRC(raw.sqlite3_bind_int64(P, P, value), P); } protected override void BindNull() { SqliteException.ThrowExceptionForRC(raw.sqlite3_bind_null(P, P), P); } protected override void BindText(string value) { SqliteException.ThrowExceptionForRC(raw.sqlite3_bind_text(P, P, ShouldTruncate(value.Length) ? value.Substring(0, P.Value) : value), P); } private bool ShouldTruncate(int length) { if (P.HasValue && length > P.Value) { return P.Value != -1; } return false; } } public class SqliteParameterCollection : DbParameterCollection { private readonly List _parameters = new List(); public override int Count => _parameters.Count; public override object SyncRoot => ((ICollection)_parameters).SyncRoot; public new virtual SqliteParameter this[int index] { get { return _parameters[index]; } set { if (_parameters[index] != value) { _parameters[index] = value; } } } public new virtual SqliteParameter this[string parameterName] { get { return this[IndexOfChecked(parameterName)]; } set { this[IndexOfChecked(parameterName)] = value; } } protected internal SqliteParameterCollection() { } public override int Add(object value) { _parameters.Add((SqliteParameter)value); return Count - 1; } public virtual SqliteParameter Add(SqliteParameter value) { _parameters.Add(value); return value; } public virtual SqliteParameter Add(string? parameterName, SqliteType type) { return Add(new SqliteParameter(parameterName, type)); } public virtual SqliteParameter Add(string? parameterName, SqliteType type, int size) { return Add(new SqliteParameter(parameterName, type, size)); } public virtual SqliteParameter Add(string? parameterName, SqliteType type, int size, string? sourceColumn) { return Add(new SqliteParameter(parameterName, type, size, sourceColumn)); } public override void AddRange(Array values) { AddRange(values.Cast()); } public virtual void AddRange(IEnumerable values) { _parameters.AddRange(values); } public virtual SqliteParameter AddWithValue(string? parameterName, object? value) { return Add(new SqliteParameter(parameterName, value)); } public override void Clear() { _parameters.Clear(); } public override bool Contains(object value) { return Contains((SqliteParameter)value); } public virtual bool Contains(SqliteParameter value) { return _parameters.Contains(value); } public override bool Contains(string value) { return IndexOf(value) != -1; } public override void CopyTo(Array array, int index) { CopyTo((SqliteParameter[])array, index); } public virtual void CopyTo(SqliteParameter[] array, int index) { _parameters.CopyTo(array, index); } public override IEnumerator GetEnumerator() { return _parameters.GetEnumerator(); } protected override DbParameter GetParameter(int index) { return this[index]; } protected override DbParameter GetParameter(string parameterName) { return GetParameter(IndexOfChecked(parameterName)); } public override int IndexOf(object value) { return IndexOf((SqliteParameter)value); } public virtual int IndexOf(SqliteParameter value) { return _parameters.IndexOf(value); } public override int IndexOf(string parameterName) { for (int i = 0; i < _parameters.Count; i++) { if (_parameters[i].ParameterName == parameterName) { return i; } } return -1; } public override void Insert(int index, object value) { Insert(index, (SqliteParameter)value); } public virtual void Insert(int index, SqliteParameter value) { _parameters.Insert(index, value); } public override void Remove(object value) { Remove((SqliteParameter)value); } public virtual void Remove(SqliteParameter value) { _parameters.Remove(value); } public override void RemoveAt(int index) { _parameters.RemoveAt(index); } public override void RemoveAt(string parameterName) { RemoveAt(IndexOfChecked(parameterName)); } protected override void SetParameter(int index, DbParameter value) { this[index] = (SqliteParameter)value; } protected override void SetParameter(string parameterName, DbParameter value) { SetParameter(IndexOfChecked(parameterName), value); } internal int Bind(sqlite3_stmt stmt, sqlite3 handle) { int num = 0; foreach (SqliteParameter parameter in _parameters) { if (parameter.Bind(stmt, handle)) { num++; } } return num; } private int IndexOfChecked(string parameterName) { int num = IndexOf(parameterName); if (num == -1) { throw new IndexOutOfRangeException(Resources.ParameterNotFound(parameterName)); } return num; } } internal class SqliteParameterReader : SqliteValueReader { [CompilerGenerated] private string P; [CompilerGenerated] private sqlite3_value[] P; public override int FieldCount => P.Length; public SqliteParameterReader(string function, sqlite3_value[] values) { P = function; P = values; base..ctor(); } protected override string GetOnNullErrorMsg(int ordinal) { return Resources.UDFCalledWithNull(P, ordinal); } protected override double GetDoubleCore(int ordinal) { return raw.sqlite3_value_double(P[ordinal]); } protected override long GetInt64Core(int ordinal) { return raw.sqlite3_value_int64(P[ordinal]); } protected override string GetStringCore(int ordinal) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) utf8z val = raw.sqlite3_value_text(P[ordinal]); return ((utf8z)(ref val)).utf8_to_string(); } protected override byte[] GetBlobCore(int ordinal) { return raw.sqlite3_value_blob(P[ordinal]).ToArray(); } protected override int GetSqliteType(int ordinal) { return raw.sqlite3_value_type(P[ordinal]); } } internal class SqliteResultBinder : SqliteValueBinder { [CompilerGenerated] private sqlite3_context P; public SqliteResultBinder(sqlite3_context ctx, object? value) { P = ctx; base..ctor(value); } protected override void BindBlob(byte[] value) { raw.sqlite3_result_blob(P, (ReadOnlySpan)value); } protected override void BindDoubleCore(double value) { raw.sqlite3_result_double(P, value); } protected override void BindInt64(long value) { raw.sqlite3_result_int64(P, value); } protected override void BindNull() { raw.sqlite3_result_null(P); } protected override void BindText(string value) { raw.sqlite3_result_text(P, value); } } public class SqliteTransaction : DbTransaction { private SqliteConnection _connection; private bool _completed; public new virtual SqliteConnection? Connection => _connection; protected override DbConnection? DbConnection => Connection; internal bool ExternalRollback { get; private set; } public override IsolationLevel IsolationLevel { get; } internal SqliteTransaction(SqliteConnection connection, IsolationLevel isolationLevel, bool deferred) { //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Expected O, but got Unknown if ((isolationLevel == IsolationLevel.ReadUncommitted && (connection.ConnectionOptions.Cache != SqliteCacheMode.Shared || !deferred)) || isolationLevel == IsolationLevel.ReadCommitted || isolationLevel == IsolationLevel.RepeatableRead || isolationLevel == IsolationLevel.Unspecified) { isolationLevel = IsolationLevel.Serializable; } _connection = connection; IsolationLevel = isolationLevel; switch (isolationLevel) { case IsolationLevel.ReadUncommitted: connection.ExecuteNonQuery("PRAGMA read_uncommitted = 1;"); break; default: throw new ArgumentException(Resources.InvalidIsolationLevel(isolationLevel)); case IsolationLevel.Serializable: break; } connection.ExecuteNonQuery((IsolationLevel == IsolationLevel.Serializable && !deferred) ? "BEGIN IMMEDIATE;" : "BEGIN;"); raw.sqlite3_rollback_hook(connection.Handle, new delegate_rollback(RollbackExternal), (object)null); } public override void Commit() { if (ExternalRollback || _completed || _connection.State != ConnectionState.Open) { throw new InvalidOperationException(Resources.TransactionCompleted); } _connection.ExecuteNonQuery("COMMIT;"); raw.sqlite3_rollback_hook(_connection.Handle, (delegate_rollback)null, (object)null); Complete(); } public override void Rollback() { if (_completed || _connection.State != ConnectionState.Open) { throw new InvalidOperationException(Resources.TransactionCompleted); } RollbackInternal(); } public new virtual void Save(string savepointName) { if (savepointName == null) { throw new ArgumentNullException("savepointName"); } if (_completed || _connection.State != ConnectionState.Open) { throw new InvalidOperationException(Resources.TransactionCompleted); } _connection.ExecuteNonQuery(new StringBuilder().Append("SAVEPOINT \"").Append(savepointName.Replace("\"", "\"\"")).Append("\";") .ToString()); } public new virtual void Rollback(string savepointName) { if (savepointName == null) { throw new ArgumentNullException("savepointName"); } if (_completed || _connection.State != ConnectionState.Open) { throw new InvalidOperationException(Resources.TransactionCompleted); } _connection.ExecuteNonQuery(new StringBuilder().Append("ROLLBACK TO SAVEPOINT \"").Append(savepointName.Replace("\"", "\"\"")).Append("\";") .ToString()); } public new virtual void Release(string savepointName) { if (savepointName == null) { throw new ArgumentNullException("savepointName"); } if (_completed || _connection.State != ConnectionState.Open) { throw new InvalidOperationException(Resources.TransactionCompleted); } _connection.ExecuteNonQuery(new StringBuilder().Append("RELEASE SAVEPOINT \"").Append(savepointName.Replace("\"", "\"\"")).Append("\";") .ToString()); } protected override void Dispose(bool disposing) { if (disposing && !_completed && _connection.State == ConnectionState.Open) { RollbackInternal(); } } private void Complete() { if (IsolationLevel == IsolationLevel.ReadUncommitted) { try { _connection.ExecuteNonQuery("PRAGMA read_uncommitted = 0;"); } catch { } } _connection.Transaction = null; _connection = null; _completed = true; } private void RollbackInternal() { try { if (!ExternalRollback) { raw.sqlite3_rollback_hook(_connection.Handle, (delegate_rollback)null, (object)null); _connection.ExecuteNonQuery("ROLLBACK;"); } } finally { Complete(); } } private void RollbackExternal(object userData) { raw.sqlite3_rollback_hook(_connection.Handle, (delegate_rollback)null, (object)null); ExternalRollback = true; } } public enum SqliteType { Integer = 1, Real, Text, Blob } internal abstract class SqliteValueBinder { [CompilerGenerated] private object P; [CompilerGenerated] private SqliteType? P; private static readonly bool Pre10TimeZoneHandling = AppContext.TryGetSwitch("Microsoft.Data.Sqlite.Pre10TimeZoneHandling", out var isEnabled) && isEnabled; private static readonly Dictionary _sqliteTypeMapping = new Dictionary { { typeof(bool), SqliteType.Integer }, { typeof(byte), SqliteType.Integer }, { typeof(byte[]), SqliteType.Blob }, { typeof(char), SqliteType.Text }, { typeof(DateTime), SqliteType.Text }, { typeof(DateTimeOffset), SqliteType.Text }, { typeof(DBNull), SqliteType.Text }, { typeof(decimal), SqliteType.Text }, { typeof(double), SqliteType.Real }, { typeof(float), SqliteType.Real }, { typeof(Guid), SqliteType.Text }, { typeof(int), SqliteType.Integer }, { typeof(long), SqliteType.Integer }, { typeof(sbyte), SqliteType.Integer }, { typeof(short), SqliteType.Integer }, { typeof(string), SqliteType.Text }, { typeof(TimeSpan), SqliteType.Text }, { typeof(uint), SqliteType.Integer }, { typeof(ulong), SqliteType.Integer }, { typeof(ushort), SqliteType.Integer } }; protected SqliteValueBinder(object? value, SqliteType? sqliteType) { P = value; P = sqliteType; base..ctor(); } protected SqliteValueBinder(object? value) : this(value, null) { } protected abstract void BindInt64(long value); protected virtual void BindDouble(double value) { if (double.IsNaN(value)) { throw new InvalidOperationException(Resources.CannotStoreNaN); } BindDoubleCore(value); } protected abstract void BindDoubleCore(double value); protected abstract void BindText(string value); protected abstract void BindBlob(byte[] value); protected abstract void BindNull(); public virtual void Bind() { if (P == null) { BindNull(); return; } Type type = P.GetType().UnwrapNullableType().UnwrapEnumType(); if (type == typeof(bool)) { long value = (((bool)P) ? 1 : 0); BindInt64(value); } else if (type == typeof(byte)) { long value2 = (byte)P; BindInt64(value2); } else if (type == typeof(byte[])) { byte[] value3 = (byte[])P; BindBlob(value3); } else if (type == typeof(char)) { char c = (char)P; if (P.GetValueOrDefault() != SqliteType.Integer) { string value4 = new string(c, 1); BindText(value4); } else { long value5 = c; BindInt64(value5); } } else if (type == typeof(DateTime)) { DateTime dateTime = (DateTime)P; if (P.GetValueOrDefault() == SqliteType.Real) { double value6 = ToJulianDate(dateTime); BindDouble(value6); } else { string value7 = dateTime.ToString("yyyy\\-MM\\-dd HH\\:mm\\:ss.FFFFFFF", CultureInfo.InvariantCulture); BindText(value7); } } else if (type == typeof(DateTimeOffset)) { DateTimeOffset dateTimeOffset = (DateTimeOffset)P; if (P.GetValueOrDefault() == SqliteType.Real) { double value8 = (Pre10TimeZoneHandling ? ToJulianDate(dateTimeOffset.DateTime) : ToJulianDate(dateTimeOffset.ToUniversalTime().DateTime)); BindDouble(value8); } else { string value9 = dateTimeOffset.ToString("yyyy\\-MM\\-dd HH\\:mm\\:ss.FFFFFFFzzz", CultureInfo.InvariantCulture); BindText(value9); } } else if (type == typeof(DBNull)) { BindNull(); } else if (type == typeof(decimal)) { string value10 = ((decimal)P).ToString("0.0###########################", CultureInfo.InvariantCulture); BindText(value10); } else if (type == typeof(double)) { double value11 = (double)P; BindDouble(value11); } else if (type == typeof(float)) { double value12 = (float)P; BindDouble(value12); } else if (type == typeof(Guid)) { Guid guid = (Guid)P; if (P.GetValueOrDefault() != SqliteType.Blob) { string value13 = guid.ToString().ToUpperInvariant(); BindText(value13); } else { byte[] value14 = guid.ToByteArray(); BindBlob(value14); } } else if (type == typeof(int)) { long value15 = (int)P; BindInt64(value15); } else if (type == typeof(long)) { long value16 = (long)P; BindInt64(value16); } else if (type == typeof(sbyte)) { long value17 = (sbyte)P; BindInt64(value17); } else if (type == typeof(short)) { long value18 = (short)P; BindInt64(value18); } else if (type == typeof(string)) { string value19 = (string)P; BindText(value19); } else if (type == typeof(TimeSpan)) { TimeSpan timeSpan = (TimeSpan)P; if (P.GetValueOrDefault() == SqliteType.Real) { double totalDays = timeSpan.TotalDays; BindDouble(totalDays); } else { string value20 = timeSpan.ToString("c"); BindText(value20); } } else if (type == typeof(uint)) { long value21 = (uint)P; BindInt64(value21); } else if (type == typeof(ulong)) { long value22 = (long)(ulong)P; BindInt64(value22); } else { if (!(type == typeof(ushort))) { throw new InvalidOperationException(Resources.UnknownDataType(type)); } long value23 = (ushort)P; BindInt64(value23); } } internal static SqliteType GetSqliteType(object? value) { if (value == null) { return SqliteType.Text; } Type type = value.GetType().UnwrapNullableType().UnwrapEnumType(); if (_sqliteTypeMapping.TryGetValue(type, out var value2)) { return value2; } throw new InvalidOperationException(Resources.UnknownDataType(type)); } private static double ToJulianDate(DateTime dateTime) { return ToJulianDate(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond); } private static double ToJulianDate(int year, int month, int day, int hour, int minute, int second, int millisecond) { int num = year; int num2 = month; if (num2 <= 2) { num--; num2 += 12; } int num3 = num / 100; int num4 = 2 - num3 + num3 / 4; int num5 = 36525 * (num + 4716) / 100; int num6 = 306001 * (num2 + 1) / 10000; return (double)((long)(((double)(num5 + num6 + day + num4) - 1524.5) * 86400000.0) + (hour * 3600000 + minute * 60000 + (long)(((double)second + (double)millisecond / 1000.0) * 1000.0))) / 86400000.0; } private static double GetTotalDays(int hour, int minute, int second, int millisecond) { return (double)(hour * 3600000 + minute * 60000 + (long)(((double)second + (double)millisecond / 1000.0) * 1000.0)) / 86400000.0; } } internal abstract class SqliteValueReader { private static readonly bool Pre10TimeZoneHandling = AppContext.TryGetSwitch("Microsoft.Data.Sqlite.Pre10TimeZoneHandling", out var isEnabled) && isEnabled; public abstract int FieldCount { get; } protected abstract int GetSqliteType(int ordinal); public virtual bool IsDBNull(int ordinal) { return GetSqliteType(ordinal) == 5; } public virtual bool GetBoolean(int ordinal) { return GetInt64(ordinal) != 0; } public virtual byte GetByte(int ordinal) { return checked((byte)GetInt64(ordinal)); } public virtual char GetChar(int ordinal) { if (GetSqliteType(ordinal) == 3) { string @string = GetString(ordinal); if (@string.Length == 1) { return @string[0]; } } return (char)checked((ushort)GetInt64(ordinal)); } public virtual DateTime GetDateTime(int ordinal) { int sqliteType = GetSqliteType(ordinal); if ((uint)(sqliteType - 1) <= 1u) { return FromJulianDate(GetDouble(ordinal)); } DateTime dateTime = DateTime.Parse(GetString(ordinal), CultureInfo.InvariantCulture); if (Pre10TimeZoneHandling) { return dateTime; } return (dateTime.Kind != DateTimeKind.Local) ? dateTime : dateTime.ToUniversalTime(); } public virtual DateTimeOffset GetDateTimeOffset(int ordinal) { int sqliteType = GetSqliteType(ordinal); if ((uint)(sqliteType - 1) <= 1u) { DateTime dateTime = FromJulianDate(GetDouble(ordinal)); if (!Pre10TimeZoneHandling) { return new DateTimeOffset(dateTime, TimeSpan.Zero); } return new DateTimeOffset(dateTime); } string @string = GetString(ordinal); if (!Pre10TimeZoneHandling) { return DateTimeOffset.Parse(@string, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } return DateTimeOffset.Parse(@string, CultureInfo.InvariantCulture); } public virtual decimal GetDecimal(int ordinal) { return decimal.Parse(GetString(ordinal), NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture); } public virtual double GetDouble(int ordinal) { if (!IsDBNull(ordinal)) { return GetDoubleCore(ordinal); } throw new InvalidOperationException(GetOnNullErrorMsg(ordinal)); } protected abstract double GetDoubleCore(int ordinal); public virtual float GetFloat(int ordinal) { return (float)GetDouble(ordinal); } public virtual Guid GetGuid(int ordinal) { if (GetSqliteType(ordinal) == 4) { byte[] blob = GetBlob(ordinal); if (blob.Length != 16) { return new Guid(Encoding.UTF8.GetString(blob, 0, blob.Length)); } return new Guid(blob); } return new Guid(GetString(ordinal)); } public virtual TimeSpan GetTimeSpan(int ordinal) { int sqliteType = GetSqliteType(ordinal); if ((uint)(sqliteType - 1) <= 1u) { return TimeSpan.FromDays(GetDouble(ordinal)); } return TimeSpan.Parse(GetString(ordinal)); } public virtual short GetInt16(int ordinal) { return checked((short)GetInt64(ordinal)); } public virtual int GetInt32(int ordinal) { return checked((int)GetInt64(ordinal)); } public virtual long GetInt64(int ordinal) { if (!IsDBNull(ordinal)) { return GetInt64Core(ordinal); } throw new InvalidOperationException(GetOnNullErrorMsg(ordinal)); } protected abstract long GetInt64Core(int ordinal); public virtual string GetString(int ordinal) { if (!IsDBNull(ordinal)) { return GetStringCore(ordinal); } throw new InvalidOperationException(GetOnNullErrorMsg(ordinal)); } protected abstract string GetStringCore(int ordinal); public virtual T? GetFieldValue(int ordinal) { if (typeof(T) == typeof(bool)) { return (T)(object)GetBoolean(ordinal); } if (typeof(T) == typeof(byte)) { return (T)(object)GetByte(ordinal); } if (typeof(T) == typeof(char)) { return (T)(object)GetChar(ordinal); } if (typeof(T) == typeof(DateTime)) { return (T)(object)GetDateTime(ordinal); } if (typeof(T) == typeof(DateTimeOffset)) { return (T)(object)GetDateTimeOffset(ordinal); } if (typeof(T) == typeof(decimal)) { return (T)(object)GetDecimal(ordinal); } if (typeof(T) == typeof(double)) { return (T)(object)GetDouble(ordinal); } if (typeof(T) == typeof(float)) { return (T)(object)GetFloat(ordinal); } if (typeof(T) == typeof(Guid)) { return (T)(object)GetGuid(ordinal); } if (typeof(T) == typeof(int)) { return (T)(object)GetInt32(ordinal); } if (typeof(T) == typeof(long)) { return (T)(object)GetInt64(ordinal); } checked { if (typeof(T) == typeof(sbyte)) { return (T)(object)(sbyte)GetInt64(ordinal); } if (typeof(T) == typeof(short)) { return (T)(object)GetInt16(ordinal); } if (typeof(T) == typeof(TimeSpan)) { return (T)(object)GetTimeSpan(ordinal); } if (typeof(T) == typeof(uint)) { return (T)(object)(uint)GetInt64(ordinal); } if (typeof(T) == typeof(ulong)) { return (T)(object)unchecked((ulong)GetInt64(ordinal)); } if (typeof(T) == typeof(ushort)) { return (T)(object)(ushort)GetInt64(ordinal); } if (IsDBNull(ordinal)) { if (default(T) != null) { throw new InvalidCastException(); } return GetNull(ordinal); } if (typeof(T) == typeof(string)) { return (T)(object)GetString(ordinal); } Type type = typeof(T).UnwrapNullableType().UnwrapEnumType(); if (type == typeof(bool)) { return (T)(object)GetBoolean(ordinal); } if (type == typeof(byte)) { return (T)(object)GetByte(ordinal); } if (type == typeof(byte[])) { return (T)(object)GetBlob(ordinal); } if (type == typeof(char)) { return (T)(object)GetChar(ordinal); } if (type == typeof(DateTime)) { return (T)(object)GetDateTime(ordinal); } if (type == typeof(DateTimeOffset)) { return (T)(object)GetDateTimeOffset(ordinal); } if (type == typeof(decimal)) { return (T)(object)GetDecimal(ordinal); } if (type == typeof(double)) { return (T)(object)GetDouble(ordinal); } if (type == typeof(float)) { return (T)(object)GetFloat(ordinal); } if (type == typeof(Guid)) { return (T)(object)GetGuid(ordinal); } if (type == typeof(int)) { return (T)(object)GetInt32(ordinal); } if (type == typeof(long)) { return (T)(object)GetInt64(ordinal); } if (type == typeof(sbyte)) { return (T)(object)(sbyte)GetInt64(ordinal); } if (type == typeof(short)) { return (T)(object)GetInt16(ordinal); } if (type == typeof(TimeSpan)) { return (T)(object)GetTimeSpan(ordinal); } if (type == typeof(uint)) { return (T)(object)(uint)GetInt64(ordinal); } if (type == typeof(ulong)) { return (T)(object)unchecked((ulong)GetInt64(ordinal)); } if (type == typeof(ushort)) { return (T)(object)(ushort)GetInt64(ordinal); } return (T)GetValue(ordinal); } } public virtual object? GetValue(int ordinal) { return GetSqliteType(ordinal) switch { 1 => GetInt64(ordinal), 2 => GetDouble(ordinal), 3 => GetString(ordinal), 5 => GetNull(ordinal), 4 => GetBlob(ordinal), _ => throw new ArgumentOutOfRangeException("Unexpected column type: " + GetSqliteType(ordinal)), }; } public virtual int GetValues(object?[] values) { int i; for (i = 0; i < FieldCount; i++) { values[i] = GetValue(i); } return i; } protected virtual byte[]? GetBlob(int ordinal) { byte[]? array; if (!IsDBNull(ordinal)) { array = GetBlobCore(ordinal); if (array == null) { return Array.Empty(); } } else { array = GetNull(ordinal); } return array; } protected abstract byte[] GetBlobCore(int ordinal); protected virtual T? GetNull(int ordinal) { if (!(typeof(T) == typeof(DBNull))) { return default(T); } return (T)(object)DBNull.Value; } protected virtual string GetOnNullErrorMsg(int ordinal) { return Resources.CalledOnNullValue(ordinal); } private static DateTime FromJulianDate(double julianDate) { long num = (long)(julianDate * 86400000.0 + 0.5); int num2 = (int)((num + 43200000) / 86400000); int num3 = (int)(((double)num2 - 1867216.25) / 36524.25); num3 = num2 + 1 + num3 - num3 / 4; int num4 = num3 + 1524; int num5 = (int)(((double)num4 - 122.1) / 365.25); int num6 = 36525 * (num5 & 0x7FFF) / 100; int num7 = (int)((double)(num4 - num6) / 30.6001); int num8 = (int)(30.6001 * (double)num7); int day = num4 - num6 - num8; int num9 = ((num7 < 14) ? (num7 - 1) : (num7 - 13)); int year = ((num9 > 2) ? (num5 - 4716) : (num5 - 4715)); int num10 = (int)((num + 43200000) % 86400000); double num11 = (double)num10 / 1000.0; num10 = (int)num11; double num12 = num11 - (double)num10; int num13 = num10 / 3600; num10 -= num13 * 3600; int num14 = num10 / 60; double num15 = num12 + (double)(num10 - num14 * 60); int num16 = (int)num15; int millisecond = (int)Math.Round((num15 - (double)num16) * 1000.0); return new DateTime(year, num9, day, num13, num14, num16, millisecond); } } } namespace Microsoft.Data.Sqlite.Utilities { internal readonly struct SharedStopwatch { private static readonly Stopwatch Stopwatch = Stopwatch.StartNew(); private readonly TimeSpan _started; public TimeSpan Elapsed => Stopwatch.Elapsed - _started; private SharedStopwatch(TimeSpan started) { _started = started; } public static SharedStopwatch StartNew() { StartNewCore(); return StartNewCore(); } private static SharedStopwatch StartNewCore() { return new SharedStopwatch(Stopwatch.Elapsed); } } } namespace Microsoft.Data.Sqlite.Properties { internal static class Resources { private static readonly ResourceManager _resourceManager = new ResourceManager("Microsoft.Data.Sqlite.Properties.Resources", typeof(Resources).Assembly); public static string CannotStoreNaN => GetString("CannotStoreNaN"); public static string ConnectionStringRequiresClosedConnection => GetString("ConnectionStringRequiresClosedConnection"); public static string DataReaderOpen => GetString("DataReaderOpen"); public static string DefaultNativeError => GetString("DefaultNativeError"); public static string InvalidOffsetAndCount => GetString("InvalidOffsetAndCount"); public static string NoData => GetString("NoData"); public static string ParallelTransactionsNotSupported => GetString("ParallelTransactionsNotSupported"); public static string ResizeNotSupported => GetString("ResizeNotSupported"); public static string SeekBeforeBegin => GetString("SeekBeforeBegin"); public static string SqlBlobRequiresOpenConnection => GetString("SqlBlobRequiresOpenConnection"); public static string TransactionCompleted => GetString("TransactionCompleted"); public static string TransactionConnectionMismatch => GetString("TransactionConnectionMismatch"); public static string TransactionRequired => GetString("TransactionRequired"); public static string WriteNotSupported => GetString("WriteNotSupported"); public static string AmbiguousColumnName(object? name, object? column1, object? column2) { return string.Format(GetString("AmbiguousColumnName", "name", "column1", "column2"), name, column1, column2); } public static string AmbiguousParameterName(object? parameterName) { return string.Format(GetString("AmbiguousParameterName", "parameterName"), parameterName); } public static string CalledOnNullValue(object? ordinal) { return string.Format(GetString("CalledOnNullValue", "ordinal"), ordinal); } public static string CallRequiresOpenConnection(object? methodName) { return string.Format(GetString("CallRequiresOpenConnection", "methodName"), methodName); } public static string ConvertFailed(object? sourceType, object? targetType) { return string.Format(GetString("ConvertFailed", "sourceType", "targetType"), sourceType, targetType); } public static string DataReaderClosed(object? operation) { return string.Format(GetString("DataReaderClosed", "operation"), operation); } public static string EncryptionNotSupported(object? libraryName) { return string.Format(GetString("EncryptionNotSupported", "libraryName"), libraryName); } public static string InvalidCommandType(object? commandType) { return string.Format(GetString("InvalidCommandType", "commandType"), commandType); } public static string InvalidEnumValue(object? enumType, object? value) { return string.Format(GetString("InvalidEnumValue", "enumType", "value"), enumType, value); } public static string InvalidIsolationLevel(object? isolationLevel) { return string.Format(GetString("InvalidIsolationLevel", "isolationLevel"), isolationLevel); } public static string InvalidParameterDirection(object? direction) { return string.Format(GetString("InvalidParameterDirection", "direction"), direction); } public static string KeywordNotSupported(object? keyword) { return string.Format(GetString("KeywordNotSupported", "keyword"), keyword); } public static string MissingParameters(object? parameters) { return string.Format(GetString("MissingParameters", "parameters"), parameters); } public static string ParameterNotFound(object? parameterName) { return string.Format(GetString("ParameterNotFound", "parameterName"), parameterName); } public static string RequiresSet(object? propertyName) { return string.Format(GetString("RequiresSet", "propertyName"), propertyName); } public static string SetRequiresNoOpenReader(object? propertyName) { return string.Format(GetString("SetRequiresNoOpenReader", "propertyName"), propertyName); } public static string SqliteNativeError(object? errorCode, object? message) { return string.Format(GetString("SqliteNativeError", "errorCode", "message"), errorCode, message); } public static string TooManyRestrictions(object? collectionName) { return string.Format(GetString("TooManyRestrictions", "collectionName"), collectionName); } public static string UDFCalledWithNull(object? function, object? ordinal) { return string.Format(GetString("UDFCalledWithNull", "function", "ordinal"), function, ordinal); } public static string UnknownCollection(object? collectionName) { return string.Format(GetString("UnknownCollection", "collectionName"), collectionName); } public static string UnknownDataType(object? typeName) { return string.Format(GetString("UnknownDataType", "typeName"), typeName); } private static string GetString(string name, params string[] formatterNames) { string text = _resourceManager.GetString(name); for (int i = 0; i < formatterNames.Length; i++) { text = text.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); } return text; } } }