Beispiel #1
0
 internal static extern int OCIBindByNameRef(IntPtr stmtp,
     out IntPtr bindpp,
     IntPtr errhp,
     string placeholder,
     int placeh_len,
     ref IntPtr valuep,
     int value_sz,
     [MarshalAs (UnmanagedType.U2)] OciDataType dty,
     IntPtr indp,
     IntPtr alenp,
     IntPtr rcodep,
     uint maxarr_len,
     IntPtr curelp,
     uint mode);
		public void DefineByPosition (int position)
		{
			OciParameterDescriptor parameter = ((OciStatementHandle) Parent).GetParameter (position);
			
			name = parameter.GetName ();
			definedType = parameter.GetDataType ();
			definedSize = parameter.GetDataSize ();
			precision = parameter.GetPrecision ();
			scale = parameter.GetScale ();

			Define (position);

			parameter.Dispose ();
		}
		internal OracleLob (OciLobLocator locator, OciDataType ociType)
		{
			notNull = true;
			this.locator = locator;

			switch (ociType) {
			case OciDataType.Blob:
				type = OracleType.Blob;
				break;
			case OciDataType.Clob:
				type = OracleType.Clob;
				break;
			}
		}
Beispiel #4
0
		internal void DefineByPosition (int position, OracleConnection connection)
		{
			OciParameterDescriptor parameter = ((OciStatementHandle) Parent).GetParameter (position);

			//name = parameter.GetName ();
			definedType = parameter.GetDataType ();
			definedSize = parameter.GetDataSize ();
			//precision = parameter.GetPrecision ();
			scale = parameter.GetScale ();

			Define (position, connection);

			parameter.Dispose ();
		}
        internal void DefineByPosition(int position, OracleConnection connection)
        {
            OciParameterDescriptor parameter = ((OciStatementHandle)Parent).GetParameter(position);

            //name = parameter.GetName ();
            definedType = parameter.GetDataType();
            definedSize = parameter.GetDataSize();
            //precision = parameter.GetPrecision ();
            scale = parameter.GetScale();

            Define(position, connection);

            parameter.Dispose();
        }
        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,
                                                ref indicator,
                                                ref rlenp,
                                                IntPtr.Zero,
                                                0);

            definedSize = Int32.MaxValue;

            if (status != 0)
            {
                OciErrorInfo info = connection.ErrorHandle.HandleError();
                throw new OracleException(info.ErrorCode, info.ErrorMessage);
            }
        }
Beispiel #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);
            }
        }
Beispiel #8
0
        internal OracleLob(OciLobLocator locator, OciDataType ociType)
        {
            notNull      = true;
            this.locator = locator;

            switch (ociType)
            {
            case OciDataType.Blob:
                type = OracleType.Blob;
                break;

            case OciDataType.Clob:
                type = OracleType.Clob;
                break;
            }
        }
Beispiel #9
0
		internal void DefineByPosition (int position, OracleConnection connection)
		{
			OciParameterDescriptor parameter = ((OciStatementHandle) Parent).GetParameter (position);

			name = parameter.GetName ();
			definedType = parameter.GetDataType ();
			definedSize = parameter.GetDataSize ();
			//precision = parameter.GetPrecision ();
			scale = parameter.GetScale ();
			rlenp = OciCalls.AllocateClear (sizeof(short));
			indicator = OciCalls.AllocateClear (sizeof(short));

			Define (position, connection);

			parameter.Dispose ();
		}
Beispiel #10
0
        internal void DefineByPosition(int position, OracleConnection connection)
        {
            OciParameterDescriptor parameter = ((OciStatementHandle)Parent).GetParameter(position);

            name        = parameter.GetName();
            definedType = parameter.GetDataType();
            definedSize = parameter.GetDataSize();
            //precision = parameter.GetPrecision ();
            scale     = parameter.GetScale();
            rlenp     = OciCalls.AllocateClear(sizeof(short));
            indicator = OciCalls.AllocateClear(sizeof(short));

            Define(position, connection);

            parameter.Dispose();
        }
		// constructor for cloning the object
		internal OracleParameter (OracleParameter value) {
			this.name = value.name;
			this.oracleType = value.oracleType;
			this.ociType = value.ociType;
			this.size = value.size;
			this.direction = value.direction;
			this.isNullable = value.isNullable;
			this.precision = value.precision;
			this.scale = value.scale;
			this.srcColumn = value.srcColumn;
			this.srcVersion = value.srcVersion;
			this.dbType = value.dbType;
			this.offset = value.offset;
			this.sizeSet = value.sizeSet;
			this.value = value.value;
			this.lobLocator = value.lobLocator;
		}
Beispiel #12
0
 internal static int OCIDefineByPosPtr(IntPtr stmtp,
     out IntPtr defnpp,
     IntPtr errhp,
     int position,
     ref IntPtr valuep,
     int value_sz,
     OciDataType dty,
     IntPtr indp,
     IntPtr rlenp,
     IntPtr rcodep,
     uint mode)
 {
     #if TRACE
     Trace.WriteLineIf(traceOci, "OCIDefineByPosPtr", "OCI");
     #endif
     return OciNativeCalls.OCIDefineByPosPtr (stmtp, out defnpp, errhp, position, ref valuep,
         value_sz, dty, indp, rlenp, rcodep, mode);
 }
Beispiel #13
0
        internal static int OCIDefineByPos(IntPtr stmtp,
                                           out IntPtr defnpp,
                                           IntPtr errhp,
                                           int position,
                                           IntPtr valuep,
                                           int value_sz,
                                           [MarshalAs(UnmanagedType.U4)] OciDataType dty,
                                           IntPtr indp,
                                           IntPtr rlenp,
                                           IntPtr rcodep,
                                           uint mode)
        {
#if TRACE
            Trace.WriteLineIf(traceOci, "OCIDefineByPos", OCI_DLL);
#endif
            return(OciNativeCalls.OCIDefineByPos(stmtp, out defnpp, errhp, position, valuep,
                                                 value_sz, dty, indp, rlenp, rcodep, mode));
        }
