Exemplo n.º 1
0
        static void Initialize()
        {
            lock (locked)
            {
                if (!isInitialized)
                {
                    bool     unicode = false;
                    IntPtr   envhp;
                    OCI.MODE environmentMode = (OCI.MODE.OCI_THREADED | OCI.MODE.OCI_OBJECT);                                   // NOTE: cannot be NO_MUTEX because we might be multi-threaded.

                    //1 TODO: we only use this environment handle in the OracleNumber class,
                    //1 which doesn't have logic to determine whether we need Unicode or not;
                    //1 we should modify OracleNumber to have that logic, but it's only for
                    //1 consistency -- nothing will break

                #if NEVER
                    if (OCI.ClientVersionAtLeastOracle9i)
                    {
                        unicode          = true;
                        environmentMode |= OCI.MODE.OCI_UTF16;
                    }
                #endif //0
                    int rc = TracedNativeMethods.OCIEnvCreate(
                        out envhp,                                                      // envhpp
                        environmentMode,                                        // mode
                        ADP.NullHandleRef,                                      // ctxp
                        ADP.NullHandleRef,                                      // malocfp
                        ADP.NullHandleRef,                                      // ralocfp
                        ADP.NullHandleRef,                                      // mfreefp
                        0,                                                      // xtramemsz
                        ADP.NullHandleRef                                       // usrmempp
                        );

                    if (rc != 0 || envhp == IntPtr.Zero)
                    {
                        throw ADP.OperationFailed("OCIEnvCreate", rc);
                    }

                    environmentHandle    = new OciEnvironmentHandle(envhp, unicode);
                    availableErrorHandle = new OciErrorHandle(environmentHandle);
                    isInitialized        = true;
                }
            }
        }
        protected OciHandle(OciHandle parentHandle, OCI.HTYPE handleType, OCI.MODE ocimode, HANDLEFLAG handleflags) : this()
        {
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                int num;
                this._handleType   = handleType;
                this._parentHandle = parentHandle;
                this._refCount     = 1;
                switch (handleType)
                {
                case OCI.HTYPE.OCI_DTYPE_TIMESTAMP:
                case OCI.HTYPE.OCI_DTYPE_TIMESTAMP_TZ:
                case OCI.HTYPE.OCI_DTYPE_TIMESTAMP_LTZ:
                case OCI.HTYPE.OCI_DTYPE_INTERVAL_DS:
                case OCI.HTYPE.OCI_DTYPE_FIRST:
                case OCI.HTYPE.OCI_DTYPE_ROWID:
                case OCI.HTYPE.OCI_DTYPE_FILE:
                    num = TracedNativeMethods.OCIDescriptorAlloc(parentHandle.EnvironmentHandle, out this.handle, handleType);
                    if ((num != 0) || (IntPtr.Zero == base.handle))
                    {
                        throw System.Data.Common.ADP.OperationFailed("OCIDescriptorAlloc", num);
                    }
                    break;

                case OCI.HTYPE.OCI_HTYPE_ENV:
                    if ((handleflags & HANDLEFLAG.NLS) != HANDLEFLAG.NLS)
                    {
                        num = TracedNativeMethods.OCIEnvCreate(out this.handle, ocimode);
                        if ((num != 0) || (IntPtr.Zero == base.handle))
                        {
                            throw System.Data.Common.ADP.OperationFailed("OCIEnvCreate", num);
                        }
                    }
                    else
                    {
                        num = TracedNativeMethods.OCIEnvNlsCreate(out this.handle, ocimode, 0, 0);
                        if ((num != 0) || (IntPtr.Zero == base.handle))
                        {
                            throw System.Data.Common.ADP.OperationFailed("OCIEnvNlsCreate", num);
                        }
                    }
                    break;

                case OCI.HTYPE.OCI_HTYPE_ERROR:
                case OCI.HTYPE.OCI_HTYPE_SVCCTX:
                case OCI.HTYPE.OCI_HTYPE_STMT:
                case OCI.HTYPE.OCI_HTYPE_SERVER:
                case OCI.HTYPE.OCI_HTYPE_SESSION:
                    num = TracedNativeMethods.OCIHandleAlloc(parentHandle.EnvironmentHandle, out this.handle, handleType);
                    if ((num != 0) || (IntPtr.Zero == base.handle))
                    {
                        throw System.Data.Common.ADP.OperationFailed("OCIHandleAlloc", num);
                    }
                    break;
                }
                if (parentHandle != null)
                {
                    parentHandle.AddRef();
                    this._isUnicode = parentHandle.IsUnicode;
                }
                else
                {
                    this._isUnicode = (handleflags & HANDLEFLAG.UNICODE) == HANDLEFLAG.UNICODE;
                }
            }
        }