コード例 #1
0
        internal NativeBuffer GetScratchBuffer(int minSize)
        {
            NativeBuffer buffer = this._scratchBuffer;

            if ((buffer == null) || (buffer.Length < minSize))
            {
                if (buffer != null)
                {
                    buffer.Dispose();
                }
                buffer = new NativeBuffer_ScratchBuffer(minSize);
                this._scratchBuffer = buffer;
            }
            return(buffer);
        }
コード例 #2
0
        private void Cleanup()
        {
            // release everything; we can't do anything from here on out.

            if (null != _buffer)
            {
                _buffer.Dispose();
                _buffer = null;
            }

            if (null != _schemaTable)
            {
                _schemaTable.Dispose();
                _schemaTable = null;
            }

            _fieldNameLookup = null;

            if (null != _columnInfo)
            {
                // Only cleanup the column info when it's not the data reader
                // that owns all the ref cursor data readers;
                if (null == _refCursorDataReaders)
                {
                    int i = _columnInfo.Length;

                    while (--i >= 0)
                    {
                        if (null != _columnInfo[i])
                        {
                            _columnInfo[i].Dispose();
                            _columnInfo[i] = null;
                        }
                    }
                }
                _columnInfo = null;
            }
        }
コード例 #3
0
        internal void Bind(
            OciHandle statementHandle,
            NativeBuffer buffer,
            OciHandle errorHandle,
            int rowBufferLength
            )
        {
            //  Binds the buffer for the column to the statement handle specified.

            OciHandle defineHandle = null;
            IntPtr    h;

            OCI.MODE mode = OCI.MODE.OCI_DEFAULT;
            int      bindSize;

            OCI.DATATYPE ociType = _metaType.OciType;

            _rowBuffer = buffer;

            if (_metaType.IsLong)
            {
                mode     = OCI.MODE.OCI_DYNAMIC_FETCH;
                bindSize = Int32.MaxValue;
            }
            else
            {
                bindSize = _size;
            }

            HandleRef indicatorLocation = ADP.NullHandleRef;
            HandleRef lengthLocation    = ADP.NullHandleRef;
            HandleRef valueLocation     = _rowBuffer.PtrOffset(_valueOffset);

            if (-1 != _indicatorOffset)
            {
                indicatorLocation = _rowBuffer.PtrOffset(_indicatorOffset);
            }

            if (-1 != _lengthOffset && !_metaType.IsLong)
            {
                lengthLocation = _rowBuffer.PtrOffset(_lengthOffset);
            }

            try
            {
                try
                {
                    int rc = TracedNativeMethods.OCIDefineByPos(
                        statementHandle,                                    // hndlp
                        out h,                                              // defnpp
                        errorHandle,                                        // errhp
                        _ordinal + 1,                                       // position
                        valueLocation,                                      // valuep
                        bindSize,                                           // value_sz
                        ociType,                                            // htype
                        indicatorLocation,                                  // indp,
                        lengthLocation,                                     // rlenp,
                        ADP.NullHandleRef,                                  // rcodep,
                        mode                                                // mode
                        );
                    if (rc != 0)
                    {
                        _connection.CheckError(errorHandle, rc);
                    }

                    defineHandle = new OciDefineHandle(statementHandle, h);

                    if (0 != rowBufferLength)
                    {
                        int valOffset = rowBufferLength;
                        int indOffset = (-1 != _indicatorOffset) ? rowBufferLength : 0;
                        int lenOffset = (-1 != _lengthOffset && !_metaType.IsLong) ? rowBufferLength : 0;

                        rc = TracedNativeMethods.OCIDefineArrayOfStruct(
                            defineHandle,
                            errorHandle,
                            valOffset,
                            indOffset,
                            lenOffset,
                            0                            // never use rcodep above...
                            );
                        if (rc != 0)
                        {
                            _connection.CheckError(errorHandle, rc);
                        }
                    }

                    if (!_connection.UnicodeEnabled)
                    {
                        if (_metaType.UsesNationalCharacterSet)
                        {
                            Debug.Assert(!_metaType.IsLong, "LONG data may never be bound as NCHAR");
                            // NOTE:    the order is important here; setting charsetForm will
                            //          reset charsetId (I found this out the hard way...)
                            defineHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, (int)OCI.CHARSETFORM.SQLCS_NCHAR, errorHandle);
                        }
                        if (_bindAsUCS2)
                        {
                            // NOTE:    the order is important here; setting charsetForm will
                            //          reset charsetId (I found this out the hard way...)
                            defineHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, OCI.OCI_UCS2ID, errorHandle);
                        }
                    }
                    if (_metaType.IsLong)
                    {
                        // Initialize the longBuffer in the rowBuffer to null
                        Marshal.WriteIntPtr((IntPtr)_rowBuffer.PtrOffset(_valueOffset), IntPtr.Zero);

                        if (null != _longBuffer)
                        {
                            _longBuffer.Dispose();
                            _longBuffer = null;
                        }

                        // We require MTxOCI8 to be in the path somewhere for us to handle LONG data
                        if (!OCI.IsNewMtxOci8Installed)
#if EVERETT
                        { throw ADP.MustInstallNewMtxOciLONG(); }
#else //!EVERETT        {
                            throw ADP.MustInstallNewMtxOci();
                        }
#endif //!EVERETT
                        _callback = new OCI.Callback.OCICallbackDefine(_callback_GetColumnPiecewise);

                        rc = TracedNativeMethods.MTxOciDefineDynamic(
                            defineHandle,                               // defnp
                            errorHandle,                                // errhp
                            ADP.NullHandleRef,                          // dvoid *octxp,
                            _callback                                   // OCICallbackDefine ocbfp
                            );
                        if (rc != 0)
                        {
                            _connection.CheckError(errorHandle, rc);
                        }
                    }
                }
                finally
                {
                    // We don't need this any longer, get rid of it.
                    OciHandle.SafeDispose(ref defineHandle);
                }
            }