Beispiel #14
0
 internal static int OCIBindByPosRef(IntPtr stmtp,
     out IntPtr bindpp,
     IntPtr errhp,
     uint position,
     ref IntPtr valuep,
     int value_sz,
     [MarshalAs (UnmanagedType.U2)] OciDataType dty,
     IntPtr indp,
     IntPtr alenp,
     IntPtr rcodep,
     uint maxarr_len,
     IntPtr curelp,
     uint mode)
 {
     #if TRACE
     Trace.WriteLineIf(traceOci, "OCIBindByPos", "OCI");
     #endif
     return OciNativeCalls.OCIBindByPosRef (stmtp, out bindpp, errhp, position, ref valuep,
         value_sz, dty, indp, alenp, rcodep, maxarr_len, curelp, mode);
 }
Beispiel #15
0
		// constructor for cloning the object
		private OracleParameter (OracleParameter value)
		{
			this.name = value.name;
			this.oracleType = value.oracleType;
			this.ociType = value.ociType;
			this.size = value.size;
			this.direction = value.direction;
			this.isNullable = value.isNullable;
			this.precision = value.precision;
			this.scale = value.scale;
			this.srcColumn = value.srcColumn;
			this.srcVersion = value.srcVersion;
			this.dbType = value.dbType;
			this.offset = value.offset;
			this.sizeSet = value.sizeSet;
			this.value = value.value;
			this.lobLocator = value.lobLocator;
			this.oracleTypeSet = value.oracleTypeSet;
			this.indicator = OciCalls.AllocateClear (sizeof(short));
		}
Beispiel #16
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);
            }
        }
Beispiel #17
0
 internal static int OCIBindByNameBytes(IntPtr stmtp,
     out IntPtr bindpp,
     IntPtr errhp,
     string placeholder,
     int placeh_len,
     byte[] valuep,
     int value_sz,
     [MarshalAs (UnmanagedType.U2)] OciDataType dty,
     IntPtr indp,
     IntPtr alenp,
     IntPtr rcodep,
     uint maxarr_len,
     IntPtr curelp,
     uint mode)
 {
     #if TRACE
     Trace.WriteLineIf(traceOci, "OCIBindByName", "OCI");
     #endif
     return OciNativeCalls.OCIBindByNameBytes (stmtp, out bindpp, errhp, placeholder, placeh_len, valuep,
         value_sz, dty, indp, alenp, rcodep, maxarr_len, curelp, mode);
 }
Beispiel #18
0
 internal static int OCIBindByNameRef(IntPtr stmtp,
     out IntPtr bindpp,
     IntPtr errhp,
     string placeholder,
     int placeh_len,
     ref IntPtr valuep,
     int value_sz,
     OciDataType dty,
     IntPtr indp,
     IntPtr alenp,
     IntPtr rcodep,
     uint maxarr_len,
     IntPtr curelp,
     uint mode)
 {
     #if TRACE
     Trace.WriteLineIf(traceOci, "OCIBindByName", "OCI");
     #endif
     return OciNativeCalls.OCIBindByNameRef (stmtp, out bindpp, errhp, placeholder, placeh_len, ref valuep,
         value_sz, dty, indp, alenp, rcodep, maxarr_len, curelp, mode);
 }
Beispiel #19
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);
            }
        }
Beispiel #20
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,
				ref indicator,
				ref rlenp,
				IntPtr.Zero,
				0);

			if (status != 0) {
				OciErrorInfo info = connection.ErrorHandle.HandleError ();
				throw new OracleException (info.ErrorCode, info.ErrorMessage);
			}
		}
Beispiel #21
0
		void DefineLongVarRaw (int position, OracleConnection connection)
		{
			ociType = OciDataType.LongVarRaw;
			fieldType = typeof (byte[]);

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

			value = OciCalls.AllocateClear (definedSize);

			int status = 0;

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

			if (status != 0) {
				OciErrorInfo info = ErrorHandle.HandleError ();
				throw new OracleException (info.ErrorCode, info.ErrorMessage);
			}
		}
Beispiel #22
0
		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,
							ref indicator,
							ref rlenp,
							IntPtr.Zero,
							0);

			definedSize = Int32.MaxValue;

			if (status != 0) {
				OciErrorInfo info = connection.ErrorHandle.HandleError ();
				throw new OracleException (info.ErrorCode, info.ErrorMessage);
			}
		}
Beispiel #23
0
		private void SetDbType (DbType type)
		{
			string exception = String.Format ("No mapping exists from DbType {0} to a known OracleType.", type);
			switch (type) {
			case DbType.AnsiString:
				oracleType = OracleType.VarChar;
				ociType = OciDataType.VarChar;
				break;
			case DbType.AnsiStringFixedLength:
				oracleType = OracleType.Char;
				ociType = OciDataType.Char;
				break;
			case DbType.Binary:
			case DbType.Guid:
				oracleType = OracleType.Raw;
				ociType = OciDataType.Raw;
				break;
			case DbType.Boolean:
			case DbType.Byte:
				oracleType = OracleType.Byte;
				ociType = OciDataType.Integer;
				break;
			case DbType.Currency:
			case DbType.Decimal:
			case DbType.Int64:
				oracleType = OracleType.Number;
				ociType = OciDataType.Number;
				break;
			case DbType.Date:
			case DbType.DateTime:
			case DbType.Time:
				oracleType = OracleType.DateTime;
				ociType = OciDataType.Char;
				break;
			case DbType.Double:
				oracleType = OracleType.Double;
				ociType = OciDataType.Float;
				break;
			case DbType.Int16:
				oracleType = OracleType.Int16;
				ociType = OciDataType.Integer;
				break;
			case DbType.Int32:
				oracleType = OracleType.Int32;
				ociType = OciDataType.Integer;
				break;
			case DbType.Object:
				oracleType = OracleType.Blob;
				ociType = OciDataType.Blob;
				break;
			case DbType.Single:
				oracleType = OracleType.Float;
				ociType = OciDataType.Float;
				break;
			case DbType.String:
				oracleType = OracleType.NVarChar;
				ociType = OciDataType.VarChar;
				break;
			case DbType.StringFixedLength:
				oracleType = OracleType.NChar;
				ociType = OciDataType.Char;																																																																																																																																																																																																																																																														

				break;
			default:
				throw new ArgumentException (exception);
			}
			dbType = type;
		}
