private void ReleaseStatementHandle(OciStatementHandle statementHandle)
 {
     if ((this.Connection.State != ConnectionState.Closed) && (this._preparedStatementHandle != statementHandle))
     {
         OciHandle.SafeDispose(ref statementHandle);
     }
 }
Ejemplo n.º 2
0
        /// <include file='doc\OracleDataReader.uex' path='docs/doc[@for="OracleDataReader.Close"]/*' />
        public void Close()
        {
            // Note that we do this first, which triggers IsClosed to return true.
            OciHandle.SafeDispose(ref _statementHandle);

            Cleanup();

            if (null != _refCursorDataReaders)
            {
                int i = _refCursorDataReaders.Length;

                while (--i >= 0)
                {
                    OracleDataReader refCursorDataReader = _refCursorDataReaders[i];
                    _refCursorDataReaders[i] = null;

                    if (null != refCursorDataReader)
                    {
                        refCursorDataReader.Dispose();
                    }
                }
                _refCursorDataReaders = null;
            }

            // If we were asked to close the connection when we're closed, then we need to
            // do that now.
            if (_closeConnectionToo && null != _connection)
            {
                _connection.Close();
            }

            _connection = null;
        }
Ejemplo n.º 3
0
        private bool NextResultInternal()
        {
            this.Cleanup();
            if ((this._refCursorDataReaders == null) || (this._nextRefCursor >= this._refCursorDataReaders.Length))
            {
                this._endOfData = true;
                this._hasRows   = 1;
                return(false);
            }
            if (this._nextRefCursor > 0)
            {
                this._refCursorDataReaders[this._nextRefCursor - 1].Dispose();
                this._refCursorDataReaders[this._nextRefCursor - 1] = null;
            }
            OciStatementHandle handle = this._statementHandle;

            this._statementHandle = this._refCursorDataReaders[this._nextRefCursor]._statementHandle;
            OciHandle.SafeDispose(ref handle);
            this._connection           = this._refCursorDataReaders[this._nextRefCursor]._connection;
            this._connectionCloseCount = this._refCursorDataReaders[this._nextRefCursor]._connectionCloseCount;
            this._hasRows         = this._refCursorDataReaders[this._nextRefCursor]._hasRows;
            this._recordsAffected = this._refCursorDataReaders[this._nextRefCursor]._recordsAffected;
            this._columnInfo      = this._refCursorDataReaders[this._nextRefCursor]._columnInfo;
            this._rowBufferLength = this._refCursorDataReaders[this._nextRefCursor]._rowBufferLength;
            this._rowsToPrefetch  = this._refCursorDataReaders[this._nextRefCursor]._rowsToPrefetch;
            this._nextRefCursor++;
            this._endOfData    = false;
            this._isLastBuffer = false;
            this._rowsTotal    = 0;
            return(true);
        }
        protected override DbSqlParserColumnCollection GatherTableColumns(DbSqlParserTable table)
        {
            OciStatementHandle          stmtp       = new OciStatementHandle(this._connection.ServiceContextHandle);
            OciErrorHandle              errorHandle = this._connection.ErrorHandle;
            StringBuilder               builder     = new StringBuilder();
            string                      schemaName  = table.SchemaName;
            string                      tableName   = table.TableName;
            DbSqlParserColumnCollection columns     = new DbSqlParserColumnCollection();

            builder.Append("select * from ");
            if (!System.Data.Common.ADP.IsEmpty(schemaName))
            {
                builder.Append(schemaName);
                builder.Append(".");
            }
            builder.Append(tableName);
            string stmt = builder.ToString();

            if ((TracedNativeMethods.OCIStmtPrepare(stmtp, errorHandle, stmt, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, this._connection) == 0) && (TracedNativeMethods.OCIStmtExecute(this._connection.ServiceContextHandle, stmtp, errorHandle, 0, OCI.MODE.OCI_DESCRIBE_ONLY) == 0))
            {
                int num3;
                stmtp.GetAttribute(OCI.ATTR.OCI_ATTR_PARAM_COUNT, out num3, errorHandle);
                for (int i = 0; i < num3; i++)
                {
                    string str;
                    OciParameterDescriptor handle = stmtp.GetDescriptor(i, errorHandle);
                    handle.GetAttribute(OCI.ATTR.OCI_ATTR_SQLCODE, out str, errorHandle, this._connection);
                    OciHandle.SafeDispose(ref handle);
                    str = this.QuotePrefixCharacter + str + this.QuoteSuffixCharacter;
                    columns.Add(null, schemaName, tableName, str, null);
                }
            }
            OciHandle.SafeDispose(ref stmtp);
            return(columns);
        }
Ejemplo n.º 5
0
 internal void Dispose()
 {
     NativeBuffer.SafeDispose(ref this._longBuffer);
     OciLobLocator.SafeDispose(ref this._lobLocator);
     OciHandle.SafeDispose(ref this._describeHandle);
     this._columnName = null;
     this._metaType   = null;
     this._callback   = null;
     this._connection = null;
 }
 internal void Dispose()
 {
     OciHandle.SafeDispose(ref this._bindHandle);
     if (this._freeTemporaryLob)
     {
         OracleLob lob = this._coercedValue as OracleLob;
         if (lob != null)
         {
             lob.Free();
         }
     }
 }
