/// <summary>
        ///     Closes all long lived resources, such as the Sqlite connection.
        /// </summary>
        public void Dispose()
        {
            _logger.Info($"Closing sqlite DB {FullPath}");

            PreviousQuery?.Dispose();

            _connection.Close();
            _connection.Dispose();
            _connection = null;

            _cache.Clear();
        }
        /// <summary>
        ///     Performs a Key Based Query on the loaded Btrieve File
        /// </summary>
        /// <param name="keyNumber">Which key to query against</param>
        /// <param name="key">The key data to query against</param>
        /// <param name="btrieveOperationCode">Which query to perform</param>
        /// <param name="newQuery">true to start a new query, false to continue a prior one</param>
        public bool PerformOperation(int keyNumber, ReadOnlySpan <byte> key, EnumBtrieveOperationCodes btrieveOperationCode)
        {
            switch (btrieveOperationCode)
            {
            case EnumBtrieveOperationCodes.StepFirst:
                return(StepFirst());

            case EnumBtrieveOperationCodes.StepLast:
                return(StepLast());

            case EnumBtrieveOperationCodes.StepNext:
            case EnumBtrieveOperationCodes.StepNextExtended:
                return(StepNext());

            case EnumBtrieveOperationCodes.StepPrevious:
            case EnumBtrieveOperationCodes.StepPreviousExtended:
                return(StepPrevious());
            }

            var          newQuery = !btrieveOperationCode.UsesPreviousQuery();
            BtrieveQuery currentQuery;

            if (newQuery || PreviousQuery == null)
            {
                currentQuery = new BtrieveQuery
                {
                    Key     = Keys[(ushort)keyNumber],
                    KeyData = key == null ? null : new byte[key.Length],
                };

                if (key != null)
                {
                    Array.Copy(key.ToArray(), 0, currentQuery.KeyData, 0, key.Length);
                }

                // Wipe any previous query we have and store this new query
                PreviousQuery?.Dispose();
                PreviousQuery = currentQuery;
            }
            else if (PreviousQuery == null)
            {
                return(false);
            }
            else
            {
                currentQuery = PreviousQuery;
            }

            return(btrieveOperationCode switch
            {
                EnumBtrieveOperationCodes.AcquireEqual => GetByKeyEqual(currentQuery),
                EnumBtrieveOperationCodes.QueryEqual => GetByKeyEqual(currentQuery),

                EnumBtrieveOperationCodes.AcquireFirst => GetByKeyFirst(currentQuery),
                EnumBtrieveOperationCodes.QueryFirst => GetByKeyFirst(currentQuery),

                EnumBtrieveOperationCodes.AcquireLast => GetByKeyLast(currentQuery),
                EnumBtrieveOperationCodes.QueryLast => GetByKeyLast(currentQuery),

                EnumBtrieveOperationCodes.AcquireGreater => GetByKeyGreater(currentQuery, ">"),
                EnumBtrieveOperationCodes.QueryGreater => GetByKeyGreater(currentQuery, ">"),
                EnumBtrieveOperationCodes.AcquireGreaterOrEqual => GetByKeyGreater(currentQuery, ">="),
                EnumBtrieveOperationCodes.QueryGreaterOrEqual => GetByKeyGreater(currentQuery, ">="),

                EnumBtrieveOperationCodes.AcquireLess => GetByKeyLess(currentQuery, "<"),
                EnumBtrieveOperationCodes.QueryLess => GetByKeyLess(currentQuery, "<"),
                EnumBtrieveOperationCodes.AcquireLessOrEqual => GetByKeyLess(currentQuery, "<="),
                EnumBtrieveOperationCodes.QueryLessOrEqual => GetByKeyLess(currentQuery, "<="),

                EnumBtrieveOperationCodes.AcquireNext => GetByKeyNext(currentQuery),
                EnumBtrieveOperationCodes.QueryNext => GetByKeyNext(currentQuery),

                EnumBtrieveOperationCodes.AcquirePrevious => GetByKeyPrevious(currentQuery),
                EnumBtrieveOperationCodes.QueryPrevious => GetByKeyPrevious(currentQuery),

                _ => throw new Exception($"Unsupported Operation Code: {btrieveOperationCode}")
            });