Beispiel #24
0
		internal static int OCIDefineByPosPtr (IntPtr stmtp,
			out IntPtr defnpp,
			IntPtr errhp,
			int position,
			ref IntPtr valuep,
			int value_sz,
			OciDataType dty,
			ref short indp,
			ref short rlenp,
			IntPtr rcodep,
			uint mode)
		{
			#if TRACE
			Trace.WriteLineIf(traceOci, "OCIDefineByPosPtr", "OCI");
			#endif
			return OciNativeCalls.OCIDefineByPosPtr (stmtp, out defnpp, errhp, position, ref valuep,
				value_sz, dty, ref indp, ref rlenp, rcodep, mode);
		}
Beispiel #25
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,
				ref indicator,
				ref rlenp,
				IntPtr.Zero,
				0);

			definedSize = 11;

			if (status != 0) {
				OciErrorInfo info = connection.ErrorHandle.HandleError ();
				throw new OracleException (info.ErrorCode, info.ErrorMessage);
			}
		}
Beispiel #26
0
		public static OracleType OciDataTypeToOracleType (OciDataType ociType)
		{
			switch (ociType) {
			case OciDataType.VarChar2:
				return OracleType.VarChar;
			case OciDataType.Number:
				return OracleType.Number;
			case OciDataType.Integer:
				return OracleType.UInt32;
			case OciDataType.Float:
				return OracleType.Float;
			case OciDataType.String:
				return OracleType.VarChar;
			case OciDataType.VarNum:
				return OracleType.Number;
			case OciDataType.Long:
				return OracleType.LongVarChar;
			case OciDataType.VarChar:
				return OracleType.VarChar;
			case OciDataType.RowId:
				return OracleType.RowId;
			case OciDataType.Date:
				return OracleType.DateTime;
			case OciDataType.VarRaw:
				return OracleType.Raw;
			case OciDataType.Raw:
				return OracleType.Raw;
			case OciDataType.LongRaw:
				return OracleType.Raw;
			case OciDataType.UnsignedInt:
				return OracleType.UInt32;
			case OciDataType.LongVarChar:
				return OracleType.LongVarChar;
			case OciDataType.LongVarRaw:
				return OracleType.Raw;
			case OciDataType.Char:
				return OracleType.Char;
			case OciDataType.CharZ:
				return OracleType.Char;
			case OciDataType.RowIdDescriptor:
				return OracleType.RowId;
			//case OciDataType.NamedDataType:
			//	return ???
			//case OciDataType.Ref:
			//	return ???
			case OciDataType.Clob:
				return OracleType.Clob;
			case OciDataType.Blob:
				return OracleType.Blob;
			case OciDataType.BFile:
				return OracleType.BFile;
			case OciDataType.OciString:
				return OracleType.VarChar;
			case OciDataType.OciDate:
				return OracleType.DateTime;
			case OciDataType.TimeStamp:
				return OracleType.Timestamp;
			case OciDataType.IntervalDayToSecond:
				return OracleType.IntervalDayToSecond;
			case OciDataType.IntervalYearToMonth:
				return OracleType.IntervalYearToMonth;
			default:
				throw new NotImplementedException ();
			}
		}
		void DefineRaw (int position)
		{
			ociType = OciDataType.Raw;
			fieldType = Type.GetType("System.Byte[]");

			value = Marshal.AllocHGlobal (definedSize);

			int status = 0;

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

			if (status != 0) {
				OciErrorInfo info = ErrorHandle.HandleError ();
				throw new OracleException (info.ErrorCode, info.ErrorMessage);
			}
		}
		void DefineChar (int position)
		{
			fieldType = typeof (System.String);

			// The buffer is able to contain twice the defined size
			// to allow usage of multibyte characters
			value = Marshal.AllocHGlobal (definedSize * 2);

			ociType = OciDataType.Char;

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

			if (status != 0) {
				OciErrorInfo info = ErrorHandle.HandleError ();
				throw new OracleException (info.ErrorCode, info.ErrorMessage);
			}
		}
Beispiel #29
0
		void DefineRaw (int position, OracleConnection connection)
		{
			ociType = OciDataType.Raw;
			fieldType = typeof (byte[]);

			value = OciCalls.AllocateClear (definedSize);

			int status = 0;

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

			if (status != 0) {
				OciErrorInfo info = ErrorHandle.HandleError ();
				throw new OracleException (info.ErrorCode, info.ErrorMessage);
			}
		}
