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

            ClearStatusVector();

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

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

            TransactionHandle trHandle = _transaction.HandlePtr;

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

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

                DbValueBase[] values = new DbValueBase[descriptor.Count];

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

                _outputParams.Enqueue(values);
            }

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

            _db.ProcessStatusVector(_statusVector);

            UpdateRecordsAffected();

            _state = StatementState.Executed;
        }
예제 #2
0
        public override DbValueBase[] Fetch()
        {
            DbValueBase[] row = null;

            if (_state == StatementState.Deallocated)
            {
                throw new InvalidOperationException("Statement is not correctly created.");
            }
            if (_statementType != DbStatementType.Select &&
                _statementType != DbStatementType.SelectForUpdate)
            {
                return(null);
            }

            if (!_allRowsFetched)
            {
                _fields.ResetValues();

                if (_fetchSqlDa == IntPtr.Zero)
                {
                    _fetchSqlDa = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _fields);
                }

                ClearStatusVector();

                IntPtr status = _db.FbClient.isc_dsql_fetch(_statusVector, ref _handle, IscCodes.SQLDA_VERSION1, _fetchSqlDa);

                Descriptor rowDesc = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, _fetchSqlDa, true);

                if (_fields.Count == rowDesc.Count)
                {
                    for (int i = 0; i < _fields.Count; i++)
                    {
                        if (_fields[i].IsArray() && _fields[i].ArrayHandle != null)
                        {
                            rowDesc[i].ArrayHandle = _fields[i].ArrayHandle;
                        }
                    }
                }

                _fields = rowDesc;

                _db.ProcessStatusVector(_statusVector);

                if (status == new IntPtr(100))
                {
                    _allRowsFetched = true;

                    XsqldaMarshaler.CleanUpNativeData(ref _fetchSqlDa);
                }
                else
                {
                    row = new DbValueBase[_fields.ActualCount];
                    for (int i = 0; i < row.Length; i++)
                    {
                        row[i] = new DbValue(this, _fields[i]);
                    }
                }
            }

            return(row);
        }