internal static void SafeDispose(ref OciDefineHandle handle)
 {
     if (handle != null)
     {
         handle.Dispose();
     }
     handle = null;
 }
示例#2
0
        public object ExecuteOracleScalar()
        {
            moreResults = -1;

            object output = DBNull.Value;

            AssertConnectionIsOpen();
            AssertTransactionMatch();
            AssertCommandTextIsSet();

            if (Transaction != null)
            {
                Transaction.AttachToServiceContext();
            }

            OciStatementHandle statement = GetStatementHandle();

            try {
                if (preparedStatement == null)
                {
                    PrepareStatement(statement);
                }

                bool isNonQuery = IsNonQuery(statement);

                BindParameters(statement);

                if (isNonQuery == true)
                {
                    ExecuteNonQueryInternal(statement, false);
                }
                else
                {
                    statement.ExecuteQuery(false);

                    if (statement.Fetch())
                    {
                        OciDefineHandle defineHandle = (OciDefineHandle)statement.Values [0];
                        if (!defineHandle.IsNull)
                        {
                            output = defineHandle.GetOracleValue(Connection.SessionFormatProvider, Connection);
                        }
                        switch (defineHandle.DataType)
                        {
                        case OciDataType.Blob:
                        case OciDataType.Clob:
                            ((OracleLob)output).connection = Connection;
                            break;
                        }
                    }
                    UpdateParameterValues();
                }

                return(output);
            } finally {
                SafeDisposeHandle(statement);
            }
        }
示例#3
0
        public object GetOracleValue(int i)
        {
            OciDefineHandle defineHandle = (OciDefineHandle)statement.Values [i];

            switch (defineHandle.DataType)
            {
            case OciDataType.Raw:
                return(GetOracleBinary(i));

            case OciDataType.Date:
                return(GetOracleDateTime(i));

            case OciDataType.Clob:
            case OciDataType.Blob:
                return(GetOracleLob(i));

            case OciDataType.Integer:
            case OciDataType.Number:
            case OciDataType.Float:
                return(GetOracleNumber(i));

            case OciDataType.VarChar2:
            case OciDataType.String:
            case OciDataType.VarChar:
            case OciDataType.Char:
            case OciDataType.CharZ:
            case OciDataType.OciString:
            case OciDataType.LongVarChar:
            case OciDataType.Long:
            case OciDataType.RowIdDescriptor:
                return(GetOracleString(i));

            case OciDataType.IntervalDayToSecond:
                return(GetOracleTimeSpan(i));

            case OciDataType.IntervalYearToMonth:
                return(GetOracleMonthSpan(i));

            default:
                throw new NotImplementedException();
            }
        }
示例#4
0
        public override object GetValue(int i)
        {
            OciDefineHandle defineHandle = (OciDefineHandle)statement.Values [i];

            if (defineHandle.IsNull)
            {
                return(DBNull.Value);
            }

            switch (defineHandle.DataType)
            {
            case OciDataType.Blob:
            case OciDataType.Clob:
                OracleLob lob   = GetOracleLob(i);
                object    value = lob.Value;
                lob.Close();
                return(value);

            default:
                return(defineHandle.GetValue(command.Connection.SessionFormatProvider, command.Connection));
            }
        }
示例#5
0
        object GetValueByteArray(int i)
        {
            OciDefineHandle defineHandle = (OciDefineHandle)statement.Values[i];

            if (defineHandle.IsNull)
            {
                return(DBNull.Value);
            }

            switch (defineHandle.DataType)
            {
            case OciDataType.Blob:
            case OciDataType.Clob:
                OracleLob lob   = GetOracleLob(i);
                object    value = lob.Value;
                lob.Close();
                return(value);

            default:
                return(defineHandle.GetValueByteArray(command.Connection));
            }
        }
        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);
                }
            }
示例#7
0
        public override bool IsDBNull(int i)
        {
            OciDefineHandle defineHandle = (OciDefineHandle)statement.Values [i];

            return(defineHandle.IsNull);
        }
示例#8
0
        public override Type GetFieldType(int i)
        {
            OciDefineHandle defineHandle = (OciDefineHandle)statement.Values [i];

            return(defineHandle.FieldType);
        }
示例#9
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);
            }
        }