示例#1
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////
        //
        // Constructors
        //
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        internal OciEnlistContext(
            string userName,
            string password,
            string serverName,
            OciHandle serviceContextHandle,
            OciHandle errorHandle)
        {
            _enlistContext        = IntPtr.Zero;
            _serviceContextHandle = serviceContextHandle;

            int rc = 0;

            try {
                rc = TracedNativeMethods.OraMTSEnlCtxGet(userName, password, serverName, _serviceContextHandle, errorHandle, 0, out _enlistContext);
            }
            catch (DllNotFoundException e)
            {
                ADP.DistribTxRequiresOracleServicesForMTS(e);
            }

            if (0 != rc)
            {
                OracleException.Check(errorHandle, rc);
            }
        }
示例#2
0
        internal void SetAttribute(
            OCI.ATTR attribute,
            string value,
            OciHandle errorHandle
            )
        {
            int valueLengthAsChars = value.Length;

            byte[] valueAsBytes       = new byte[valueLengthAsChars * 4];
            int    valueLengthAsBytes = GetBytes(value.ToCharArray(), 0, valueLengthAsChars, valueAsBytes, 0);

            int rc = TracedNativeMethods.OCIAttrSet(
                this,                       // trgthndlp/trghndltyp
                valueAsBytes,               // attributep
                valueLengthAsBytes,         // size
                attribute,                  // attrtype
                errorHandle                 // errhp
                );

            if (0 != rc)
            {
                OracleException.Check(errorHandle, rc);
            }

            GC.KeepAlive(this);
        }
示例#3
0
        internal OciHandle GetDescriptor(
            int i,
            OciHandle errorHandle
            )
        {
            //  Wraps the OCIParamGet call. We do not expect it to fail, so we
            //  will throw if it does.

            IntPtr paramdesc;
            int    rc = TracedNativeMethods.OCIParamGet(
                this,
                errorHandle,
                out paramdesc,
                i + 1
                );

            if (0 != rc)
            {
                OracleException.Check(errorHandle, rc);
            }

            OciHandle result = new OciParameterDescriptor(this, paramdesc);

            GC.KeepAlive(this);
            return(result);
        }
示例#4
0
 internal OciEnlistContext(byte[] userName, byte[] password, byte[] serverName, OciServiceContextHandle serviceContextHandle, OciErrorHandle errorHandle) : base(IntPtr.Zero, true)
 {
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
     }
     finally
     {
         this._serviceContextHandle = serviceContextHandle;
         int rc = 0;
         try
         {
             rc = TracedNativeMethods.OraMTSEnlCtxGet(userName, password, serverName, this._serviceContextHandle, errorHandle, out this.handle);
         }
         catch (DllNotFoundException exception)
         {
             throw System.Data.Common.ADP.DistribTxRequiresOracleServicesForMTS(exception);
         }
         if (rc != 0)
         {
             OracleException.Check(errorHandle, rc);
         }
         serviceContextHandle.AddRef();
     }
 }
        internal void SetAttribute(OCI.ATTR attribute, int value, OciErrorHandle errorHandle)
        {
            int rc = TracedNativeMethods.OCIAttrSet(this, ref value, 0, attribute, errorHandle);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
        }
示例#6
0
        private static void InternalSub(OciErrorHandle errorHandle, byte[] x, byte[] y, byte[] result)
        {
            int rc = System.Data.Common.UnsafeNativeMethods.OCINumberSub(errorHandle, x, y, result);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
        }
示例#7
0
        private static void FromUInt64(OciErrorHandle errorHandle, ulong ulongValue, byte[] result)
        {
            int rc = System.Data.Common.UnsafeNativeMethods.OCINumberFromInt(errorHandle, ref ulongValue, 8, OCI.SIGN.OCI_NUMBER_UNSIGNED, result);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
        }
示例#8
0
        private static void InternalTrunc(OciErrorHandle errorHandle, byte[] n, int position, byte[] result)
        {
            int rc = System.Data.Common.UnsafeNativeMethods.OCINumberTrunc(errorHandle, n, position, result);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
        }
示例#9
0
        private static void InternalShift(OciErrorHandle errorHandle, byte[] n, int digits, byte[] result)
        {
            int rc = System.Data.Common.UnsafeNativeMethods.OCINumberShift(errorHandle, n, digits, result);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
        }