Ejemplo n.º 7
0
 internal void Dispose()
 {
     if (Interlocked.Decrement(ref this._cloneCount) == 0)
     {
         if ((this._openMode != 0) && !this.ConnectionIsClosed)
         {
             this.ForceClose();
         }
         OciHandle.SafeDispose(ref this._descriptor);
         GC.KeepAlive(this);
         this._connection = null;
     }
 }
        public override void Prepare()
        {
            IntPtr ptr;

            OracleConnection.ExecutePermission.Demand();
            Bid.ScopeEnter(out ptr, "<ora.OracleCommand.Prepare|API> %d#\n", this.ObjectID);
            try
            {
                if (this.ConnectionIsClosed)
                {
                    throw System.Data.Common.ADP.ClosedConnectionError();
                }
                if (System.Data.CommandType.Text == this.CommandType)
                {
                    short num2;
                    OciStatementHandle statementHandle = this.GetStatementHandle();
                    int    closeCount    = this._connection.CloseCount;
                    string statementText = this.StatementText;
                    int    rc            = TracedNativeMethods.OCIStmtPrepare(statementHandle, this.ErrorHandle, statementText, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, this.Connection);
                    if (rc != 0)
                    {
                        this.Connection.CheckError(this.ErrorHandle, rc);
                    }
                    statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_STMT_TYPE, out num2, this.ErrorHandle);
                    this._statementType = (OCI.STMT)num2;
                    if (OCI.STMT.OCI_STMT_SELECT == this._statementType)
                    {
                        rc = TracedNativeMethods.OCIStmtExecute(this._connection.ServiceContextHandle, statementHandle, this.ErrorHandle, 0, OCI.MODE.OCI_DESCRIBE_ONLY);
                        if (rc != 0)
                        {
                            this.Connection.CheckError(this.ErrorHandle, rc);
                        }
                    }
                    if (statementHandle != this._preparedStatementHandle)
                    {
                        OciHandle.SafeDispose(ref this._preparedStatementHandle);
                    }
                    this._preparedStatementHandle = statementHandle;
                    this._preparedAtCloseCount    = closeCount;
                }
                else if (this._preparedStatementHandle != null)
                {
                    OciHandle.SafeDispose(ref this._preparedStatementHandle);
                }
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
        }