コード例 #4
0
        internal void Cleanup(bool disposing, bool silent)
        {
            //	Cleanup the connection as best we can, releasing as many objects
            //	as we can.  We use this when we fail to connect completely, when
            //	we are closing the connection, and when we're disposing of this
            //	object.

            bool fireEvent = false;

            _serverTimeZoneAdjustment = TimeSpan.MinValue;

            // Increment the close counter so the child objects can know when their
            // connection is toast (or being re-used)
            Interlocked.Increment(ref _closeCount);

            // If we're not disposing, it's because we went out of scope, and we're
            // being garbage collected.  We shouldn't touch any managed objects
            // or bad things can happen.
            if (disposing)
            {
                // We need to "dispose" of the internal connection object, either
                // by returning it to the pool (if it came from one) or by closing it
                // outright.
                if (null != _internalConnection)
                {
                    if (null == _internalConnection.Pool)
                    {
                        // We just close the connection; there is no need to rollback
                        // here because Oracle will do it for us.
                        _internalConnection.Close();
                    }
                    else
                    {
                        // Before we return the connection to the pool, we rollback any
                        // active transaction that may have been created.  Note that we
                        // don't bother with distributed transactions because we don't
                        // want to them back (it's handled by the TM).  We also don't
                        // worry about implicit transactions (like "select...for update")
                        // because we don't want to take the performance hit of the server
                        // round-trip when it isn't very likely.
                        if (TransactionState.LocalStarted == TransState)
                        {
                            // On the off chance that we have some failure during rollback
                            // we just eat it and make sure that the connection is doomed.
                            try
                            {
                                Rollback();
                            }
                            catch (Exception e)
                            {
                                ADP.TraceException(e);
                                _internalConnection.DoomThisConnection();
                            }
                        }
                        OracleConnectionPoolManager.ReturnPooledConnection(_internalConnection, this);
                    }

                    _internalConnection = null;
                }

                if (null != _scratchBuffer)
                {
                    _scratchBuffer.Dispose();
                    _scratchBuffer = null;
                }

                // Mark this connection as closed
                if (_state != ConnectionState.Closed)
                {
                    _state    = ConnectionState.Closed;
                    fireEvent = true;
                }

                _encodingDatabase = null;
                _encodingNational = null;

                if (fireEvent && !silent)
                {
                    OnStateChange(ConnectionState.Open, ConnectionState.Closed);
                }
            }
        }