public abstract void Execute(int timeout, IDescriptorFiller descriptorFiller);
 public abstract ValueTask ExecuteAsync(int timeout, IDescriptorFiller descriptorFiller, CancellationToken cancellationToken = default);
    protected override async ValueTask SendExecuteToBufferAsync(int timeout, IDescriptorFiller descriptorFiller, CancellationToken cancellationToken = default)
    {
        await base.SendExecuteToBufferAsync(timeout, descriptorFiller, cancellationToken).ConfigureAwait(false);

        await _database.Xdr.WriteAsync(timeout, cancellationToken).ConfigureAwait(false);
    }
Esempio n. 4
0
    public override async ValueTask ExecuteAsync(int timeout, IDescriptorFiller descriptorFiller, CancellationToken cancellationToken = default)
    {
        EnsureNotDeallocated();

        await descriptorFiller.FillAsync(_parameters, 0, cancellationToken).ConfigureAwait(false);

        ClearStatusVector();
        NativeHelpers.CallIfExists(() =>
        {
            _db.FbClient.fb_dsql_set_timeout(_statusVector, ref _handle, (uint)timeout);
            _db.ProcessStatusVector(_statusVector);
        });

        ClearStatusVector();

        var inSqlda  = IntPtr.Zero;
        var outSqlda = IntPtr.Zero;

        if (_parameters != null)
        {
            inSqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _parameters);
        }
        if (StatementType == DbStatementType.StoredProcedure)
        {
            Fields.ResetValues();
            outSqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _fields);
        }

        var trHandle = _transaction.HandlePtr;

        _db.FbClient.isc_dsql_execute2(
            _statusVector,
            ref trHandle,
            ref _handle,
            IscCodes.SQLDA_VERSION1,
            inSqlda,
            outSqlda);

        if (outSqlda != IntPtr.Zero)
        {
            var descriptor = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, outSqlda, true);

            var values = new DbValue[descriptor.Count];

            for (var i = 0; i < values.Length; i++)
            {
                var d     = descriptor[i];
                var value = await d.DbValue.GetValueAsync(cancellationToken).ConfigureAwait(false);

                values[i] = new DbValue(this, d, value);
            }

            OutputParameters.Enqueue(values);
        }

        XsqldaMarshaler.CleanUpNativeData(ref inSqlda);
        XsqldaMarshaler.CleanUpNativeData(ref outSqlda);

        _db.ProcessStatusVector(_statusVector);

        if (DoRecordsAffected)
        {
            RecordsAffected = await GetRecordsAffectedAsync(cancellationToken).ConfigureAwait(false);
        }
        else
        {
            RecordsAffected = -1;
        }

        State = StatementState.Executed;
    }
    public override void Execute(int timeout, IDescriptorFiller descriptorFiller)
    {
        EnsureNotDeallocated();

        Clear();

        try
        {
            RecordsAffected = -1;

            SendExecuteToBuffer(timeout, descriptorFiller);

            _database.Xdr.Flush();

            var numberOfResponses = (StatementType == DbStatementType.StoredProcedure ? 1 : 0) + 1;
            try
            {
                SqlResponse sqlStoredProcedureResponse = null;
                if (StatementType == DbStatementType.StoredProcedure)
                {
                    numberOfResponses--;
                    sqlStoredProcedureResponse = (SqlResponse)_database.ReadResponse();
                    ProcessStoredProcedureExecuteResponse(sqlStoredProcedureResponse);
                }

                numberOfResponses--;
                var executeResponse = (GenericResponse)_database.ReadResponse();
                ProcessExecuteResponse(executeResponse);
            }
            finally
            {
                (Database as GdsDatabase).SafeFinishFetching(numberOfResponses);
            }

            // we need to split this in two, to allow server handle op_cancel properly

            if (DoRecordsAffected)
            {
                SendInfoSqlToBuffer(RowsAffectedInfoItems, IscCodes.ROWS_AFFECTED_BUFFER_SIZE);

                _database.Xdr.Flush();

                numberOfResponses = 1;
                try
                {
                    numberOfResponses--;
                    var rowsAffectedResponse = (GenericResponse)_database.ReadResponse();
                    RecordsAffected = ProcessRecordsAffectedBuffer(ProcessInfoSqlResponse(rowsAffectedResponse));
                }
                finally
                {
                    (Database as GdsDatabase).SafeFinishFetching(numberOfResponses);
                }
            }

            State = StatementState.Executed;
        }
        catch (IOException ex)
        {
            State = StatementState.Error;
            throw IscException.ForIOException(ex);
        }
    }
 protected override void SendExecuteToBuffer(int timeout, IDescriptorFiller descriptorFiller)
 {
     base.SendExecuteToBuffer(timeout, descriptorFiller);
     _database.Xdr.Write(timeout);
 }
    public override async ValueTask ExecuteAsync(int timeout, IDescriptorFiller descriptorFiller, CancellationToken cancellationToken = default)
    {
        EnsureNotDeallocated();

        Clear();

        try
        {
            RecordsAffected = -1;

            await SendExecuteToBufferAsync(timeout, descriptorFiller, cancellationToken).ConfigureAwait(false);

            await _database.Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

            var numberOfResponses = (StatementType == DbStatementType.StoredProcedure ? 1 : 0) + 1;
            try
            {
                SqlResponse sqlStoredProcedureResponse = null;
                if (StatementType == DbStatementType.StoredProcedure)
                {
                    numberOfResponses--;
                    sqlStoredProcedureResponse = (SqlResponse)await _database.ReadResponseAsync(cancellationToken).ConfigureAwait(false);
                    await ProcessStoredProcedureExecuteResponseAsync(sqlStoredProcedureResponse, cancellationToken).ConfigureAwait(false);
                }

                numberOfResponses--;
                var executeResponse = (GenericResponse)await _database.ReadResponseAsync(cancellationToken).ConfigureAwait(false);
                await ProcessExecuteResponseAsync(executeResponse, cancellationToken).ConfigureAwait(false);
            }
            finally
            {
                await(Database as GdsDatabase).SafeFinishFetchingAsync(numberOfResponses, cancellationToken).ConfigureAwait(false);
            }

            // we need to split this in two, to allow server handle op_cancel properly

            if (DoRecordsAffected)
            {
                await SendInfoSqlToBufferAsync(RowsAffectedInfoItems, IscCodes.ROWS_AFFECTED_BUFFER_SIZE, cancellationToken).ConfigureAwait(false);

                await _database.Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                numberOfResponses = 1;
                try
                {
                    numberOfResponses--;
                    var rowsAffectedResponse = (GenericResponse)await _database.ReadResponseAsync(cancellationToken).ConfigureAwait(false);

                    RecordsAffected = ProcessRecordsAffectedBuffer(await ProcessInfoSqlResponseAsync(rowsAffectedResponse, cancellationToken).ConfigureAwait(false));
                }
                finally
                {
                    await(Database as GdsDatabase).SafeFinishFetchingAsync(numberOfResponses, cancellationToken).ConfigureAwait(false);
                }
            }

            State = StatementState.Executed;
        }
        catch (IOException ex)
        {
            State = StatementState.Error;
            throw IscException.ForIOException(ex);
        }
    }