Ejemplo n.º 9
0
        internal void Dispose()
        {
            int cloneCount = Interlocked.Decrement(ref _cloneCount);

            if (0 == cloneCount)
            {
                if (0 != _openMode && !ConnectionIsClosed)
                {
                    ForceClose();
                }
                OciHandle.SafeDispose(ref _descriptor);
                GC.KeepAlive(this);
                _connection = null;
            }
        }
 public override void Dispose()
 {
     this.Deactivate();
     OciEnlistContext.SafeDispose(ref this._enlistContext);
     OciHandle.SafeDispose(ref this._sessionHandle);
     OciHandle.SafeDispose(ref this._serviceContextHandle);
     OciHandle.SafeDispose(ref this._serverHandle);
     OciHandle.SafeDispose(ref this._errorHandle);
     OciHandle.SafeDispose(ref this._environmentHandle);
     if (this._scratchBuffer != null)
     {
         this._scratchBuffer.Dispose();
     }
     this._scratchBuffer       = null;
     this._encodingDatabase    = null;
     this._encodingNational    = null;
     this._transaction         = null;
     this._serverVersionString = null;
     base.Dispose();
 }
        public override int ExecuteNonQuery()
        {
            int    num;
            IntPtr ptr;

            OracleConnection.ExecutePermission.Demand();
            Bid.ScopeEnter(out ptr, "<ora.OracleCommand.ExecuteNonQuery|API> %d#\n", this.ObjectID);
            try
            {
                OciRowidDescriptor rowidDescriptor = null;
                int num2 = this.ExecuteNonQueryInternal(false, out rowidDescriptor);
                OciHandle.SafeDispose(ref rowidDescriptor);
                num = num2;
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
            return(num);
        }
        public override object ExecuteScalar()
        {
            object obj2;
            IntPtr ptr;

            OracleConnection.ExecutePermission.Demand();
            Bid.ScopeEnter(out ptr, "<ora.OracleCommand.ExecuteScalar|API> %d#\n", this.ObjectID);
            try
            {
                OciRowidDescriptor descriptor;
                object             obj3 = this.ExecuteScalarInternal(true, false, out descriptor);
                OciHandle.SafeDispose(ref descriptor);
                obj2 = obj3;
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
            return(obj2);
        }
        public int ExecuteOracleNonQuery(out OracleString rowid)
        {
            int    num;
            IntPtr ptr;

            OracleConnection.ExecutePermission.Demand();
            Bid.ScopeEnter(out ptr, "<ora.OracleCommand.ExecuteOracleNonQuery|API> %d#\n", this.ObjectID);
            try
            {
                OciRowidDescriptor rowidDescriptor = null;
                int num2 = this.ExecuteNonQueryInternal(true, out rowidDescriptor);
                rowid = GetPersistedRowid(this.Connection, rowidDescriptor);
                OciHandle.SafeDispose(ref rowidDescriptor);
                num = num2;
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
            return(num);
        }
Ejemplo n.º 14
0
        public override void Close()
        {
            IntPtr ptr;

            Bid.ScopeEnter(out ptr, "<ora.OracleDataReader.Close|API> %d#\n", this.ObjectID);
            try
            {
                OciHandle.SafeDispose(ref this._statementHandle);
                this.Cleanup();
                if (this._refCursorDataReaders != null)
                {
                    int length = this._refCursorDataReaders.Length;
                    while (--length >= 0)
                    {
                        OracleDataReader reader = this._refCursorDataReaders[length];
                        this._refCursorDataReaders[length] = null;
                        if (reader != null)
                        {
                            reader.Dispose();
                        }
                    }
                    this._refCursorDataReaders = null;
                }
                if (this._closeConnectionToo && (this._connection != null))
                {
                    this._connection.Close();
                }
                this._connection      = null;
                this._fieldNameLookup = null;
                this._schemaTable     = null;
            }
            finally
            {
                Bid.ScopeLeave(ref ptr);
            }
        }
Ejemplo n.º 15
0
        private bool NextResultInternal()
        {
            Cleanup();

            if (null == _refCursorDataReaders || _nextRefCursor >= _refCursorDataReaders.Length)
            {
                _endOfData = true; // force current result to be done.
                _hasRows   = x_hasRows_False;
                return(false);
            }

            if (_nextRefCursor > 0)
            {
                _refCursorDataReaders[_nextRefCursor - 1].Dispose();
                _refCursorDataReaders[_nextRefCursor - 1] = null;
            }

            OciHandle oldStatementHandle = _statementHandle;

            _statementHandle = _refCursorDataReaders[_nextRefCursor]._statementHandle;
            OciHandle.SafeDispose(ref oldStatementHandle);

            _connection           = _refCursorDataReaders[_nextRefCursor]._connection;
            _connectionCloseCount = _refCursorDataReaders[_nextRefCursor]._connectionCloseCount;
            _hasRows         = _refCursorDataReaders[_nextRefCursor]._hasRows;
            _recordsAffected = _refCursorDataReaders[_nextRefCursor]._recordsAffected;
            _columnInfo      = _refCursorDataReaders[_nextRefCursor]._columnInfo;
            _rowBufferLength = _refCursorDataReaders[_nextRefCursor]._rowBufferLength;
            _rowsToPrefetch  = _refCursorDataReaders[_nextRefCursor]._rowsToPrefetch;

            _nextRefCursor++;
            _endOfData    = false;
            _isLastBuffer = false;
            _rowsTotal    = 0;
            return(true);
        }
Ejemplo n.º 16
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);
                }
            }
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        //
        // Methods
        //
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        internal void Bind(
            OciHandle statementHandle,
            NativeBuffer parameterBuffer,
            OracleConnection connection
            )
        {
            IntPtr h;

            // Don't bother with parameters where the user asks for the default value.
            if (!IsDirection(Parameter, ParameterDirection.Output) && null == Parameter.Value)
            {
                return;
            }

            string    parameterName     = Parameter.ParameterName;
            OciHandle errorHandle       = connection.ErrorHandle;
            OciHandle environmentHandle = connection.EnvironmentHandle;

            int valueLength = 0;

            OCI.INDICATOR indicatorValue = OCI.INDICATOR.OK;
            int           bufferLength;

            OCI.DATATYPE ociType = _bindingMetaType.OciType;

            HandleRef indicatorLocation = parameterBuffer.PtrOffset(_indicatorOffset);
            HandleRef lengthLocation    = parameterBuffer.PtrOffset(_lengthOffset);
            HandleRef valueLocation     = parameterBuffer.PtrOffset(_valueOffset);

            if (IsDirection(Parameter, ParameterDirection.Input))
            {
                if (ADP.IsNull(_coercedValue))
                {
                    indicatorValue = OCI.INDICATOR.ISNULL;
                }
                else
                {
                    valueLength = PutOracleValue(
                        _coercedValue,
                        valueLocation,
                        _bindingMetaType,
                        connection);
                }
            }
            else
            {
                Debug.Assert(IsDirection(Parameter, ParameterDirection.Output), "non-output output parameter?");

                if (_bindingMetaType.IsVariableLength)
                {
                    valueLength = 0;                // Output-only values never have an input length...
                }
                else
                {
                    valueLength = _bufferLengthInBytes; // ...except when they're fixed length, to avoid ORA-01459 errors
                }
                OciLobLocator.SafeDispose(ref _locator);
                OciHandle.SafeDispose(ref _descriptor);

                switch (ociType)
                {
                case OCI.DATATYPE.BFILE:
                case OCI.DATATYPE.BLOB:
                case OCI.DATATYPE.CLOB:
                    _locator = new OciLobLocator(connection, _bindingMetaType.OracleType);
                    break;

                case OCI.DATATYPE.RSET:
                    _descriptor = new OciStatementHandle(environmentHandle);
                    break;
                }

                if (null != _locator)
                {
                    Marshal.WriteIntPtr((IntPtr)valueLocation, (IntPtr)_locator.Handle);
                }
                else if (null != _descriptor)
                {
                    Marshal.WriteIntPtr((IntPtr)valueLocation, (IntPtr)_descriptor.Handle);
                }
            }

            Marshal.WriteInt16((IntPtr)indicatorLocation, (Int16)indicatorValue);

            // Don't bind a length value for LONGVARCHAR or LONGVARRAW data, or you'll end
            // up with ORA-01098: program Interface error during Long Insert\nORA-01458: invalid length inside variable character string
            // errors.

            if (OCI.DATATYPE.LONGVARCHAR == ociType ||
                OCI.DATATYPE.LONGVARRAW == ociType)
            {
                lengthLocation = ADP.NullHandleRef;
            }
            else
            {
                // When we're binding this parameter as UCS2, the length we specify
                // must be in characters, not in bytes.
                if (_bindAsUCS2)
                {
                    Marshal.WriteInt32((IntPtr)lengthLocation, (Int32)(valueLength / ADP.CharSize));
                }
                else
                {
                    Marshal.WriteInt32((IntPtr)lengthLocation, (Int32)valueLength);
                }
            }

            if (IsDirection(Parameter, ParameterDirection.Output))
            {
                bufferLength = _bufferLengthInBytes;
            }
            else
            {
                bufferLength = valueLength;
            }

            // Finally, tell Oracle about our parameter.

            int rc = TracedNativeMethods.OCIBindByName(
                statementHandle,
                out h,
                errorHandle,
                parameterName,
                parameterName.Length,
                valueLocation,
                bufferLength,
                ociType,
                indicatorLocation,
                lengthLocation,
                ADP.NullHandleRef,
                0,
                ADP.NullHandleRef,
                OCI.MODE.OCI_DEFAULT
                );

            if (rc != 0)
            {
                _command.Connection.CheckError(errorHandle, rc);
            }

            _bindHandle = new OciBindHandle(statementHandle, h);

#if TRACEPARAMETERVALUES
            if (null != _coercedValue)
            {
                SafeNativeMethods.OutputDebugStringW("Value = '" + _coercedValue.ToString() + "'\n");
            }
#endif //TRACEPARAMETERVALUES

            // OK, character bindings have a few extra things we need to do to
            // deal with character sizes and alternate character sets.

            if (_bindingMetaType.IsCharacterType)
            {
                // To avoid problems when our buffer is larger than the maximum number
                // of characters, we use OCI_ATTR_MAXCHAR_SIZE to limit the number of
                // characters that will be used.  (Except on Oracle8i clients where it
                // isn't available)
                if (OCI.ClientVersionAtLeastOracle9i &&
                    IsDirection(Parameter, ParameterDirection.Output))
                {
                    _bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXCHAR_SIZE, (int)_bufferLength, errorHandle);
                }

                if ((bufferLength > _bindingMetaType.MaxBindSize / ADP.CharSize) ||
                    (!OCI.ClientVersionAtLeastOracle9i && _bindingMetaType.UsesNationalCharacterSet))           // need to specify MAXDATA_SIZE for OCI8 UCS2 bindings to work
                {
                    _bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXDATA_SIZE, (int)_bindingMetaType.MaxBindSize, errorHandle);
                }

                // NOTE:    the order is important here; setting charsetForm will
                //          reset charsetId (I found this out the hard way...)
                if (_bindingMetaType.UsesNationalCharacterSet)
                {
                    _bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, (int)OCI.CHARSETFORM.SQLCS_NCHAR, errorHandle);
                }

                // NOTE:    the order is important here; setting charsetForm will
                //          reset charsetId (I found this out the hard way...)
                if (_bindAsUCS2)
                {
                    _bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, OCI.OCI_UCS2ID, errorHandle);
                }
            }
        }
 internal void Dispose()
 {
     OciHandle.SafeDispose(ref _bindHandle);
 }