Beispiel #30
0
		private void SetOracleType (OracleType type, bool inferring)
		{
			Type valType;
			FreeHandle ();

			if (value == null)
				valType = typeof(System.DBNull);
			else
				valType = value.GetType ();

			string exception = String.Format ("No mapping exists from OracleType {0} to a known DbType.", type);
			switch (type) {
			case OracleType.BFile:
			case OracleType.Blob:
				dbType = DbType.Binary;
				ociType = OciDataType.Blob;
				break;
			case OracleType.LongRaw:
			case OracleType.Raw:
				if (valType.FullName == "System.Guid")
					dbType = DbType.Guid;
				else
					dbType = DbType.Binary;
				ociType = OciDataType.Raw;
				break;
			case OracleType.Byte:
				dbType = DbType.Byte;
				ociType = OciDataType.Number;
				break;
			case OracleType.Char:
				dbType = DbType.AnsiString;
				ociType = OciDataType.Char;
				break;
			case OracleType.Clob:
				dbType = DbType.AnsiString;
				ociType = OciDataType.Clob;
				break;
			case OracleType.LongVarChar:
			case OracleType.RowId:
			case OracleType.VarChar:
				dbType = DbType.AnsiString;
				ociType = OciDataType.VarChar;
				break;
			case OracleType.Cursor: // REF CURSOR
				ociType = OciDataType.RSet;
				dbType = DbType.Object;
				break;
			case OracleType.IntervalDayToSecond:
				dbType = DbType.AnsiStringFixedLength;
				ociType = OciDataType.Char;
				break;
			case OracleType.Timestamp:
			case OracleType.TimestampLocal:
			case OracleType.TimestampWithTZ:
				dbType = DbType.DateTime;
				ociType = OciDataType.TimeStamp;
				break;
			case OracleType.DateTime:
				dbType = DbType.DateTime;
				ociType = OciDataType.Date;
				break;
			case OracleType.Double:
				dbType = DbType.Double;
				ociType = OciDataType.Number;
				break;
			case OracleType.Float:
				dbType = DbType.Single;
				ociType = OciDataType.Number;
				break;
			case OracleType.Int16:
				dbType = DbType.Int16;
				ociType = OciDataType.Number;
				break;
			case OracleType.Int32:
			case OracleType.IntervalYearToMonth:
				dbType = DbType.Int32;
				ociType = OciDataType.Number;
				break;
			case OracleType.NChar:
				dbType = DbType.StringFixedLength;
				ociType = OciDataType.Char;
				break;
			case OracleType.NClob:
			case OracleType.NVarChar:
				dbType = DbType.String;
				ociType = OciDataType.Char;
				break;
			case OracleType.Number:
				dbType = DbType.VarNumeric;
				ociType = OciDataType.Number;
				break;
			case OracleType.SByte:
				dbType = DbType.SByte;
				ociType = OciDataType.Number;
				break;
			case OracleType.UInt16:
				dbType = DbType.UInt16;
				ociType = OciDataType.Number;
				break;
			case OracleType.UInt32:
				dbType = DbType.UInt32;
				ociType = OciDataType.Number;
				break;
			default:
				throw new ArgumentException (exception);
			}

			if (!oracleTypeSet || !inferring )
				oracleType = type;
		}
        public static OracleType OciDataTypeToOracleType(OciDataType ociType)
        {
            switch (ociType)
            {
            case OciDataType.VarChar2:
                return(OracleType.VarChar);

            case OciDataType.Number:
                return(OracleType.Number);

            case OciDataType.Integer:
                return(OracleType.UInt32);

            case OciDataType.Float:
                return(OracleType.Float);

            case OciDataType.String:
                return(OracleType.VarChar);

            case OciDataType.VarNum:
                return(OracleType.Number);

            case OciDataType.Long:
                return(OracleType.LongVarChar);

            case OciDataType.VarChar:
                return(OracleType.VarChar);

            case OciDataType.RowId:
                return(OracleType.RowId);

            case OciDataType.Date:
                return(OracleType.DateTime);

            case OciDataType.VarRaw:
                return(OracleType.Raw);

            case OciDataType.Raw:
                return(OracleType.Raw);

            case OciDataType.LongRaw:
                return(OracleType.Raw);

            case OciDataType.UnsignedInt:
                return(OracleType.UInt32);

            case OciDataType.LongVarChar:
                return(OracleType.LongVarChar);

            case OciDataType.LongVarRaw:
                return(OracleType.Raw);

            case OciDataType.Char:
                return(OracleType.Char);

            case OciDataType.CharZ:
                return(OracleType.Char);

            case OciDataType.RowIdDescriptor:
                return(OracleType.RowId);

            //case OciDataType.NamedDataType:
            //	return ???
            //case OciDataType.Ref:
            //	return ???
            case OciDataType.Clob:
                return(OracleType.Clob);

            case OciDataType.Blob:
                return(OracleType.Blob);

            case OciDataType.BFile:
                return(OracleType.BFile);

            case OciDataType.OciString:
                return(OracleType.VarChar);

            case OciDataType.OciDate:
                return(OracleType.DateTime);

            case OciDataType.TimeStamp:
                return(OracleType.Timestamp);

            case OciDataType.IntervalDayToSecond:
                return(OracleType.IntervalDayToSecond);

            case OciDataType.IntervalYearToMonth:
                return(OracleType.IntervalYearToMonth);

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #32
0
		internal static int OCIBindByNameRef (IntPtr stmtp,
			out IntPtr bindpp,
			IntPtr errhp,
			string placeholder,
			int placeh_len,
			ref IntPtr valuep,
			int value_sz,
			OciDataType dty,
			ref short indp,
			IntPtr alenp,
			IntPtr rcodep,
			uint maxarr_len,
			IntPtr curelp,
			uint mode)
		{
			#if TRACE
			Trace.WriteLineIf(traceOci, "OCIBindByName", "OCI");
			#endif
			return OciNativeCalls.OCIBindByNameRef (stmtp, out bindpp, errhp, placeholder, placeh_len, ref valuep,
				value_sz, dty, ref indp, alenp, rcodep, maxarr_len, curelp, mode);
		}
Beispiel #33
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,
				ref indicator,
				ref rlenp,
				IntPtr.Zero, 0);

			rlenp = (short) definedSize;

			if (status != 0) {
				OciErrorInfo info = ErrorHandle.HandleError ();
				throw new OracleException (info.ErrorCode, info.ErrorMessage);
			}
		}