示例#10
0
        internal void Join(OracleInternalConnection internalConnection, Transaction indigoTransaction)
        {
            IDtcTransaction oletxTransaction = System.Data.Common.ADP.GetOletxTransaction(indigoTransaction);
            int             rc = TracedNativeMethods.OraMTSJoinTxn(this, oletxTransaction);

            if (rc != 0)
            {
                OracleException.Check(rc, internalConnection);
            }
        }
        internal void GetAttribute(OCI.ATTR attribute, out int value, OciErrorHandle errorHandle)
        {
            uint sizep = 0;
            int  rc    = TracedNativeMethods.OCIAttrGet(this, out value, out sizep, attribute, errorHandle);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
        }
示例#12
0
        internal void Join(ITransaction transaction)
        {
            int rc = TracedNativeMethods.OraMTSJoinTxn(Handle, transaction);

            if (0 != rc)
            {
                OracleException.Check(rc);
            }

            _transaction = transaction;
        }
示例#13
0
        internal OciParameterDescriptor GetDescriptor(int i, OciErrorHandle errorHandle)
        {
            IntPtr ptr;
            int    rc = TracedNativeMethods.OCIParamGet(this, base.HandleType, errorHandle, out ptr, i + 1);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
            return(new OciParameterDescriptor(this, ptr));
        }
示例#14
0
        private static ulong ToUInt64(OciErrorHandle errorHandle, byte[] value)
        {
            ulong num2;
            int   rc = System.Data.Common.UnsafeNativeMethods.OCINumberToInt(errorHandle, value, 8, OCI.SIGN.OCI_NUMBER_UNSIGNED, out num2);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
            return(num2);
        }
示例#15
0
        private static int InternalSign(OciErrorHandle errorHandle, byte[] n)
        {
            int num2;
            int rc = System.Data.Common.UnsafeNativeMethods.OCINumberSign(errorHandle, n, out num2);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
            return(num2);
        }
        internal void Commit()
        {
            int rc = TracedNativeMethods.OCITransCommit(this.ServiceContextHandle, this.ErrorHandle, OCI.MODE.OCI_DEFAULT);

            if (rc != 0)
            {
                OracleException.Check(this.ErrorHandle, rc);
            }
            this.TransactionState = System.Data.OracleClient.TransactionState.AutoCommit;
            this.Transaction      = null;
        }
        internal void SetAttribute(OCI.ATTR attribute, string value, OciErrorHandle errorHandle)
        {
            uint length = (uint)value.Length;

            byte[] bytes = new byte[length * 4];
            uint   size  = this.GetBytes(value.ToCharArray(), 0, length, bytes, 0);
            int    rc    = TracedNativeMethods.OCIAttrSet(this, bytes, size, attribute, errorHandle);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
        }
示例#18
0
        private static void FromDouble(OciErrorHandle errorHandle, double dblValue, byte[] result)
        {
            if ((dblValue < doubleMinValue) || (dblValue > doubleMaxValue))
            {
                throw System.Data.Common.ADP.OperationResultedInOverflow();
            }
            int rc = System.Data.Common.UnsafeNativeMethods.OCINumberFromReal(errorHandle, ref dblValue, 8, result);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
        }
        internal void GetAttribute(OCI.ATTR attribute, out string value, OciErrorHandle errorHandle, OracleConnection connection)
        {
            IntPtr zero  = IntPtr.Zero;
            uint   sizep = 0;
            int    rc    = TracedNativeMethods.OCIAttrGet(this, ref zero, ref sizep, attribute, errorHandle);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
            byte[] destination = new byte[sizep];
            Marshal.Copy(zero, destination, 0, (int)sizep);
            value = connection.GetString(destination);
        }
示例#20
0
        internal void GetRowid(OciStatementHandle statementHandle, OciErrorHandle errorHandle)
        {
            uint sizep = 0;
            int  rc    = TracedNativeMethods.OCIAttrGet(statementHandle, this, out sizep, OCI.ATTR.OCI_ATTR_ROWID, errorHandle);

            if (100 == rc)
            {
                base.Dispose();
            }
            else if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
        }