Ejemplo n.º 19
0
 internal static int DetermineClientVersion()
 {
     if (_clientVersion == 0)
     {
         int  num             = 0;
         MODE environmentMode = MODE.OCI_DATA_AT_EXEC | MODE.OCI_BATCH_MODE;
         try
         {
             System.Data.Common.UnsafeNativeMethods.OCILobCopy2(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0L, 0L, 0L);
             num = 0x65;
         }
         catch (EntryPointNotFoundException exception6)
         {
             System.Data.Common.ADP.TraceException(exception6);
             try
             {
                 OciHandle handle = new OciNlsEnvironmentHandle(environmentMode);
                 if (!handle.IsInvalid)
                 {
                     num = 0x5c;
                     OciHandle.SafeDispose(ref handle);
                 }
             }
             catch (EntryPointNotFoundException exception5)
             {
                 System.Data.Common.ADP.TraceException(exception5);
                 try
                 {
                     environmentMode |= MODE.OCI_UTF16;
                     OciHandle handle2 = new OciEnvironmentHandle(environmentMode, true);
                     num = 90;
                     OciHandle.SafeDispose(ref handle2);
                 }
                 catch (EntryPointNotFoundException exception4)
                 {
                     System.Data.Common.ADP.TraceException(exception4);
                     num = 80;
                 }
                 catch (Exception exception)
                 {
                     if (!System.Data.Common.ADP.IsCatchableExceptionType(exception))
                     {
                         throw;
                     }
                     System.Data.Common.ADP.TraceException(exception);
                     num = 0x51;
                 }
             }
         }
         catch (DllNotFoundException exception3)
         {
             System.Data.Common.ADP.TraceException(exception3);
             num = 0x49;
         }
         catch (BadImageFormatException exception2)
         {
             throw System.Data.Common.ADP.BadOracleClientImageFormat(exception2);
         }
         if (0x51 > num)
         {
             throw System.Data.Common.ADP.BadOracleClientVersion();
         }
         _clientVersion = num;
     }
     return(_clientVersion);
 }
