Esempio n. 1
0
        /// <inheritdoc />
        public void ExecuteReader(CommandBehavior commandBehavior)
        {
            Packet response;

            if (null != _parentCommand.Guid)
            {
                var request = Fields.Fields.SerializeObject(new GuidAndIndexRequest
                {
                    Guid  = _parentCommand.Guid,
                    Index = (int)commandBehavior
                });
                response = _controller.SendAndWaitAsync(SQLiteMessage.ExecuteReaderRequest, request.Pack(), _queryTimeouts)
                           .Result;
            }
            else
            {
                var request = Fields.Fields.SerializeObject(new CommandTextAndIndexRequest
                {
                    CommandText = _parentCommand.CommandText,
                    Index       = (int)commandBehavior
                });
                response = _controller.SendAndWaitAsync(SQLiteMessage.ExecuteCommandReaderRequest, request.Pack(), _queryTimeouts)
                           .Result;
            }

            switch (response.Message)
            {
            case SQLiteMessage.SendAndWaitTimeOut:
                throw new TimeoutException("There was a timeout error creating the Command.");

            case SQLiteMessage.ExecuteReaderResponse:
                var fields = Fields.Fields.Unpack(response.Payload);
                _currentRowHeader   = Fields.Fields.DeserializeObject <RowHeader>(fields);
                _parentCommand.Guid = _currentRowHeader.Guid;
                return;

            case SQLiteMessage.ExecuteReaderException:
                var error = response.Get <string>();
                throw new SQLiteServerException(error);

            default:
                throw new InvalidOperationException($"Unknown response {response.Message} from the server.");
            }
        }
        /// <summary>
        /// Get the server guid
        /// </summary>
        /// <returns></returns>
        private async Task <string> CreateGuidAsync()
        {
            var response = await _controller.SendAndWaitAsync(SQLiteMessage.CreateCommandRequest, Encoding.ASCII.GetBytes(CommandText), CommandTimeout).ConfigureAwait(false);

            switch (response.Message)
            {
            case SQLiteMessage.SendAndWaitTimeOut:
                throw new TimeoutException("There was a timeout error creating the Command.");

            case SQLiteMessage.CreateCommandResponse:
                return(response.Get <string>());

            case SQLiteMessage.CreateCommandException:
                throw new SQLiteServerException(response.Get <string>());

            default:
                throw new InvalidOperationException($"Unknown response {response.Message} from the server.");
            }
        }
Esempio n. 3
0
        /// <inheritdoc />
        public async Task <SQLiteConnection> LockConnectionAsync()
        {
            // can we use this?
            ThrowIfAny();

            // wait for the connection
            if (!await WaitForLockedConnectionAsync(-1).ConfigureAwait(false))
            {
                throw new SQLiteServerException("Unable to obtain connection lock");
            }

            // can we use this?
            ThrowIfAny();

            // wait for the connection
            if (!await WaitForLockedConnectionAsync(-1).ConfigureAwait(false))
            {
                throw new SQLiteServerException("Unable to obtain connection lock");
            }

            var response = await _controller.SendAndWaitAsync(SQLiteMessage.LockConnectionRequest, null, CommandTimeout).ConfigureAwait(false);

            switch (response.Message)
            {
            case SQLiteMessage.SendAndWaitTimeOut:
                throw new TimeoutException("There was a timeout error obtaining the lock.");

            case SQLiteMessage.LockConnectionResponse:
                _connection = new SQLiteConnection(_connectionString);
                _connection.Open();
                return(_connection);

            case SQLiteMessage.LockConnectionException:
                throw new SQLiteServerException(response.Get <string>());

            default:
                throw new InvalidOperationException($"Unknown response {response.Message} from the server.");
            }
        }