Beispiel #34
0
		void DefineChar (int position, OracleConnection connection)
		{
			fieldType = typeof (System.String);

			int maxByteCount = Encoding.UTF8.GetMaxByteCount (definedSize);
			value = OciCalls.AllocateClear (maxByteCount);

			ociType = OciDataType.Char;

			int status = 0;

			status = OciCalls.OCIDefineByPos (Parent,
						out handle,
						ErrorHandle,
						position + 1,
						value,
						maxByteCount,
						ociType,
						ref indicator,
						ref rlenp,
						IntPtr.Zero,
						0);
			OciErrorHandle.ThrowExceptionIfError (ErrorHandle, status);
		}
Beispiel #35
0
		void DefineNumber (int position, OracleConnection connection)
		{
			fieldType = typeof (System.Decimal);
			value = OciCalls.AllocateClear (definedSize);

			ociType = OciDataType.Char;

			int status = 0;

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

			if (status != 0) {
				OciErrorInfo info = ErrorHandle.HandleError ();
				throw new OracleException (info.ErrorCode, info.ErrorMessage);
			}
		}
Beispiel #36
0
        DataTable GetSchemaTable()
        {
            StringCollection keyinfo = null;

            if (schemaTable.Rows != null && schemaTable.Rows.Count > 0)
            {
                return(schemaTable);
            }

            string owner = String.Empty;
            string table = String.Empty;

            if ((behavior & CommandBehavior.KeyInfo) != 0)
            {
                keyinfo = GetKeyInfo(out owner, out table);
            }

            dataTypeNames = new ArrayList();

            for (int i = 0; i < statement.ColumnCount; i += 1)
            {
                DataRow row = schemaTable.NewRow();

                OciParameterDescriptor parameter = statement.GetParameter(i);

                dataTypeNames.Add(parameter.GetDataTypeName());

                row ["ColumnName"]       = parameter.GetName();
                row ["ColumnOrdinal"]    = i + 1;
                row ["ColumnSize"]       = parameter.GetDataSize();
                row ["NumericPrecision"] = parameter.GetPrecision();
                row ["NumericScale"]     = parameter.GetScale();

                string sDataTypeName = parameter.GetDataTypeName();
                row ["DataType"] = parameter.GetFieldType(sDataTypeName);

                OciDataType ociType = parameter.GetDataType();
                OracleType  oraType = OciParameterDescriptor.OciDataTypeToOracleType(ociType);
                row ["ProviderType"] = (int)oraType;

                if (ociType == OciDataType.Blob || ociType == OciDataType.Clob)
                {
                    row ["IsLong"] = true;
                }
                else
                {
                    row ["IsLong"] = false;
                }

                row ["AllowDBNull"] = parameter.GetIsNull();

                row ["IsAliased"]    = DBNull.Value;                            // TODO:
                row ["IsExpression"] = DBNull.Value;                            // TODO:

                if ((behavior & CommandBehavior.KeyInfo) != 0)
                {
                    if (keyinfo.IndexOf((string)row ["ColumnName"]) >= 0)
                    {
                        row ["IsKey"] = true;
                    }
                    else
                    {
                        row ["IsKey"] = false;
                    }

                    row ["IsUnique"]       = DBNull.Value;                      // TODO: only set this if CommandBehavior.KeyInfo, otherwise, null
                    row ["BaseSchemaName"] = owner;
                    row ["BaseTableName"]  = table;
                    row ["BaseColumnName"] = row ["ColumnName"];
                }
                else
                {
                    row ["IsKey"]          = DBNull.Value;
                    row ["IsUnique"]       = DBNull.Value;
                    row ["BaseSchemaName"] = DBNull.Value;
                    row ["BaseTableName"]  = DBNull.Value;
                    row ["BaseColumnName"] = DBNull.Value;
                }

                schemaTable.Rows.Add(row);
            }

            return(schemaTable);
        }