Ejemplo n.º 20
0
        internal void Bind(OciStatementHandle statementHandle, NativeBuffer_RowBuffer buffer, OciErrorHandle errorHandle, int rowBufferLength)
        {
            OciDefineHandle defnp = null;
            int             num3;

            OCI.MODE     mode    = OCI.MODE.OCI_DEFAULT;
            OCI.DATATYPE ociType = this._metaType.OciType;
            this._rowBuffer = buffer;
            if (this._metaType.IsLong)
            {
                mode = OCI.MODE.OCI_DATA_AT_EXEC;
                num3 = 0x7fffffff;
            }
            else
            {
                num3 = this._byteSize;
            }
            IntPtr zero    = IntPtr.Zero;
            IntPtr rlenp   = IntPtr.Zero;
            IntPtr dataPtr = this._rowBuffer.DangerousGetDataPtr(this._valueOffset);

            if (-1 != this._indicatorOffset)
            {
                zero = this._rowBuffer.DangerousGetDataPtr(this._indicatorOffset);
            }
            if ((-1 != this._lengthOffset) && !this._metaType.IsLong)
            {
                rlenp = this._rowBuffer.DangerousGetDataPtr(this._lengthOffset);
            }
            try
            {
                IntPtr ptr3;
                int    rc = TracedNativeMethods.OCIDefineByPos(statementHandle, out ptr3, errorHandle, ((uint)this._ordinal) + 1, dataPtr, num3, ociType, zero, rlenp, IntPtr.Zero, mode);
                if (rc != 0)
                {
                    this._connection.CheckError(errorHandle, rc);
                }
                defnp = new OciDefineHandle(statementHandle, ptr3);
                if (rowBufferLength != 0)
                {
                    uint pvskip  = (uint)rowBufferLength;
                    uint indskip = (-1 != this._indicatorOffset) ? pvskip : 0;
                    uint rlskip  = ((-1 != this._lengthOffset) && !this._metaType.IsLong) ? pvskip : 0;
                    rc = TracedNativeMethods.OCIDefineArrayOfStruct(defnp, errorHandle, pvskip, indskip, rlskip, 0);
                    if (rc != 0)
                    {
                        this._connection.CheckError(errorHandle, rc);
                    }
                }
                if (this._metaType.UsesNationalCharacterSet)
                {
                    defnp.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, 2, errorHandle);
                }
                if (!this._connection.UnicodeEnabled && this._bindAsUTF16)
                {
                    defnp.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, 0x3e8, errorHandle);
                }
                if (this._metaType.IsLong)
                {
                    this._rowBuffer.WriteIntPtr(this._valueOffset, IntPtr.Zero);
                    this._callback = new OCI.Callback.OCICallbackDefine(this._callback_GetColumnPiecewise);
                    rc             = TracedNativeMethods.OCIDefineDynamic(defnp, errorHandle, IntPtr.Zero, this._callback);
                    if (rc != 0)
                    {
                        this._connection.CheckError(errorHandle, rc);
                    }
                }
            }
            finally
            {
                NativeBuffer.SafeDispose(ref this._longBuffer);
                OciHandle.SafeDispose(ref defnp);
            }
        }
        internal void Bind(OciStatementHandle statementHandle, NativeBuffer parameterBuffer, OracleConnection connection, ref bool mustRelease, ref SafeHandle handleToBind)
        {
            if (IsDirection(this.Parameter, ParameterDirection.Output) || (this.Parameter.Value != null))
            {
                int                     num2;
                IntPtr                  ptr2;
                string                  parameterName        = this.Parameter.ParameterName;
                OciErrorHandle          errorHandle          = connection.ErrorHandle;
                OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle;
                int                     num     = 0;
                OCI.INDICATOR           oK      = OCI.INDICATOR.OK;
                OCI.DATATYPE            ociType = this._bindingMetaType.OciType;
                IntPtr                  dataPtr = parameterBuffer.DangerousGetDataPtr(this._indicatorOffset);
                IntPtr                  alenp   = parameterBuffer.DangerousGetDataPtr(this._lengthOffset);
                IntPtr                  valuep  = parameterBuffer.DangerousGetDataPtr(this._valueOffset);
                OciHandle.SafeDispose(ref this._dateTimeDescriptor);
                if (IsDirection(this.Parameter, ParameterDirection.Input))
                {
                    if (System.Data.Common.ADP.IsNull(this._coercedValue))
                    {
                        oK = OCI.INDICATOR.ISNULL;
                        switch (ociType)
                        {
                        case OCI.DATATYPE.INT_TIMESTAMP:
                        case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                        case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                            this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection);
                            handleToBind             = this._dateTimeDescriptor;
                            break;
                        }
                    }
                    else
                    {
                        num = this.PutOracleValue(this._coercedValue, parameterBuffer, this._valueOffset, this._bindingMetaType, connection, ref handleToBind);
                    }
                }
                else
                {
                    if (this._bindingMetaType.IsVariableLength)
                    {
                        num = 0;
                    }
                    else
                    {
                        num = this._bufferLength;
                    }
                    OciLobLocator.SafeDispose(ref this._locator);
                    OciHandle.SafeDispose(ref this._descriptor);
                    switch (ociType)
                    {
                    case OCI.DATATYPE.CLOB:
                    case OCI.DATATYPE.BLOB:
                    case OCI.DATATYPE.BFILE:
                        this._locator = new OciLobLocator(connection, this._bindingMetaType.OracleType);
                        handleToBind  = this._locator.Descriptor;
                        break;

                    case OCI.DATATYPE.RSET:
                        this._descriptor = new OciStatementHandle(serviceContextHandle);
                        handleToBind     = this._descriptor;
                        break;

                    case OCI.DATATYPE.INT_TIMESTAMP:
                    case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                    case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                        this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection);
                        handleToBind             = this._dateTimeDescriptor;
                        break;
                    }
                }
                if (handleToBind != null)
                {
                    handleToBind.DangerousAddRef(ref mustRelease);
                    parameterBuffer.WriteIntPtr(this._valueOffset, handleToBind.DangerousGetHandle());
                }
                parameterBuffer.WriteInt16(this._indicatorOffset, (short)oK);
                if ((OCI.DATATYPE.LONGVARCHAR == ociType) || (OCI.DATATYPE.LONGVARRAW == ociType))
                {
                    alenp = IntPtr.Zero;
                }
                else if (this._bindAsUCS2)
                {
                    parameterBuffer.WriteInt32(this._lengthOffset, num / System.Data.Common.ADP.CharSize);
                }
                else
                {
                    parameterBuffer.WriteInt32(this._lengthOffset, num);
                }
                if (IsDirection(this.Parameter, ParameterDirection.Output))
                {
                    num2 = this._bufferLength;
                }
                else
                {
                    num2 = num;
                }
                OCI.DATATYPE dty = ociType;
                switch (ociType)
                {
                case OCI.DATATYPE.INT_TIMESTAMP:
                    dty = OCI.DATATYPE.TIMESTAMP;
                    break;

                case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                    dty = OCI.DATATYPE.TIMESTAMP_TZ;
                    break;

                case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                    dty = OCI.DATATYPE.TIMESTAMP_LTZ;
                    break;
                }
                int rc = TracedNativeMethods.OCIBindByName(statementHandle, out ptr2, errorHandle, parameterName, parameterName.Length, valuep, num2, dty, dataPtr, alenp, OCI.MODE.OCI_DEFAULT);
                if (rc != 0)
                {
                    this._command.Connection.CheckError(errorHandle, rc);
                }
                this._bindHandle = new OciBindHandle(statementHandle, ptr2);
                if (this._bindingMetaType.IsCharacterType)
                {
                    if (OCI.ClientVersionAtLeastOracle9i && IsDirection(this.Parameter, ParameterDirection.Output))
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXCHAR_SIZE, this._bindSize, errorHandle);
                    }
                    if ((num2 > (this._bindingMetaType.MaxBindSize / System.Data.Common.ADP.CharSize)) || (!OCI.ClientVersionAtLeastOracle9i && this._bindingMetaType.UsesNationalCharacterSet))
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXDATA_SIZE, this._bindingMetaType.MaxBindSize, errorHandle);
                    }
                    if (this._bindingMetaType.UsesNationalCharacterSet)
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, 2, errorHandle);
                    }
                    if (this._bindAsUCS2)
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, 0x3e8, errorHandle);
                    }
                }
                GC.KeepAlive(parameterBuffer);
            }
        }
        private bool OpenOnLocalTransaction(string userName, string password, string serverName, bool integratedSecurity, bool unicode, bool omitOracleConnectionName)
        {
            int rc = 0;

            OCI.MODE environmentMode = OCI.MODE.OCI_DATA_AT_EXEC | OCI.MODE.OCI_BATCH_MODE;
            OCI.DetermineClientVersion();
            if (unicode)
            {
                if (OCI.ClientVersionAtLeastOracle9i)
                {
                    environmentMode |= OCI.MODE.OCI_UTF16;
                }
                else
                {
                    unicode = false;
                }
            }
            this._environmentHandle = new OciEnvironmentHandle(environmentMode, unicode);
            if (this._environmentHandle.IsInvalid)
            {
                throw System.Data.Common.ADP.CouldNotCreateEnvironment("OCIEnvCreate", rc);
            }
            this._errorHandle          = new OciErrorHandle(this._environmentHandle);
            this._serverHandle         = new OciServerHandle(this._errorHandle);
            this._sessionHandle        = new OciSessionHandle(this._serverHandle);
            this._serviceContextHandle = new OciServiceContextHandle(this._sessionHandle);
            try
            {
                OCI.CRED cred;
                rc = TracedNativeMethods.OCIServerAttach(this._serverHandle, this._errorHandle, serverName, serverName.Length, OCI.MODE.OCI_DEFAULT);
                if (rc != 0)
                {
                    if (1 == rc)
                    {
                        this.CreateDeferredInfoMessage(this.ErrorHandle, rc);
                    }
                    else
                    {
                        OracleException.Check(this.ErrorHandle, rc);
                    }
                }
                this._serviceContextHandle.SetAttribute(OCI.ATTR.OCI_ATTR_SERVER, this._serverHandle, this._errorHandle);
                if (integratedSecurity)
                {
                    cred = OCI.CRED.OCI_CRED_EXT;
                }
                else
                {
                    cred = OCI.CRED.OCI_CRED_RDBMS;
                    this._sessionHandle.SetAttribute(OCI.ATTR.OCI_ATTR_USERNAME, userName, this._errorHandle);
                    if (password != null)
                    {
                        this._sessionHandle.SetAttribute(OCI.ATTR.OCI_ATTR_PASSWORD, password, this._errorHandle);
                    }
                }
                if (!omitOracleConnectionName)
                {
                    string dataSource = this._connectionOptions.DataSource;
                    if (dataSource.Length > 0x10)
                    {
                        dataSource = dataSource.Substring(0, 0x10);
                    }
                    this._serverHandle.SetAttribute(OCI.ATTR.OCI_ATTR_EXTERNAL_NAME, dataSource, this._errorHandle);
                    this._serverHandle.SetAttribute(OCI.ATTR.OCI_ATTR_INTERNAL_NAME, dataSource, this._errorHandle);
                }
                rc = TracedNativeMethods.OCISessionBegin(this._serviceContextHandle, this._errorHandle, this._sessionHandle, cred, OCI.MODE.OCI_DEFAULT);
                if (rc != 0)
                {
                    if (1 == rc)
                    {
                        this.CreateDeferredInfoMessage(this.ErrorHandle, rc);
                    }
                    else
                    {
                        OracleException.Check(this.ErrorHandle, rc);
                    }
                }
                this._serviceContextHandle.SetAttribute(OCI.ATTR.OCI_ATTR_SESSION, this._sessionHandle, this._errorHandle);
            }
            catch (OracleException)
            {
                OciHandle.SafeDispose(ref this._serviceContextHandle);
                OciHandle.SafeDispose(ref this._sessionHandle);
                OciHandle.SafeDispose(ref this._serverHandle);
                OciHandle.SafeDispose(ref this._errorHandle);
                OciHandle.SafeDispose(ref this._environmentHandle);
                throw;
            }
            return(true);
        }
        internal static OracleString GetPersistedRowid(OracleConnection connection, OciRowidDescriptor rowidHandle)
        {
            OracleString @null = OracleString.Null;

            if (rowidHandle != null)
            {
                OciErrorHandle errorHandle   = connection.ErrorHandle;
                NativeBuffer   scratchBuffer = connection.GetScratchBuffer(0xf82);
                bool           success       = false;
                bool           flag          = false;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    int num;
                    scratchBuffer.DangerousAddRef(ref success);
                    if (OCI.ClientVersionAtLeastOracle9i)
                    {
                        int length = scratchBuffer.Length;
                        num = TracedNativeMethods.OCIRowidToChar(rowidHandle, scratchBuffer, ref length, errorHandle);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        return(new OracleString(scratchBuffer.PtrToStringAnsi(0, length)));
                    }
                    rowidHandle.DangerousAddRef(ref flag);
                    OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle;
                    OciStatementHandle      stmtp = new OciStatementHandle(serviceContextHandle);
                    string stmt   = "begin :rowid := :rdesc; end;";
                    int    offset = 0;
                    int    num6   = 4;
                    int    num5   = 8;
                    int    num3   = 12;
                    int    num2   = 0x10;
                    int    num4   = 20;
                    try
                    {
                        IntPtr ptr;
                        IntPtr ptr2;
                        num = TracedNativeMethods.OCIStmtPrepare(stmtp, errorHandle, stmt, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, connection);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        scratchBuffer.WriteIntPtr(num5, rowidHandle.DangerousGetHandle());
                        scratchBuffer.WriteInt32(offset, 0);
                        scratchBuffer.WriteInt32(num6, 4);
                        scratchBuffer.WriteInt32(num3, 0);
                        scratchBuffer.WriteInt32(num2, 0xf6e);
                        num = TracedNativeMethods.OCIBindByName(stmtp, out ptr2, errorHandle, "rowid", 5, scratchBuffer.DangerousGetDataPtr(num4), 0xf6e, OCI.DATATYPE.VARCHAR2, scratchBuffer.DangerousGetDataPtr(num3), scratchBuffer.DangerousGetDataPtr(num2), OCI.MODE.OCI_DEFAULT);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        num = TracedNativeMethods.OCIBindByName(stmtp, out ptr, errorHandle, "rdesc", 5, scratchBuffer.DangerousGetDataPtr(num5), 4, OCI.DATATYPE.ROWID_DESC, scratchBuffer.DangerousGetDataPtr(offset), scratchBuffer.DangerousGetDataPtr(num6), OCI.MODE.OCI_DEFAULT);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        num = TracedNativeMethods.OCIStmtExecute(serviceContextHandle, stmtp, errorHandle, 1, OCI.MODE.OCI_DEFAULT);
                        if (num != 0)
                        {
                            connection.CheckError(errorHandle, num);
                        }
                        if (scratchBuffer.ReadInt16(num3) == -1)
                        {
                            return(@null);
                        }
                        @null = new OracleString(scratchBuffer, num4, num2, MetaType.GetMetaTypeForType(OracleType.RowId), connection, false, true);
                        GC.KeepAlive(rowidHandle);
                    }
                    finally
                    {
                        OciHandle.SafeDispose(ref stmtp);
                    }
                }
                finally
                {
                    if (flag)
                    {
                        rowidHandle.DangerousRelease();
                    }
                    if (success)
                    {
                        scratchBuffer.DangerousRelease();
                    }
                }
            }
            return(@null);
        }