Esempio n. 8
0
 public abstract ValueTask <ExecuteResultItem[]> ExecuteAsync(int count, IDescriptorFiller descriptorFiller, CancellationToken cancellationToken = default);
Esempio n. 9
0
 public abstract ExecuteResultItem[] Execute(int count, IDescriptorFiller descriptorFiller);
    public override ExecuteResultItem[] Execute(int count, IDescriptorFiller descriptorFiller)
    {
        var parametersData = new byte[count][];

        for (var i = 0; i < parametersData.Length; i++)
        {
            descriptorFiller.Fill(_statement.Parameters, i);
            // this may throw error, so it needs to be before any writing
            parametersData[i] = _statement.WriteParameters();
        }

        Database.Xdr.Write(IscCodes.op_batch_create);
        Database.Xdr.Write(_statement.Handle);         // p_batch_statement
        var blr = _statement.Parameters.ToBlr();

        Database.Xdr.WriteBuffer(blr.Data);     // p_batch_blr
        Database.Xdr.Write(blr.Length);         // p_batch_msglen
        var pb = new BatchParameterBuffer();

        if (_statement.ReturnRecordsAffected)
        {
            pb.Append(IscCodes.Batch.TAG_RECORD_COUNTS, 1);
        }
        if (MultiError)
        {
            pb.Append(IscCodes.Batch.TAG_MULTIERROR, 1);
        }
        Database.Xdr.WriteBuffer(pb.ToArray());         // p_batch_pb

        Database.Xdr.Write(IscCodes.op_batch_msg);
        Database.Xdr.Write(_statement.Handle);         // p_batch_statement
        Database.Xdr.Write(parametersData.Length);     // p_batch_messages
        foreach (var item in parametersData)
        {
            Database.Xdr.WriteOpaque(item, item.Length);             // p_batch_data
        }

        Database.Xdr.Write(IscCodes.op_batch_exec);
        Database.Xdr.Write(_statement.Handle);             // p_batch_statement
        Database.Xdr.Write(_statement.Transaction.Handle); // p_batch_transaction;

        Database.Xdr.Flush();

        var numberOfResponses = 3;

        try
        {
            numberOfResponses--;
            var batchCreateResponse = Database.ReadResponse();
            numberOfResponses--;
            var batchMsgResponse = Database.ReadResponse();
            numberOfResponses--;
            var batchExecResponse = (BatchCompletionStateResponse)Database.ReadResponse();

            return(BuildResult(batchExecResponse));
        }
        finally
        {
            Database.SafeFinishFetching(numberOfResponses);
        }
    }
    public override async ValueTask <ExecuteResultItem[]> ExecuteAsync(int count, IDescriptorFiller descriptorFiller, CancellationToken cancellationToken = default)
    {
        var parametersData = new byte[count][];

        for (var i = 0; i < parametersData.Length; i++)
        {
            await descriptorFiller.FillAsync(_statement.Parameters, i, cancellationToken).ConfigureAwait(false);

            // this may throw error, so it needs to be before any writing
            parametersData[i] = await _statement.WriteParametersAsync(cancellationToken).ConfigureAwait(false);
        }

        await Database.Xdr.WriteAsync(IscCodes.op_batch_create, cancellationToken).ConfigureAwait(false);

        await Database.Xdr.WriteAsync(_statement.Handle, cancellationToken).ConfigureAwait(false);         // p_batch_statement

        var blr = _statement.Parameters.ToBlr();
        await Database.Xdr.WriteBufferAsync(blr.Data, cancellationToken).ConfigureAwait(false);     // p_batch_blr

        await Database.Xdr.WriteAsync(blr.Length, cancellationToken).ConfigureAwait(false);         // p_batch_msglen

        var pb = new BatchParameterBuffer();

        if (_statement.ReturnRecordsAffected)
        {
            pb.Append(IscCodes.Batch.TAG_RECORD_COUNTS, 1);
        }
        if (MultiError)
        {
            pb.Append(IscCodes.Batch.TAG_MULTIERROR, 1);
        }
        await Database.Xdr.WriteBufferAsync(pb.ToArray(), cancellationToken).ConfigureAwait(false);         // p_batch_pb

        await Database.Xdr.WriteAsync(IscCodes.op_batch_msg, cancellationToken).ConfigureAwait(false);

        await Database.Xdr.WriteAsync(_statement.Handle, cancellationToken).ConfigureAwait(false);         // p_batch_statement

        await Database.Xdr.WriteAsync(parametersData.Length, cancellationToken).ConfigureAwait(false);     // p_batch_messages

        foreach (var item in parametersData)
        {
            await Database.Xdr.WriteOpaqueAsync(item, item.Length, cancellationToken).ConfigureAwait(false);             // p_batch_data
        }

        await Database.Xdr.WriteAsync(IscCodes.op_batch_exec, cancellationToken).ConfigureAwait(false);

        await Database.Xdr.WriteAsync(_statement.Handle, cancellationToken).ConfigureAwait(false);             // p_batch_statement

        await Database.Xdr.WriteAsync(_statement.Transaction.Handle, cancellationToken).ConfigureAwait(false); // p_batch_transaction;

        await Database.Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

        var numberOfResponses = 3;

        try
        {
            numberOfResponses--;
            var batchCreateResponse = await Database.ReadResponseAsync(cancellationToken).ConfigureAwait(false);

            numberOfResponses--;
            var batchMsgResponse = await Database.ReadResponseAsync(cancellationToken).ConfigureAwait(false);

            numberOfResponses--;
            var batchExecResponse = (BatchCompletionStateResponse)await Database.ReadResponseAsync(cancellationToken).ConfigureAwait(false);

            return(BuildResult(batchExecResponse));
        }
        finally
        {
            await Database.SafeFinishFetchingAsync(numberOfResponses, cancellationToken).ConfigureAwait(false);
        }
    }