コード例 #1
0
    async Task Cancel(bool async, CancellationToken cancellationToken = default)
    {
        _state = ImporterState.Cancelled;
        _buf.Clear();
        _buf.EndCopyMode();
        await _connector.WriteCopyFail(async, cancellationToken);

        await _connector.Flush(async, cancellationToken);

        try
        {
            using var registration = _connector.StartNestedCancellableOperation(cancellationToken, attemptPgCancellation: false);
            var msg = await _connector.ReadMessage(async);

            // The CopyFail should immediately trigger an exception from the read above.
            throw _connector.Break(
                      new NpgsqlException("Expected ErrorResponse when cancelling COPY but got: " + msg.Code));
        }
        catch (PostgresException e)
        {
            if (e.SqlState != PostgresErrorCodes.QueryCanceled)
            {
                throw;
            }
        }
    }
コード例 #2
0
        internal static PregeneratedMessage Generate(NpgsqlWriteBuffer buf, QueryMessage queryMessage, string query, int responseMessageCount = 2)
        {
            Debug.Assert(query != null && query.All(c => c < 128));
            queryMessage.Populate(query);
            var description = queryMessage.ToString();

            queryMessage.Write(buf, false).Wait();
            var bytes = buf.GetContents();

            buf.Clear();
            return(new PregeneratedMessage(bytes, description, responseMessageCount));
        }
コード例 #3
0
    internal static byte[] Generate(NpgsqlWriteBuffer buf, string query)
    {
        Debug.Assert(query.All(c => c < 128));

        var queryByteLen = Encoding.ASCII.GetByteCount(query);

        buf.WriteByte(FrontendMessageCode.Query);
        buf.WriteInt32(4 +            // Message length (including self excluding code)
                       queryByteLen + // Query byte length
                       1);            // Null terminator

        buf.WriteString(query, queryByteLen, false).Wait();
        buf.WriteByte(0);

        var bytes = buf.GetContents();

        buf.Clear();
        return(bytes);
    }