Ejemplo n.º 24
0
        internal bool Describe(ref int offset, OracleConnection connection, OciErrorHandle errorHandle)
        {
            byte  num;
            short num3;
            bool  flag  = false;
            bool  flag2 = false;

            this._describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_SQLCODE, out this._columnName, errorHandle, this._connection);
            this._describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_OBJECT, out num3, errorHandle);
            this._describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_SESSION, out num, errorHandle);
            this._isNullable = 0 != num;
            OCI.DATATYPE ociType = (OCI.DATATYPE)num3;
            switch (ociType)
            {
            case OCI.DATATYPE.VARCHAR2:
            case OCI.DATATYPE.CHAR:
            {
                int num2;
                this._describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_FNCODE, out this._byteSize, errorHandle);
                this._describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, out num, errorHandle);
                OCI.CHARSETFORM charsetform = (OCI.CHARSETFORM)num;
                this._bindAsUTF16 = connection.ServerVersionAtLeastOracle8;
                if (connection.ServerVersionAtLeastOracle9i && OCI.ClientVersionAtLeastOracle9i)
                {
                    this._describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_CHAR_SIZE, out num3, errorHandle);
                    num2 = num3;
                }
                else
                {
                    num2 = this._byteSize;
                }
                if (charsetform == OCI.CHARSETFORM.SQLCS_NCHAR)
                {
                    this._metaType = MetaType.GetMetaTypeForType((OCI.DATATYPE.CHAR == ociType) ? System.Data.OracleClient.OracleType.NChar : System.Data.OracleClient.OracleType.NVarChar);
                }
                else
                {
                    this._metaType = MetaType.GetMetaTypeForType((OCI.DATATYPE.CHAR == ociType) ? System.Data.OracleClient.OracleType.Char : System.Data.OracleClient.OracleType.VarChar);
                    if (this._bindAsUTF16)
                    {
                        this._byteSize *= System.Data.Common.ADP.CharSize;
                    }
                }
                this._byteSize = Math.Max(this._byteSize, num2 * System.Data.Common.ADP.CharSize);
                flag           = true;
                break;
            }

            case OCI.DATATYPE.NUMBER:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.Number);
                this._byteSize = this._metaType.BindSize;
                this._describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_ENV, out this._precision, errorHandle);
                this._describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_SERVER, out this._scale, errorHandle);
                break;

            case OCI.DATATYPE.LONG:
                this._metaType    = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.LongVarChar);
                this._byteSize    = this._metaType.BindSize;
                flag              = true;
                flag2             = true;
                this._bindAsUTF16 = connection.ServerVersionAtLeastOracle8;
                break;

            case OCI.DATATYPE.ROWID:
            case OCI.DATATYPE.ROWID_DESC:
            case OCI.DATATYPE.UROWID:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.RowId);
                this._byteSize = this._metaType.BindSize;
                if (connection.UnicodeEnabled)
                {
                    this._bindAsUTF16 = true;
                    this._byteSize   *= System.Data.Common.ADP.CharSize;
                }
                flag = true;
                break;

            case OCI.DATATYPE.DATE:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.DateTime);
                this._byteSize = this._metaType.BindSize;
                flag           = true;
                break;

            case OCI.DATATYPE.RAW:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.Raw);
                this._describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_FNCODE, out this._byteSize, errorHandle);
                flag = true;
                break;

            case OCI.DATATYPE.LONGRAW:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.LongRaw);
                this._byteSize = this._metaType.BindSize;
                flag           = true;
                flag2          = true;
                break;

            case OCI.DATATYPE.CLOB:
                this._describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, out num, errorHandle);
                this._metaType = MetaType.GetMetaTypeForType((2 == num) ? System.Data.OracleClient.OracleType.NClob : System.Data.OracleClient.OracleType.Clob);
                this._byteSize = this._metaType.BindSize;
                flag2          = true;
                break;

            case OCI.DATATYPE.BLOB:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.Blob);
                this._byteSize = this._metaType.BindSize;
                flag2          = true;
                break;

            case OCI.DATATYPE.BFILE:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.BFile);
                this._byteSize = this._metaType.BindSize;
                flag2          = true;
                break;

            case OCI.DATATYPE.TIMESTAMP:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.Timestamp);
                this._byteSize = this._metaType.BindSize;
                flag           = true;
                break;

            case OCI.DATATYPE.TIMESTAMP_TZ:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.TimestampWithTZ);
                this._byteSize = this._metaType.BindSize;
                flag           = true;
                break;

            case OCI.DATATYPE.INTERVAL_YM:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.IntervalYearToMonth);
                this._byteSize = this._metaType.BindSize;
                break;

            case OCI.DATATYPE.INTERVAL_DS:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.IntervalDayToSecond);
                this._byteSize = this._metaType.BindSize;
                break;

            case OCI.DATATYPE.TIMESTAMP_LTZ:
                this._metaType = MetaType.GetMetaTypeForType(System.Data.OracleClient.OracleType.TimestampLocal);
                this._byteSize = this._metaType.BindSize;
                flag           = true;
                break;

            default:
                throw System.Data.Common.ADP.TypeNotSupported(ociType);
            }
            if (this._isNullable)
            {
                this._indicatorOffset = offset;
                offset += IntPtr.Size;
            }
            else
            {
                this._indicatorOffset = -1;
            }
            if (flag)
            {
                this._lengthOffset = offset;
                offset            += IntPtr.Size;
            }
            else
            {
                this._lengthOffset = -1;
            }
            this._valueOffset = offset;
            if ((OCI.DATATYPE.LONG == ociType) || (OCI.DATATYPE.LONGRAW == ociType))
            {
                offset += IntPtr.Size;
            }
            else
            {
                offset += this._byteSize;
            }
            offset = (offset + (IntPtr.Size - 1)) & ~(IntPtr.Size - 1);
            OciHandle.SafeDispose(ref this._describeHandle);
            return(flag2);
        }
