void DefineLob(int position, OciDataType type, OracleConnection connection)
        {
            ociType = type;

            if (ociType == OciDataType.Clob)
            {
                fieldType = typeof(System.String);
            }
            else if (ociType == OciDataType.Blob)
            {
                fieldType = typeof(byte[]);
            }

            int status = 0;

            definedSize = -1;

            lobLocator = (OciLobLocator)connection.Environment.Allocate(OciHandleType.LobLocator);

            if (lobLocator == null)
            {
                OciErrorInfo info = connection.ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            value = lobLocator.Handle;
            lobLocator.ErrorHandle = connection.ErrorHandle;
            lobLocator.Service     = connection.ServiceContext;
            lobLocator.Environment = connection.Environment;

            status = OciCalls.OCIDefineByPosPtr(Parent,
                                                out handle,
                                                ErrorHandle,
                                                position + 1,
                                                ref value,
                                                definedSize,
                                                ociType,
                                                indicator,
                                                rlenp,
                                                IntPtr.Zero,
                                                0);

            definedSize = Int32.MaxValue;

            if (status != 0)
            {
                OciErrorInfo info = connection.ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Exemple #2
0
        public OciTransactionHandle CreateTransaction()
        {
            OciTransactionHandle transaction = (OciTransactionHandle)environment.Allocate(OciHandleType.Transaction);

            if (transaction == null)
            {
                OciErrorInfo info = environment.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
            transaction.ErrorHandle = error;
            transaction.Service     = service;

            return(transaction);
        }
Exemple #3
0
        public OciStatementHandle CreateStatement()
        {
            OciStatementHandle statement = (OciStatementHandle)environment.Allocate(OciHandleType.Statement);

            if (statement == null)
            {
                OciErrorInfo info = environment.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
            statement.ErrorHandle = error;
            statement.Service     = service;

            return(statement);
        }
Exemple #4
0
        public void Trim(uint newlen)
        {
            int status = 0;

            status = OciCalls.OCILobTrim(Service,
                                         ErrorHandle,
                                         this,
                                         newlen);

            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Exemple #5
0
        public void BeginBatch(OracleLobOpenMode mode)
        {
            int status = 0;

            status = OciCalls.OCILobOpen(Service,
                                         ErrorHandle,
                                         Handle,
                                         (byte)mode);

            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
        public bool Attach(string tnsname, OciErrorHandle error)
        {
            errorHandle = error;

            int status = OciCalls.OCIServerAttach(this, error, tnsname, tnsname.Length, 0);

            if (status != 0)
            {
                OciErrorInfo info = errorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            attached = true;
            return(attached);
        }
Exemple #7
0
        void DefineInterval(int position, OciDataType type, OracleConnection connection)
        {
            ociType     = type;
            fieldType   = typeof(string);
            definedSize = -1;

            switch (type)
            {
            case OciDataType.IntervalDayToSecond:
                definedSize  = 11;
                intervalDesc = (OciIntervalDescriptor)connection.Environment.Allocate(OciHandleType.IntervalDayToSecond);
                break;

            case OciDataType.IntervalYearToMonth:
                intervalDesc = (OciIntervalDescriptor)connection.Environment.Allocate(OciHandleType.IntervalYearToMonth);
                definedSize  = 5;
                break;
            }

            if (intervalDesc == null)
            {
                OciErrorInfo info = connection.ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            value = intervalDesc.Handle;
            intervalDesc.ErrorHandle = ErrorHandle;

            int status = 0;

            status = OciCalls.OCIDefineByPosPtr(Parent,
                                                out handle,
                                                ErrorHandle,
                                                position + 1,
                                                ref value,
                                                definedSize,
                                                ociType,
                                                indicator,
                                                rlenp,
                                                IntPtr.Zero,
                                                0);

            if (status != 0)
            {
                OciErrorInfo info = connection.ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Exemple #8
0
        public void DetachFromServiceContext()
        {
            int status = 0;

            status = OciCalls.OCIAttrSet(Service,
                                         OciHandleType.Service,
                                         IntPtr.Zero,
                                         0,
                                         OciAttributeType.Transaction,
                                         ErrorHandle);
            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Exemple #9
0
        public void Begin()
        {
            int status = 0;

            AttachToServiceContext();

            status = OciCalls.OCITransStart(Service,
                                            ErrorHandle,
                                            60,
                                            OciTransactionFlags.New);

            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Exemple #10
0
        internal void SetAttributeString(string attribute, OciAttributeType attrType, OciErrorHandle errorHandle)
        {
            int status = 0;

            status = OciCalls.OCIAttrSetString(Handle,
                                               HandleType,
                                               attribute,
                                               (uint)attribute.Length,
                                               attrType,
                                               errorHandle);

            if (status != 0)
            {
                OciErrorInfo info = errorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Exemple #11
0
        public void Rollback()
        {
            try {
                int status = 0;
                AttachToServiceContext();
                status = OciCalls.OCITransRollback(Service, ErrorHandle, 0);

                if (status != 0)
                {
                    OciErrorInfo info = ErrorHandle.HandleError();
                    throw new OracleException(info.ErrorCode, info.ErrorMessage);
                }
            }
            finally {
                DetachFromServiceContext();
            }
        }
        public void Detach(OciErrorHandle error)
        {
            if (!attached)
            {
                return;
            }

            int status = OciCalls.OCIServerDetach(this, error, 0);

            if (status != 0)
            {
                OciErrorInfo info = errorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            attached = false;
        }
Exemple #13
0
        public int GetChunkSize()
        {
            int  status = 0;
            uint output;

            status = OciCalls.OCILobGetChunkSize(Service,
                                                 ErrorHandle,
                                                 this,
                                                 out output);

            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            return((int)output);
        }
Exemple #14
0
        public uint Erase(uint offset, uint amount)
        {
            int  status = 0;
            uint output = amount;

            status = OciCalls.OCILobErase(Service,
                                          ErrorHandle,
                                          this,
                                          ref output,
                                          (uint)offset);

            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            return(output);
        }
Exemple #15
0
        public bool Fetch()
        {
            int status = 0;

            if (this.disposed)
            {
                throw new InvalidOperationException("StatementHandle is already disposed.");
            }

            status = OciCalls.OCIStmtFetch(Handle,
                                           ErrorHandle.Handle,
                                           1,
                                           2,
                                           0);

            switch (status)
            {
            case OciGlue.OCI_NO_DATA:
                moreResults = false;
                foreach (IntPtr h in parm)
                {
                    OciCalls.OCIDescriptorFree(h, OciHandleType.Parameter);
                }
                break;

            case OciGlue.OCI_DEFAULT:
                moreResults = true;
                break;

            case OciGlue.OCI_SUCCESS_WITH_INFO:
                //OciErrorInfo ei = ErrorHandle.HandleError ();
                //command.Connection.CreateInfoMessage (ei);
                moreResults = true;
                break;

            default:
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            return(moreResults);
        }
Exemple #16
0
        public int Read(byte[] buffer, uint offset, uint count, bool binary)
        {
            int  status = 0;
            uint amount = count;
            byte csfrm  = 0;

            // Character types are UTF-16, so amount of characters is 1/2
            // the amount of bytes
            if (!binary)
            {
                amount /= 2;
                status  = OciCalls.OCILobCharSetForm(environment,
                                                     ErrorHandle,
                                                     this,
                                                     out csfrm);
                if (status != 0)
                {
                    OciErrorInfo info = ErrorHandle.HandleError();
                    throw new OracleException(info.ErrorCode, info.ErrorMessage);
                }
            }

            status = OciCalls.OCILobRead(Service,
                                         ErrorHandle,
                                         this,
                                         ref amount,
                                         offset,
                                         buffer,
                                         count,
                                         IntPtr.Zero,
                                         IntPtr.Zero,
                                         1000, // OCI_UCS2ID
                                         csfrm);

            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            return((int)amount);
        }
Exemple #17
0
        internal IntPtr GetAttributeIntPtr(OciAttributeType attrType, OciErrorHandle errorHandle)
        {
            int    status = 0;
            IntPtr output = IntPtr.Zero;

            status = OciCalls.OCIAttrGetIntPtr(Handle,
                                               HandleType,
                                               out output,
                                               IntPtr.Zero,
                                               attrType,
                                               errorHandle);

            if (status != 0)
            {
                OciErrorInfo info = errorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            return(output);
        }
Exemple #18
0
        void DefineLongVarChar(int position, OracleConnection connection)
        {
            fieldType = typeof(System.String);

            // LONG VARCHAR max length is 2 to the 31 power - 5
            // the first 4 bytes of a LONG VARCHAR value contains the length
            // Int32.MaxValue - 5 causes out of memory in mono on win32
            // because I do not have 2GB of memory available
            // so Int16.MaxValue - 5 is used instead.
            // LAMESPEC for Oracle OCI - you can not get the length of the LONG VARCHAR value
            // until after you get the value.  This could be why Oracle deprecated LONG VARCHAR.
            // If you specify a definedSize less then the length of the column value,
            // then you will get an OCI_ERROR ORA-01406: fetched column value was truncated

            // TODO: get via piece-wise - a chunk at a time
            definedSize = LongVarCharMaxValue;

            value   = OciCalls.AllocateClear(definedSize);
            ociType = OciDataType.LongVarChar;

            int status = 0;

            status = OciCalls.OCIDefineByPos(Parent,
                                             out handle,
                                             ErrorHandle,
                                             position + 1,
                                             value,
                                             definedSize,
                                             ociType,
                                             indicator,
                                             rlenp,
                                             IntPtr.Zero, 0);

            Size = (short)definedSize;

            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Exemple #19
0
        public void Prepare(string commandText)
        {
            int status = 0;

            if (this.disposed)
            {
                throw new InvalidOperationException("StatementHandle is already disposed.");
            }

            ulong rsize = 0;

            byte [] buffer;

            UIntPtr rsizep = new UIntPtr(rsize);

            // Get size of buffer
            OciCalls.OCIUnicodeToCharSet(Parent, null, commandText, ref rsizep);
            rsize = rsizep.ToUInt64();

            //rsize = Encoding.UTF8.GetMaxByteCount (commandText.Length+1);

            // Fill buffer
            buffer = new byte[rsize];

            OciCalls.OCIUnicodeToCharSet(Parent, buffer, commandText, ref rsizep);

            // Execute statement
            status = OciCalls.OCIStmtPrepare(this,
                                             ErrorHandle,
                                             buffer,
                                             buffer.Length,
                                             OciStatementLanguage.NTV,
                                             OciStatementMode.Default);

            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Exemple #20
0
        public OciParameterDescriptor GetParameter(int position)
        {
            IntPtr handle = IntPtr.Zero;
            int    status = 0;

            status = OciCalls.OCIParamGet(this,
                                          OciHandleType.Statement,
                                          ErrorHandle,
                                          out handle,
                                          position + 1);

            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            OciParameterDescriptor output = new OciParameterDescriptor(this, handle);

            output.ErrorHandle = ErrorHandle;
            return(output);
        }
Exemple #21
0
        public long GetLength(bool binary)
        {
            int  status = 0;
            uint output;

            status = OciCalls.OCILobGetLength(Service,
                                              ErrorHandle,
                                              this,
                                              out output);
            if (status != 0)
            {
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            if (!binary)
            {
                output *= 2;
            }

            return((long)output);
        }
Exemple #22
0
        void DefineTimeStamp(int position, OracleConnection connection)
        {
            definedSize = -1;
            ociType     = OciDataType.TimeStamp;
            fieldType   = typeof(System.DateTime);

            dateTimeDesc = (OciDateTimeDescriptor)connection.Environment.Allocate(OciHandleType.TimeStamp);
            if (dateTimeDesc == null)
            {
                OciErrorInfo info = connection.ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            value = dateTimeDesc.Handle;
            dateTimeDesc.ErrorHandle = ErrorHandle;

            int status = 0;

            status = OciCalls.OCIDefineByPosPtr(Parent,
                                                out handle,
                                                ErrorHandle,
                                                position + 1,
                                                ref value,
                                                definedSize,
                                                ociType,
                                                indicator,
                                                rlenp,
                                                IntPtr.Zero,
                                                0);

            definedSize = 11;

            if (status != 0)
            {
                OciErrorInfo info = connection.ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Exemple #23
0
        public void CreateConnection(OracleConnectionInfo conInfo)
        {
            environment = new OciEnvironmentHandle(OciEnvironmentMode.Threaded | OciEnvironmentMode.NoUserCallback);

            if (environment.Handle == IntPtr.Zero)
            {
                throw new OracleException(0, "Could not allocate the Oracle environment.");
            }

            service = (OciServiceHandle)environment.Allocate(OciHandleType.Service);
            if (service == null)
            {
                OciErrorInfo info = environment.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            error = (OciErrorHandle)environment.Allocate(OciHandleType.Error);
            if (error == null)
            {
                OciErrorInfo info = environment.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
            service.ErrorHandle = error;

            server = (OciServerHandle)environment.Allocate(OciHandleType.Server);
            if (server == null)
            {
                OciErrorInfo info = environment.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            session = (OciSessionHandle)environment.Allocate(OciHandleType.Session);
            if (session == null)
            {
                OciErrorInfo info = environment.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
            session.Username = conInfo.Username;
            session.Password = conInfo.Password;
            session.Service  = service;

            if (!server.Attach(conInfo.Database, ErrorHandle))
            {
                OciErrorInfo info = error.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            if (!service.SetServer(server))
            {
                OciErrorInfo info = error.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            if (!session.BeginSession(conInfo.CredentialType, OciSessionMode.Default, ErrorHandle))
            {
                OciErrorInfo info = error.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            if (!service.SetSession(session))
            {
                OciErrorInfo info = error.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            connected = true;
        }
Exemple #24
0
		internal void CreateInfoMessage (OciErrorInfo info)
		{
			OracleInfoMessageEventArgs a = new OracleInfoMessageEventArgs (info);
			OnInfoMessage (a);
		}
        public void CreateConnection(OracleConnectionInfo conInfo)
        {
            environment = new OciEnvironmentHandle(OciEnvironmentMode.Threaded | OciEnvironmentMode.NoUserCallback);

            if (environment.Handle == IntPtr.Zero)
            {
                throw new OracleException(0, "Could not allocate the Oracle environment.");
            }

            service = (OciServiceHandle)environment.Allocate(OciHandleType.Service);
            if (service == null)
            {
                OciErrorInfo info = environment.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            error = (OciErrorHandle)environment.Allocate(OciHandleType.Error);
            if (error == null)
            {
                OciErrorInfo info = environment.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
            service.ErrorHandle = error;

            server = (OciServerHandle)environment.Allocate(OciHandleType.Server);
            if (server == null)
            {
                OciErrorInfo info = environment.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            session = (OciSessionHandle)environment.Allocate(OciHandleType.Session);
            if (session == null)
            {
                OciErrorInfo info = environment.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
            session.Username = conInfo.Username;
            session.Password = conInfo.Password;
            session.Service  = service;

            if (!server.Attach(conInfo.Database, ErrorHandle))
            {
                OciErrorInfo info = error.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            if (!service.SetServer(server))
            {
                OciErrorInfo info = error.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

#if ORACLE_DATA_ACCESS
            if (conInfo.SetNewPassword == true)
            {
                // open with new password
                if (!service.SetSession(session))
                {
                    OciErrorInfo info = error.HandleError();
                    Disconnect();
                    throw new OracleException(info.ErrorCode, info.ErrorMessage);
                }
                if (!service.ChangePassword(conInfo.NewPassword, error))
                {
                    OciErrorInfo info = error.HandleError();
                    Disconnect();
                    throw new OracleException(info.ErrorCode, info.ErrorMessage);
                }
                conInfo.Password       = conInfo.NewPassword;
                conInfo.SetNewPassword = false;
                conInfo.NewPassword    = string.Empty;
            }
            else
            {
#endif
            // open normally
            if (!session.BeginSession(conInfo.CredentialType, OciSessionMode.Default, ErrorHandle))
            {
                OciErrorInfo info = error.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }

            if (!service.SetSession(session))
            {
                OciErrorInfo info = error.HandleError();
                Disconnect();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
#if ORACLE_DATA_ACCESS
        }
#endif
            connected = true;
        }
Exemple #26
0
        public bool Execute(bool nonQuery, bool useAutoCommit, bool schemaOnly)
        {
            int status = 0;

            columnCount = 0;
            moreResults = false;
            int executeMode;

            if (useAutoCommit)
            {
                executeMode = (int)OciExecuteMode.CommitOnSuccess;
            }
            else
            {
                if (schemaOnly)
                {
                    executeMode = (int)OciExecuteMode.DescribeOnly;
                }
                else
                {
                    executeMode = (int)OciExecuteMode.Default;
                }
            }

            if (this.disposed)
            {
                throw new InvalidOperationException("StatementHandle is already disposed.");
            }

            status = OciCalls.OCIStmtExecute(Service,
                                             Handle,
                                             ErrorHandle,
                                             nonQuery,
                                             0,
                                             IntPtr.Zero,
                                             IntPtr.Zero,
                                             (OciExecuteMode)executeMode);

            switch (status)
            {
            case OciGlue.OCI_DEFAULT:
                if (!nonQuery)
                {
                    GetColumnCount();
                    Define();
                    moreResults = true;
                }
                break;

            case OciGlue.OCI_NO_DATA:
                break;

            case OciGlue.OCI_INVALID_HANDLE:
                throw new OracleException(0, "Invalid handle.");

            default:
                OciErrorInfo info = ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
            return(true);
        }
        public OciErrorInfo HandleError()
        {
            OciErrorInfo info = OciErrorHandle.HandleError(this);

            return(info);
        }
		internal OracleInfoMessageEventArgs (OciErrorInfo info)
		{
			code = info.ErrorCode;
			message = info.ErrorMessage;
		}