Exemple #1
0
        public override void Execute()
        {
            if (this.state == StatementState.Deallocated)
            {
                throw new InvalidOperationException("Statment is not correctly created.");
            }

            lock (this.db)
            {
                // Marshal structures to pointer
                XsqldaMarshaler marshaler = XsqldaMarshaler.GetInstance();

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

                if (this.parameters != null)
                {
                    inSqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.parameters);
                }
                if (this.statementType == DbStatementType.StoredProcedure)
                {
                    this.Fields.ResetValues();
                    outSqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.fields);
                }

                int[] statusVector = FesConnection.GetNewStatusVector();
                int   trHandle     = this.transaction.Handle;
                int   stmtHandle   = this.handle;

                FbClient.isc_dsql_execute2(
                    statusVector,
                    ref trHandle,
                    ref stmtHandle,
                    IscCodes.SQLDA_VERSION1,
                    inSqlda,
                    outSqlda);

                if (outSqlda != IntPtr.Zero)
                {
                    Descriptor descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, outSqlda);

                    // This	would be an	Execute	procedure
                    DbValue[] values = new DbValue[descriptor.Count];

                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = new DbValue(this, descriptor[i]);
                    }

                    this.outputParams.Enqueue(values);
                }

                // Free	memory
                marshaler.CleanUpNativeData(ref inSqlda);
                marshaler.CleanUpNativeData(ref outSqlda);

                this.db.ParseStatusVector(statusVector);

                this.UpdateRecordsAffected();

                this.state = StatementState.Executed;
            }
        }