Ejemplo n.º 25
0
        override protected DBSqlParserColumnCollection GatherTableColumns(
            DBSqlParserTable table
            )
        {
            //  Called to get a column list for the table specified.

            OciHandle     statementHandle = _connection.EnvironmentHandle.CreateOciHandle(OCI.HTYPE.OCI_HTYPE_STMT);
            OciHandle     errorHandle     = _connection.ErrorHandle;
            StringBuilder sb         = new StringBuilder();
            string        schemaName = table.SchemaName;
            string        tableName  = table.TableName;
            string        columnName;
            int           tableColumnCount;
            int           rc;
            string        tempStatement;

            DBSqlParserColumnCollection columns = new DBSqlParserColumnCollection();

            Debug.Assert(string.Empty == table.DatabaseName, "oracle doesn't support 4 part names!");

            sb.Append("select * from ");

            if (String.Empty != schemaName)
            {
                sb.Append(schemaName);
                sb.Append(".");
            }

            sb.Append(tableName);

            tempStatement = sb.ToString();

            rc = TracedNativeMethods.OCIStmtPrepare(
                statementHandle,
                errorHandle,
                tempStatement,
                tempStatement.Length,
                OCI.SYNTAX.OCI_NTV_SYNTAX,
                OCI.MODE.OCI_DEFAULT,
                _connection
                );

            if (0 == rc)
            {
                rc = TracedNativeMethods.OCIStmtExecute(
                    _connection.ServiceContextHandle,
                    statementHandle,
                    errorHandle,
                    0,                                              // iters
                    0,                                              // rowoff
                    ADP.NullHandleRef,                              // snap_in
                    ADP.NullHandleRef,                              // snap_out
                    OCI.MODE.OCI_DESCRIBE_ONLY                      // mode
                    );

                if (0 == rc)
                {
                    // Build the column list for the table
                    statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_PARAM_COUNT, out tableColumnCount, errorHandle);

                    for (int j = 0; j < tableColumnCount; j++)
                    {
                        OciHandle describeHandle = statementHandle.GetDescriptor(j, errorHandle);
                        describeHandle.GetAttribute(OCI.ATTR.OCI_ATTR_NAME, out columnName, errorHandle, _connection);
                        OciHandle.SafeDispose(ref describeHandle);

                        columnName = QuotePrefixCharacter + columnName + QuoteSuffixCharacter;

                        columns.Add(null, schemaName, tableName, columnName, null);
                    }

                    // Now, derive the key information for the statement and update the column list
                    // with it.
                }
            }

            // Clean up and return;
            OciHandle.SafeDispose(ref statementHandle);

            return(columns);
        }