示例#21
0
        private static string ToString(OciErrorHandle errorHandle, byte[] value)
        {
            byte[] buffer = new byte[0x40];
            uint   length = (uint)buffer.Length;
            int    rc     = System.Data.Common.UnsafeNativeMethods.OCINumberToText(errorHandle, value, "TM9", 3, IntPtr.Zero, 0, ref length, buffer);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
            int index = Array.IndexOf <byte>(buffer, 0x3a);

            index = (index > 0) ? index : Array.LastIndexOf(buffer, 0);
            return(Encoding.Default.GetString(buffer, 0, (index > 0) ? index : ((int)length)));
        }
示例#22
0
        internal void GetAttribute(
            OCI.ATTR attribute,
            out int value,
            OciHandle errorHandle
            )
        {
            int zero = 0;
            int rc   = TracedNativeMethods.OCIAttrGet(this, out value, out zero, attribute, errorHandle);

            if (0 != rc)
            {
                OracleException.Check(errorHandle, rc);
            }

            GC.KeepAlive(this);
        }
示例#23
0
        public static OracleNumber Floor(OracleNumber n)
        {
            if (n.IsNull)
            {
                return(Null);
            }
            OracleConnection.ExecutePermission.Demand();
            OciErrorHandle errorHandle = TempEnvironment.GetErrorHandle();
            OracleNumber   number      = new OracleNumber(false);
            int            rc          = System.Data.Common.UnsafeNativeMethods.OCINumberFloor(errorHandle, n._value, number._value);

            if (rc != 0)
            {
                OracleException.Check(errorHandle, rc);
            }
            return(number);
        }
示例#24
0
        internal void GetAttribute(
            OCI.ATTR attribute,
            out string value,
            OciHandle errorHandle,
            OracleConnection connection
            )
        {
            IntPtr tempptr;
            int    tempub4;
            int    rc = TracedNativeMethods.OCIAttrGet(this, out tempptr, out tempub4, attribute, errorHandle);

            if (0 != rc)
            {
                OracleException.Check(errorHandle, rc);
            }

            value = connection.GetString(tempptr, tempub4, false);

            GC.KeepAlive(this);
        }
示例#25
0
 private void FromStringOfDigits(OciErrorHandle errorHandle, string s, byte[] result)
 {
     if (s.Length <= 0x3f)
     {
         int rc = System.Data.Common.UnsafeNativeMethods.OCINumberFromText(errorHandle, s, (uint)s.Length, "999999999999999999999999999999999999999999999999999999999999999", 0x3f, IntPtr.Zero, 0, result);
         if (rc != 0)
         {
             OracleException.Check(errorHandle, rc);
         }
     }
     else
     {
         byte[] buffer = new byte[0x16];
         string str2   = s.Substring(0, 0x3f);
         string str    = s.Substring(0x3f);
         this.FromStringOfDigits(errorHandle, str2, buffer);
         this.FromStringOfDigits(errorHandle, str, result);
         InternalShift(errorHandle, buffer, str.Length, buffer);
         InternalAdd(errorHandle, result, buffer, result);
     }
 }
示例#26
0
        internal void SetAttribute(
            OCI.ATTR attribute,
            OciHandle value,
            OciHandle errorHandle
            )
        {
            int rc = TracedNativeMethods.OCIAttrSet(
                this,                   // trgthndlp/trghndltyp
                value,                  // attributep
                0,                      // size
                attribute,              // attrtype
                errorHandle             // errhp
                );

            if (0 != rc)
            {
                OracleException.Check(errorHandle, rc);
            }

            GC.KeepAlive(this);
        }
示例#27
0
        internal OciHandle GetRowid(
            OciHandle environmentHandle,
            OciHandle errorHandle
            )
        {
            OciHandle rowidHandle = new OciRowidDescriptor(environmentHandle);

            int zero = 0;
            int rc   = TracedNativeMethods.OCIAttrGet(this, rowidHandle, out zero, OCI.ATTR.OCI_ATTR_ROWID, errorHandle);

            if ((int)OCI.RETURNCODE.OCI_NO_DATA == rc)
            {
                SafeDispose(ref rowidHandle);
            }
            else if (0 != rc)
            {
                OracleException.Check(errorHandle, rc);
            }

            GC.KeepAlive(this);
            return(rowidHandle);
        }
        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);
        }