Beispiel #37
0
		internal void Bind (OciStatementHandle statement, OracleConnection con, uint pos)
		{
			connection = con;

			if (bindHandle == null)
				bindHandle = new OciBindHandle ((OciHandle) statement);

			IntPtr tmpHandle = bindHandle.Handle;

			if (Direction != ParameterDirection.Input)
				AssertSizeIsSet ();
			if (!sizeSet)
				size = InferSize ();

			bindSize = size;
			object v = value;
			int status = 0;
			bindType = ociType;
			int rsize = 0;

			string svalue;
			string sDate;
			DateTime dt;
			bool isnull = false;
			int byteCount;
			byte[] byteArrayLen;

			if (direction == ParameterDirection.Input || direction == ParameterDirection.InputOutput) {
				if (v == null)
					isnull = true;
				else if (v is DBNull)
					isnull = true;
				else {
					INullable mynullable = v as INullable;
					if (mynullable != null)
						isnull = mynullable.IsNull;
				}					
			} 

			if (isnull == true && direction == ParameterDirection.Input) {
				bindType = OciDataType.VarChar2;
				bindSize = 0;
			} else {
				switch(ociType) {
				case OciDataType.VarChar2:
				case OciDataType.String:
				case OciDataType.VarChar:
				case OciDataType.Char:
				case OciDataType.CharZ:
				case OciDataType.OciString:
					bindType = OciDataType.String;
					svalue = "\0";
					// convert value from managed type to type to marshal
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {

						svalue = v.ToString ();

						if (direction == ParameterDirection.Input && size > 0 && svalue.Length > size)
							svalue = svalue.Substring(0, size);

						svalue = svalue.ToString () + '\0';
						
						// convert managed type to memory allocated earlier
						// in this case using OCIUnicodeToCharSet
						rsize = 0;
						// Get size of buffer
						status = OciCalls.OCIUnicodeToCharSet (statement.Parent, null, svalue, out rsize);

						if (direction == ParameterDirection.Input)
							bindSize = rsize;
						else {
							// this cannot be rsize because you need room for the output after the execute
							bindSize = Encoding.UTF8.GetMaxByteCount (Size + 1);
						}

						// allocate memory based on bind size
						bytes = new byte [bindSize];

						// Fill buffer
						status = OciCalls.OCIUnicodeToCharSet (statement.Parent, bytes, svalue, out rsize);
					} else {
						// for Output and ReturnValue parameters, get size in bytes 					
						bindSize = Encoding.UTF8.GetMaxByteCount (size + 1);
						// allocate memory for oracle to place the results for the Return or Output param						
						bytes = new byte [bindSize];
					}
					break;
				case OciDataType.Date:
					bindType = OciDataType.Date;
					bindSize = 7;
					// convert value from managed type to type to marshal
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {

						if (isnull)
							bytes = new byte [7];
						else {
							sDate = "";
							dt = DateTime.MinValue;
							if (v is String) {
								sDate = (string) v;
								dt = DateTime.Parse (sDate);
							}
							else if (v is DateTime)
								dt = (DateTime) v;
							else if (v is OracleString) {
								sDate = v.ToString ();
								dt = DateTime.Parse (sDate);
							}
							else if (v is OracleDateTime) {
								OracleDateTime odt = (OracleDateTime) v;
								dt = (DateTime) odt.Value;
							}
							else
								throw new NotImplementedException ("For OracleType.DateTime, data type not implemented: " + v.GetType().ToString() + ".");

							// for Input and InputOuput, create byte array and pack DateTime into it
							bytes = PackDate (dt);
						}
					} else	{
						// allocate 7-byte array for Output and ReturnValue to put date
						bytes = new byte [7];
					}
					break;
				case OciDataType.TimeStamp:
					dateTimeDesc = (OciDateTimeDescriptor) connection.Environment.Allocate (OciHandleType.TimeStamp);
					if (dateTimeDesc == null) {
						OciErrorInfo info = connection.ErrorHandle.HandleError ();
						throw new OracleException (info.ErrorCode, info.ErrorMessage);
					}
					dateTimeDesc.ErrorHandle = connection.ErrorHandle;
					bindSize = 11;
					bindType = OciDataType.TimeStamp;
					bindOutValue = dateTimeDesc.Handle;
					bindValue = dateTimeDesc.Handle;
					useRef = true;
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {

						dt = DateTime.MinValue;
						sDate = "";
						if (isnull)
							Indicator = -1;
						else if (v is String) {
							sDate = (string) v;
							dt = DateTime.Parse (sDate);
						}
						else if (v is DateTime)
							dt = (DateTime) v;
						else if (v is OracleString) {
							sDate = (string) v;
							dt = DateTime.Parse (sDate);
						}
						else if (v is OracleDateTime) {
							OracleDateTime odt = (OracleDateTime) v;
							dt = (DateTime) odt.Value;
						}
						else
							throw new NotImplementedException ("For OracleType.Timestamp, data type not implemented: " + v.GetType().ToString()); // ?

						short year = (short) dt.Year;
						byte month = (byte) dt.Month;
						byte day = (byte) dt.Day;
						byte hour = (byte) dt.Hour;
						byte min = (byte) dt.Minute;
						byte sec = (byte) dt.Second;
						uint fsec = (uint) dt.Millisecond;
						string timezone = "";
						dateTimeDesc.SetDateTime (connection.Session,
							connection.ErrorHandle,
							year, month, day, hour, min, sec, fsec,
							timezone);
					}
					break;
				case OciDataType.Integer:
				case OciDataType.Float:
				case OciDataType.Number:
					bindType = OciDataType.String;
					Indicator = 0;
					svalue = "\0";
					// convert value from managed type to type to marshal
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {

						svalue = null;
						if(v is IFormattable)
							svalue = ((IFormattable)v).ToString (null, con.SessionFormatProvider);
						else if (v is OracleNumber)
							svalue = ((OracleNumber)v).ToString(con.SessionFormatProvider);
						else
							svalue = v.ToString();

						svalue = svalue + "\0";

						rsize = 0;
						// Get size of buffer
						OciCalls.OCIUnicodeToCharSet (statement.Parent, null, svalue, out rsize);

						// Fill buffer 
						
						if (direction == ParameterDirection.Input)
							bindSize = rsize;
						else
							bindSize = 30; // need room for output possibly being bigger than the input
						
						bytes = new byte [bindSize];
						OciCalls.OCIUnicodeToCharSet (statement.Parent, bytes, svalue, out rsize);
					} else {
						// Output and ReturnValue parameters allocate memory
						bindSize = 30;
						bytes = new byte [bindSize];
					} 
					break;
				case OciDataType.Long:
				case OciDataType.LongVarChar:
					bindType = OciDataType.LongVarChar;

					// FIXME: use piecewise fetching for Long, Clob, Blob, and Long Raw
					// See http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14250/oci05bnd.htm#sthref724
					
					bindSize = Size + 5; // 4 bytes prepended for length, bytes, 1 byte NUL character

					Indicator = 0;
					svalue = "\0";
					// convert value from managed type to type to marshal
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {

						svalue = v.ToString () + '\0';
					}

					bytes = new byte [bindSize];
					// LONG is only ANSI 
					ASCIIEncoding enc = new ASCIIEncoding ();
					
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {
						if (svalue.Length > 0) {	
							byteCount = enc.GetBytes (svalue, 4, svalue.Length, bytes, 0);
							// LONG VARCHAR prepends a 4-byte length
							if (byteCount > 0) {
								byteArrayLen = BitConverter.GetBytes ((uint) byteCount);
								bytes[0] = byteArrayLen[0];
								bytes[1] = byteArrayLen[1];
								bytes[2] = byteArrayLen[2];
								bytes[3] = byteArrayLen[3];
							}
						}
					}
					break;
				case OciDataType.Clob:
					if (direction == ParameterDirection.Input) {
						svalue = v.ToString();
						rsize = 0;

						// Get size of buffer
						OciCalls.OCIUnicodeToCharSet (statement.Parent, null, svalue, out rsize);

						// Fill buffer
						bytes = new byte[rsize];
						OciCalls.OCIUnicodeToCharSet (statement.Parent, bytes, svalue, out rsize);

						bindType = OciDataType.Long;
						bindSize = bytes.Length;
					} 
					else if (direction == ParameterDirection.InputOutput) {
						// not the exact error that .net 2.0 throws, but this is better
						throw new NotImplementedException ("Parameters of OracleType.Clob with direction of InputOutput are not supported.");
					}
					else {
						// Output and Return parameters
						bindSize = -1;
						lobLocator = (OciLobLocator) connection.Environment.Allocate (OciHandleType.LobLocator);
						if (lobLocator == null) {
							OciErrorInfo info = connection.ErrorHandle.HandleError ();
							throw new OracleException (info.ErrorCode, info.ErrorMessage);
						}
						bindOutValue = lobLocator.Handle;
						bindValue = lobLocator.Handle;
						lobLocator.ErrorHandle = connection.ErrorHandle;
						lobLocator.Service = statement.Service;
						lobLocator.Environment = connection.Environment;
						useRef = true;
					}
					break;
				case OciDataType.Blob:
					if (direction == ParameterDirection.Input) {
						if (v is byte[]) {
							bytes = (byte[]) v;
							bindType = OciDataType.LongRaw;
							bindSize = bytes.Length;
						}
						else if (v is OracleLob) {
							OracleLob lob = (OracleLob) v;
							if (lob.LobType == OracleType.Blob) {
								lobLocator = lob.Locator;
								bindOutValue = lobLocator.Handle;
								bindValue = lobLocator.Handle;
								lobLocator.ErrorHandle = connection.ErrorHandle;
								lobLocator.Service = connection.ServiceContext;
								useRef = true;
							}
							else
								throw new NotImplementedException("For OracleType.Blob, data type OracleLob of LobType Clob/NClob is not implemented.");
						}
						else
							throw new NotImplementedException ("For OracleType.Blob, data type not implemented: " + v.GetType().ToString()); // ?
					}
					else if (direction == ParameterDirection.InputOutput) {
						// not the exact error that .net 2.0 throws, but this is better
						throw new NotImplementedException ("Parameters of OracleType.Blob with direction of InputOutput are not supported.");
					}
					else {
						bindSize = -1;
						if (value != null && value is OracleLob) {
							OracleLob blob = (OracleLob) value;
							if (blob.LobType == OracleType.Blob)
								if (value != OracleLob.Null) {
									lobLocator = blob.Locator;
									byte[] bs = (byte[]) blob.Value;
									bindSize = bs.Length;
								}
						}
						if (lobLocator == null) {
							lobLocator = (OciLobLocator) connection.Environment.Allocate (OciHandleType.LobLocator);
							if (lobLocator == null) {
								OciErrorInfo info = connection.ErrorHandle.HandleError ();
								throw new OracleException (info.ErrorCode, info.ErrorMessage);
							}
						}
						bindOutValue = lobLocator.Handle;
						bindValue = lobLocator.Handle;
						lobLocator.ErrorHandle = connection.ErrorHandle;
						lobLocator.Service = connection.ServiceContext;
						lobLocator.Environment = connection.Environment;
						useRef = true;
					}
					break;
				case OciDataType.Raw:
				case OciDataType.VarRaw:
					bindType = OciDataType.VarRaw;
					bindSize = Size + 2; // include 2 bytes prepended to hold the length
					Indicator = 0;
					bytes = new byte [bindSize];
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {
						byteCount = 0;
						byte[] val;
						if (dbType == DbType.Guid)
							val = ((Guid)v).ToByteArray();
						else
							val = v as byte[];
						if (val.Length > 0) {	
							byteCount = val.Length;
							// LONG VARRAW prepends a 4-byte length
							if (byteCount > 0) {
								byteArrayLen = BitConverter.GetBytes ((ushort) byteCount);
								bytes[0] = byteArrayLen[0];
								bytes[1] = byteArrayLen[1];
								Array.ConstrainedCopy (val, 0, bytes, 2, byteCount);
							}
						}
					}
					break;
				case OciDataType.LongRaw:
				case OciDataType.LongVarRaw:
					bindType = OciDataType.LongVarRaw;
					bindSize = Size + 4; // include 4 bytes prepended to hold the length
					Indicator = 0;
					bytes = new byte [bindSize];
					if (direction == ParameterDirection.Input || 
						direction == ParameterDirection.InputOutput) {
						byteCount = 0;
						byte[] val = v as byte[];
						if (val.Length > 0) {	
							byteCount = val.Length;
							// LONG VARRAW prepends a 4-byte length
							if (byteCount > 0) {
								byteArrayLen = BitConverter.GetBytes ((uint) byteCount);
								bytes[0] = byteArrayLen[0];
								bytes[1] = byteArrayLen[1];
								bytes[2] = byteArrayLen[2];
								bytes[3] = byteArrayLen[3];
								Array.ConstrainedCopy (val, 0, bytes, 4, byteCount);
							}
						}
					}
					break;
				case OciDataType.RowIdDescriptor:
					if (direction == ParameterDirection.Output || 
						direction == ParameterDirection.InputOutput || 
						direction == ParameterDirection.ReturnValue) {

					size = 10;
					bindType = OciDataType.Char;
					bindSize = size * 2;
					bindOutValue = OciCalls.AllocateClear (bindSize);
					bindValue = bindOutValue;
					} else
						throw new NotImplementedException("data type RowIdDescriptor as Intput parameters");
					break;
				case OciDataType.RSet: // REF CURSOR
					if (direction == ParameterDirection.Output || 
						direction == ParameterDirection.InputOutput || 
						direction == ParameterDirection.ReturnValue) {
						if (cursor != IntPtr.Zero) {
							OciCalls.OCIHandleFree (cursor,
								OciHandleType.Statement);
							cursor = IntPtr.Zero;
						}
						OciCalls.OCIHandleAlloc (connection.Environment,
							out cursor,
							OciHandleType.Statement,
							0,
							IntPtr.Zero);
							bindSize = 0;
						bindType = OciDataType.RSet;
					} else
						throw new NotImplementedException ("data type Ref Cursor not implemented for Input parameters");
					break;
				default:
					throw new NotImplementedException ("Data Type not implemented: " + ociType.ToString() + ".");
				}			
			}
			
			// Now, call the appropriate OCI Bind function;

			if (useRef == true) {
				if (bindType == OciDataType.TimeStamp) {
					bindValue = dateTimeDesc.Handle;
					status = OciCalls.OCIBindByNameRef (statement,
						out tmpHandle,
						connection.ErrorHandle,
						ParameterName,
						ParameterName.Length,
						ref bindValue,
						bindSize,
						bindType,
						indicator,
						IntPtr.Zero,
						IntPtr.Zero,
						0,
						IntPtr.Zero,
						0);
				}
				else {
					status = OciCalls.OCIBindByNameRef (statement,
						out tmpHandle,
						connection.ErrorHandle,
						ParameterName,
						ParameterName.Length,
						ref bindValue,
						bindSize,
						bindType,
						indicator,
						IntPtr.Zero,
						IntPtr.Zero,
						0,
						IntPtr.Zero,
						0);
				}
			}
			else if (bindType == OciDataType.RSet) {
				status = OciCalls.OCIBindByNameRef (statement,
					out tmpHandle,
					connection.ErrorHandle,
					ParameterName,
					ParameterName.Length,
					ref cursor,
					bindSize,
					bindType,
					indicator,
					IntPtr.Zero,
					IntPtr.Zero,
					0,
					IntPtr.Zero,
					0);
			}
			else if (bytes != null) {
				status = OciCalls.OCIBindByNameBytes (statement,
					out tmpHandle,
					connection.ErrorHandle,
					ParameterName,
					ParameterName.Length,
					bytes,
					bindSize,
					bindType,
					indicator,
					IntPtr.Zero,
					IntPtr.Zero,
					0,
					IntPtr.Zero,
					0);
			}
			else {
				status = OciCalls.OCIBindByName (statement,
					out tmpHandle,
					connection.ErrorHandle,
					ParameterName,
					ParameterName.Length, // FIXME: this should be in bytes!
					bindValue,
					bindSize,
					bindType,
					indicator,
					IntPtr.Zero,
					IntPtr.Zero,
					0,
					IntPtr.Zero,
					0);
			}
			OciErrorHandle.ThrowExceptionIfError (connection.ErrorHandle, status);

			bindHandle.SetHandle (tmpHandle);
		}
		void DefineDate (int position)
		{
			definedSize = 7;
			ociType = OciDataType.Date;
			fieldType = typeof(System.DateTime);

			value = Marshal.AllocHGlobal (definedSize);

			int status = 0;

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

			if (status != 0) {
				OciErrorInfo info = ErrorHandle.HandleError ();
				throw new OracleException (info.ErrorCode, info.ErrorMessage);
			}
		}
		private void SetOracleType (OracleType type)
		{
			string exception = String.Format ("No mapping exists from OracleType {0} to a known DbType.", type);
			switch (type) {
			case OracleType.BFile:
			case OracleType.Blob:
			case OracleType.LongRaw:
			case OracleType.Raw:
				dbType = DbType.Binary;
				ociType = OciDataType.Raw;
				break;
			case OracleType.Byte:
				dbType = DbType.Byte;
				ociType = OciDataType.Integer;
				break;
			case OracleType.Char:
				dbType = DbType.AnsiStringFixedLength;
				ociType = OciDataType.Char;
				break;
			case OracleType.Clob:
			case OracleType.LongVarChar:
			case OracleType.RowId:
			case OracleType.VarChar:
				dbType = DbType.AnsiString;
				ociType = OciDataType.VarChar;
				break;
			case OracleType.Cursor:
			case OracleType.IntervalDayToSecond:
				dbType = DbType.Object;
				ociType = OciDataType.Blob;
				break;
			case OracleType.DateTime:
			case OracleType.Timestamp:
			case OracleType.TimestampLocal:
			case OracleType.TimestampWithTZ:
				dbType = DbType.DateTime;
				ociType = OciDataType.Char;
				break;
			case OracleType.Double:
				dbType = DbType.Double;
				ociType = OciDataType.Float;
				break;
			case OracleType.Float:
				dbType = DbType.Single;
				ociType = OciDataType.Float;
				break;
			case OracleType.Int16:
				dbType = DbType.Int16;
				ociType = OciDataType.Integer;
				break;
			case OracleType.Int32:
			case OracleType.IntervalYearToMonth:
				dbType = DbType.Int32;
				ociType = OciDataType.Integer;
				break;
			case OracleType.NChar:
				dbType = DbType.StringFixedLength;
				ociType = OciDataType.Char;
				break;
			case OracleType.NClob:
			case OracleType.NVarChar:
				dbType = DbType.String;
				ociType = OciDataType.VarChar;
				break;
			case OracleType.Number:
				dbType = DbType.VarNumeric;
				ociType = OciDataType.Number;
				break;
			case OracleType.SByte:
				dbType = DbType.SByte;
				ociType = OciDataType.Integer;
				break;
			case OracleType.UInt16:
				dbType = DbType.UInt16;
				ociType = OciDataType.Integer;
				break;
			case OracleType.UInt32:
				dbType = DbType.UInt32;
				ociType = OciDataType.Integer;
				break;
			default:
				throw new ArgumentException (exception);
			}

			oracleType = type;
		}