internal void Rebind(OracleConnection connection, ref bool mustRelease, ref SafeHandle handleToBind) { handleToBind = null; switch (this._metaType.OciType) { case OCI.DATATYPE.CLOB: case OCI.DATATYPE.BLOB: case OCI.DATATYPE.BFILE: OciLobLocator.SafeDispose(ref this._lobLocator); this._lobLocator = new OciLobLocator(connection, this._metaType.OracleType); handleToBind = this._lobLocator.Descriptor; break; case OCI.DATATYPE.LONGRAW: case OCI.DATATYPE.LONG: this._rowBuffer.WriteInt32(this._lengthOffset, 0); this._longLength = -1; if (this._longBuffer != null) { this._longBuffer.Reset(); } else { this._longBuffer = new NativeBuffer_LongColumnData(); } handleToBind = this._longBuffer; break; } if (handleToBind != null) { handleToBind.DangerousAddRef(ref mustRelease); this._rowBuffer.WriteIntPtr(this._valueOffset, handleToBind.DangerousGetHandle()); } }
internal OracleLob(OracleLob lob) { this._lobLocator = lob._lobLocator.Clone(); this._lobType = lob._lobLocator.LobType; this._charsetForm = lob._charsetForm; this._currentPosition = lob._currentPosition; this._isTemporaryState = lob._isTemporaryState; }
internal static void SafeDispose(ref OciLobLocator locator) { if (locator != null) { locator.Dispose(); } locator = null; }
internal OracleLob(OracleLob lob) { this._lobLocator = lob._lobLocator.Clone(); this._lobType = lob._lobLocator.LobType; this._charsetForm = lob._charsetForm; this._currentPosition = lob._currentPosition; this._isTemporaryState = lob._isTemporaryState; }
// (internal) Construct from a buffer internal OracleLob(OciLobLocator lobLocator) { _lobLocator = lobLocator.Clone(); _lobType = _lobLocator.LobType; _charsetForm = (OracleType.NClob == _lobType) ? OCI.CHARSETFORM.SQLCS_NCHAR : OCI.CHARSETFORM.SQLCS_IMPLICIT; #if EXPOSELOBBUFFERING _bufferedRequested = false; #endif //EXPOSELOBBUFFERING }
internal void Dispose() { NativeBuffer.SafeDispose(ref this._longBuffer); OciLobLocator.SafeDispose(ref this._lobLocator); OciHandle.SafeDispose(ref this._describeHandle); this._columnName = null; this._metaType = null; this._callback = null; this._connection = null; }
internal static void SafeDispose(ref OciLobLocator locator) { // Safely disposes of the handle (even if it is already null) and // then nulls it out. if (null != locator) { locator.Dispose(); } locator = null; }
/// <include file='doc\OracleLob.uex' path='docs/doc[@for="OracleLob.Close"]/*' /> public override void Close() { if (!IsNull && !ConnectionIsClosed) { Flush(); #if EXPOSELOBBUFFERING _bufferedRequested = false; #endif //EXPOSELOBBUFFERING OciLobLocator.SafeDispose(ref _lobLocator); } }
// (internal) Construct from an existing Lob object (copy constructor) internal OracleLob(OracleLob lob) { this._lobLocator = lob._lobLocator.Clone(); this._lobType = lob._lobLocator.LobType; this._charsetForm = lob._charsetForm; this._currentPosition = lob._currentPosition; #if EXPOSELOBBUFFERING this._isCurrentlyBuffered = lob._isCurrentlyBuffered; this._bufferedRequested = lob._bufferedRequested; #endif //EXPOSELOBBUFFERING this._isTemporaryState = lob._isTemporaryState; }
private void Dispose(bool disposing) { // If we're disposing, it's because we went out of scope, and we're // being garbage collected. We shouldn't touch any managed objects // or bad things can happen. if (disposing) { Close(); } _lobLocator = null; }
void Dispose(bool disposing) { if (disposing) { if (locator != null) { locator.Dispose(); } } locator = null; isOpen = false; }
internal OracleLob(OracleConnection connection, OracleType oracleType) { this._lobLocator = new OciLobLocator(connection, oracleType); this._lobType = oracleType; this._charsetForm = (OracleType.NClob == this._lobType) ? OCI.CHARSETFORM.SQLCS_NCHAR : OCI.CHARSETFORM.SQLCS_IMPLICIT; this._isTemporaryState = 1; OCI.LOB_TYPE lobtype = (OracleType.Blob == oracleType) ? OCI.LOB_TYPE.OCI_TEMP_BLOB : OCI.LOB_TYPE.OCI_TEMP_CLOB; int rc = TracedNativeMethods.OCILobCreateTemporary(connection.ServiceContextHandle, connection.ErrorHandle, this._lobLocator.Descriptor, 0, this._charsetForm, lobtype, 0, OCI.DURATION.OCI_DURATION_BEGIN); if (rc != 0) { connection.CheckError(this.ErrorHandle, rc); } }
internal OracleLob(OracleConnection connection, OracleType oracleType) { this._lobLocator = new OciLobLocator(connection, oracleType); this._lobType = oracleType; this._charsetForm = (OracleType.NClob == this._lobType) ? OCI.CHARSETFORM.SQLCS_NCHAR : OCI.CHARSETFORM.SQLCS_IMPLICIT; this._isTemporaryState = 1; OCI.LOB_TYPE lobtype = (OracleType.Blob == oracleType) ? OCI.LOB_TYPE.OCI_TEMP_BLOB : OCI.LOB_TYPE.OCI_TEMP_CLOB; int rc = TracedNativeMethods.OCILobCreateTemporary(connection.ServiceContextHandle, connection.ErrorHandle, this._lobLocator.Descriptor, 0, this._charsetForm, lobtype, 0, OCI.DURATION.OCI_DURATION_BEGIN); if (rc != 0) { connection.CheckError(this.ErrorHandle, rc); } }
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; } }
protected override void Dispose(bool disposing) { try { if ((disposing && !this.IsNull) && !this.ConnectionIsClosed) { this.Flush(); OciLobLocator.SafeDispose(ref this._lobLocator); this._lobLocator = null; } } finally { base.Dispose(disposing); } }
internal void Bind(OciStatementHandle statementHandle, NativeBuffer parameterBuffer, OracleConnection connection, ref bool mustRelease, ref SafeHandle handleToBind) { if (IsDirection(this.Parameter, ParameterDirection.Output) || (this.Parameter.Value != null)) { int num2; IntPtr ptr2; string parameterName = this.Parameter.ParameterName; OciErrorHandle errorHandle = connection.ErrorHandle; OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle; int num = 0; OCI.INDICATOR oK = OCI.INDICATOR.OK; OCI.DATATYPE ociType = this._bindingMetaType.OciType; IntPtr dataPtr = parameterBuffer.DangerousGetDataPtr(this._indicatorOffset); IntPtr alenp = parameterBuffer.DangerousGetDataPtr(this._lengthOffset); IntPtr valuep = parameterBuffer.DangerousGetDataPtr(this._valueOffset); OciHandle.SafeDispose(ref this._dateTimeDescriptor); if (IsDirection(this.Parameter, ParameterDirection.Input)) { if (System.Data.Common.ADP.IsNull(this._coercedValue)) { oK = OCI.INDICATOR.ISNULL; switch (ociType) { case OCI.DATATYPE.INT_TIMESTAMP: case OCI.DATATYPE.INT_TIMESTAMP_TZ: case OCI.DATATYPE.INT_TIMESTAMP_LTZ: this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection); handleToBind = this._dateTimeDescriptor; break; } } else { num = this.PutOracleValue(this._coercedValue, parameterBuffer, this._valueOffset, this._bindingMetaType, connection, ref handleToBind); } } else { if (this._bindingMetaType.IsVariableLength) { num = 0; } else { num = this._bufferLength; } OciLobLocator.SafeDispose(ref this._locator); OciHandle.SafeDispose(ref this._descriptor); switch (ociType) { case OCI.DATATYPE.CLOB: case OCI.DATATYPE.BLOB: case OCI.DATATYPE.BFILE: this._locator = new OciLobLocator(connection, this._bindingMetaType.OracleType); handleToBind = this._locator.Descriptor; break; case OCI.DATATYPE.RSET: this._descriptor = new OciStatementHandle(serviceContextHandle); handleToBind = this._descriptor; break; case OCI.DATATYPE.INT_TIMESTAMP: case OCI.DATATYPE.INT_TIMESTAMP_TZ: case OCI.DATATYPE.INT_TIMESTAMP_LTZ: this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection); handleToBind = this._dateTimeDescriptor; break; } } if (handleToBind != null) { handleToBind.DangerousAddRef(ref mustRelease); parameterBuffer.WriteIntPtr(this._valueOffset, handleToBind.DangerousGetHandle()); } parameterBuffer.WriteInt16(this._indicatorOffset, (short) oK); if ((OCI.DATATYPE.LONGVARCHAR == ociType) || (OCI.DATATYPE.LONGVARRAW == ociType)) { alenp = IntPtr.Zero; } else if (this._bindAsUCS2) { parameterBuffer.WriteInt32(this._lengthOffset, num / System.Data.Common.ADP.CharSize); } else { parameterBuffer.WriteInt32(this._lengthOffset, num); } if (IsDirection(this.Parameter, ParameterDirection.Output)) { num2 = this._bufferLength; } else { num2 = num; } OCI.DATATYPE dty = ociType; switch (ociType) { case OCI.DATATYPE.INT_TIMESTAMP: dty = OCI.DATATYPE.TIMESTAMP; break; case OCI.DATATYPE.INT_TIMESTAMP_TZ: dty = OCI.DATATYPE.TIMESTAMP_TZ; break; case OCI.DATATYPE.INT_TIMESTAMP_LTZ: dty = OCI.DATATYPE.TIMESTAMP_LTZ; break; } int rc = TracedNativeMethods.OCIBindByName(statementHandle, out ptr2, errorHandle, parameterName, parameterName.Length, valuep, num2, dty, dataPtr, alenp, OCI.MODE.OCI_DEFAULT); if (rc != 0) { this._command.Connection.CheckError(errorHandle, rc); } this._bindHandle = new OciBindHandle(statementHandle, ptr2); if (this._bindingMetaType.IsCharacterType) { if (OCI.ClientVersionAtLeastOracle9i && IsDirection(this.Parameter, ParameterDirection.Output)) { this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXCHAR_SIZE, this._bindSize, errorHandle); } if ((num2 > (this._bindingMetaType.MaxBindSize / System.Data.Common.ADP.CharSize)) || (!OCI.ClientVersionAtLeastOracle9i && this._bindingMetaType.UsesNationalCharacterSet)) { this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXDATA_SIZE, this._bindingMetaType.MaxBindSize, errorHandle); } if (this._bindingMetaType.UsesNationalCharacterSet) { this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, 2, errorHandle); } if (this._bindAsUCS2) { this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, 0x3e8, errorHandle); } } GC.KeepAlive(parameterBuffer); } }
//////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // // Methods // //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// internal void Bind( OciHandle statementHandle, NativeBuffer parameterBuffer, OracleConnection connection ) { IntPtr h; // Don't bother with parameters where the user asks for the default value. if (!IsDirection(Parameter, ParameterDirection.Output) && null == Parameter.Value) { return; } string parameterName = Parameter.ParameterName; OciHandle errorHandle = connection.ErrorHandle; OciHandle environmentHandle = connection.EnvironmentHandle; int valueLength = 0; OCI.INDICATOR indicatorValue = OCI.INDICATOR.OK; int bufferLength; OCI.DATATYPE ociType = _bindingMetaType.OciType; HandleRef indicatorLocation = parameterBuffer.PtrOffset(_indicatorOffset); HandleRef lengthLocation = parameterBuffer.PtrOffset(_lengthOffset); HandleRef valueLocation = parameterBuffer.PtrOffset(_valueOffset); if (IsDirection(Parameter, ParameterDirection.Input)) { if (ADP.IsNull(_coercedValue)) { indicatorValue = OCI.INDICATOR.ISNULL; } else { valueLength = PutOracleValue( _coercedValue, valueLocation, _bindingMetaType, connection); } } else { Debug.Assert(IsDirection(Parameter, ParameterDirection.Output), "non-output output parameter?"); if (_bindingMetaType.IsVariableLength) { valueLength = 0; // Output-only values never have an input length... } else { valueLength = _bufferLengthInBytes; // ...except when they're fixed length, to avoid ORA-01459 errors } OciLobLocator.SafeDispose(ref _locator); OciHandle.SafeDispose(ref _descriptor); switch (ociType) { case OCI.DATATYPE.BFILE: case OCI.DATATYPE.BLOB: case OCI.DATATYPE.CLOB: _locator = new OciLobLocator(connection, _bindingMetaType.OracleType); break; case OCI.DATATYPE.RSET: _descriptor = new OciStatementHandle(environmentHandle); break; } if (null != _locator) { Marshal.WriteIntPtr((IntPtr)valueLocation, (IntPtr)_locator.Handle); } else if (null != _descriptor) { Marshal.WriteIntPtr((IntPtr)valueLocation, (IntPtr)_descriptor.Handle); } } Marshal.WriteInt16((IntPtr)indicatorLocation, (Int16)indicatorValue); // Don't bind a length value for LONGVARCHAR or LONGVARRAW data, or you'll end // up with ORA-01098: program Interface error during Long Insert\nORA-01458: invalid length inside variable character string // errors. if (OCI.DATATYPE.LONGVARCHAR == ociType || OCI.DATATYPE.LONGVARRAW == ociType) { lengthLocation = ADP.NullHandleRef; } else { // When we're binding this parameter as UCS2, the length we specify // must be in characters, not in bytes. if (_bindAsUCS2) { Marshal.WriteInt32((IntPtr)lengthLocation, (Int32)(valueLength / ADP.CharSize)); } else { Marshal.WriteInt32((IntPtr)lengthLocation, (Int32)valueLength); } } if (IsDirection(Parameter, ParameterDirection.Output)) { bufferLength = _bufferLengthInBytes; } else { bufferLength = valueLength; } // Finally, tell Oracle about our parameter. int rc = TracedNativeMethods.OCIBindByName( statementHandle, out h, errorHandle, parameterName, parameterName.Length, valueLocation, bufferLength, ociType, indicatorLocation, lengthLocation, ADP.NullHandleRef, 0, ADP.NullHandleRef, OCI.MODE.OCI_DEFAULT ); if (rc != 0) { _command.Connection.CheckError(errorHandle, rc); } _bindHandle = new OciBindHandle(statementHandle, h); #if TRACEPARAMETERVALUES if (null != _coercedValue) { SafeNativeMethods.OutputDebugStringW("Value = '" + _coercedValue.ToString() + "'\n"); } #endif //TRACEPARAMETERVALUES // OK, character bindings have a few extra things we need to do to // deal with character sizes and alternate character sets. if (_bindingMetaType.IsCharacterType) { // To avoid problems when our buffer is larger than the maximum number // of characters, we use OCI_ATTR_MAXCHAR_SIZE to limit the number of // characters that will be used. (Except on Oracle8i clients where it // isn't available) if (OCI.ClientVersionAtLeastOracle9i && IsDirection(Parameter, ParameterDirection.Output)) { _bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXCHAR_SIZE, (int)_bufferLength, errorHandle); } if ((bufferLength > _bindingMetaType.MaxBindSize / ADP.CharSize) || (!OCI.ClientVersionAtLeastOracle9i && _bindingMetaType.UsesNationalCharacterSet)) // need to specify MAXDATA_SIZE for OCI8 UCS2 bindings to work { _bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXDATA_SIZE, (int)_bindingMetaType.MaxBindSize, errorHandle); } // NOTE: the order is important here; setting charsetForm will // reset charsetId (I found this out the hard way...) if (_bindingMetaType.UsesNationalCharacterSet) { _bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, (int)OCI.CHARSETFORM.SQLCS_NCHAR, errorHandle); } // NOTE: the order is important here; setting charsetForm will // reset charsetId (I found this out the hard way...) if (_bindAsUCS2) { _bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, OCI.OCI_UCS2ID, errorHandle); } } }
internal OracleBFile(OciLobLocator lobLocator) { this._lob = new OracleLob(lobLocator); }
internal void Bind(OciStatementHandle statementHandle, NativeBuffer parameterBuffer, OracleConnection connection, ref bool mustRelease, ref SafeHandle handleToBind) { if (IsDirection(this.Parameter, ParameterDirection.Output) || (this.Parameter.Value != null)) { int num2; IntPtr ptr2; string parameterName = this.Parameter.ParameterName; OciErrorHandle errorHandle = connection.ErrorHandle; OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle; int num = 0; OCI.INDICATOR oK = OCI.INDICATOR.OK; OCI.DATATYPE ociType = this._bindingMetaType.OciType; IntPtr dataPtr = parameterBuffer.DangerousGetDataPtr(this._indicatorOffset); IntPtr alenp = parameterBuffer.DangerousGetDataPtr(this._lengthOffset); IntPtr valuep = parameterBuffer.DangerousGetDataPtr(this._valueOffset); OciHandle.SafeDispose(ref this._dateTimeDescriptor); if (IsDirection(this.Parameter, ParameterDirection.Input)) { if (System.Data.Common.ADP.IsNull(this._coercedValue)) { oK = OCI.INDICATOR.ISNULL; switch (ociType) { case OCI.DATATYPE.INT_TIMESTAMP: case OCI.DATATYPE.INT_TIMESTAMP_TZ: case OCI.DATATYPE.INT_TIMESTAMP_LTZ: this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection); handleToBind = this._dateTimeDescriptor; break; } } else { num = this.PutOracleValue(this._coercedValue, parameterBuffer, this._valueOffset, this._bindingMetaType, connection, ref handleToBind); } } else { if (this._bindingMetaType.IsVariableLength) { num = 0; } else { num = this._bufferLength; } OciLobLocator.SafeDispose(ref this._locator); OciHandle.SafeDispose(ref this._descriptor); switch (ociType) { case OCI.DATATYPE.CLOB: case OCI.DATATYPE.BLOB: case OCI.DATATYPE.BFILE: this._locator = new OciLobLocator(connection, this._bindingMetaType.OracleType); handleToBind = this._locator.Descriptor; break; case OCI.DATATYPE.RSET: this._descriptor = new OciStatementHandle(serviceContextHandle); handleToBind = this._descriptor; break; case OCI.DATATYPE.INT_TIMESTAMP: case OCI.DATATYPE.INT_TIMESTAMP_TZ: case OCI.DATATYPE.INT_TIMESTAMP_LTZ: this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection); handleToBind = this._dateTimeDescriptor; break; } } if (handleToBind != null) { handleToBind.DangerousAddRef(ref mustRelease); parameterBuffer.WriteIntPtr(this._valueOffset, handleToBind.DangerousGetHandle()); } parameterBuffer.WriteInt16(this._indicatorOffset, (short)oK); if ((OCI.DATATYPE.LONGVARCHAR == ociType) || (OCI.DATATYPE.LONGVARRAW == ociType)) { alenp = IntPtr.Zero; } else if (this._bindAsUCS2) { parameterBuffer.WriteInt32(this._lengthOffset, num / System.Data.Common.ADP.CharSize); } else { parameterBuffer.WriteInt32(this._lengthOffset, num); } if (IsDirection(this.Parameter, ParameterDirection.Output)) { num2 = this._bufferLength; } else { num2 = num; } OCI.DATATYPE dty = ociType; switch (ociType) { case OCI.DATATYPE.INT_TIMESTAMP: dty = OCI.DATATYPE.TIMESTAMP; break; case OCI.DATATYPE.INT_TIMESTAMP_TZ: dty = OCI.DATATYPE.TIMESTAMP_TZ; break; case OCI.DATATYPE.INT_TIMESTAMP_LTZ: dty = OCI.DATATYPE.TIMESTAMP_LTZ; break; } int rc = TracedNativeMethods.OCIBindByName(statementHandle, out ptr2, errorHandle, parameterName, parameterName.Length, valuep, num2, dty, dataPtr, alenp, OCI.MODE.OCI_DEFAULT); if (rc != 0) { this._command.Connection.CheckError(errorHandle, rc); } this._bindHandle = new OciBindHandle(statementHandle, ptr2); if (this._bindingMetaType.IsCharacterType) { if (OCI.ClientVersionAtLeastOracle9i && IsDirection(this.Parameter, ParameterDirection.Output)) { this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXCHAR_SIZE, this._bindSize, errorHandle); } if ((num2 > (this._bindingMetaType.MaxBindSize / System.Data.Common.ADP.CharSize)) || (!OCI.ClientVersionAtLeastOracle9i && this._bindingMetaType.UsesNationalCharacterSet)) { this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXDATA_SIZE, this._bindingMetaType.MaxBindSize, errorHandle); } if (this._bindingMetaType.UsesNationalCharacterSet) { this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, 2, errorHandle); } if (this._bindAsUCS2) { this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, 0x3e8, errorHandle); } } GC.KeepAlive(parameterBuffer); } }
internal OracleLob(OciLobLocator lobLocator) { this._lobLocator = lobLocator.Clone(); this._lobType = this._lobLocator.LobType; this._charsetForm = (OracleType.NClob == this._lobType) ? OCI.CHARSETFORM.SQLCS_NCHAR : OCI.CHARSETFORM.SQLCS_IMPLICIT; }
protected override void Dispose(bool disposing) { try { if ((disposing && !this.IsNull) && !this.ConnectionIsClosed) { this.Flush(); OciLobLocator.SafeDispose(ref this._lobLocator); this._lobLocator = null; } } finally { base.Dispose(disposing); } }
internal static void SafeDispose(ref OciLobLocator locator) { if (locator != null) { locator.Dispose(); } locator = null; }
internal OracleLob(OciLobLocator lobLocator) { this._lobLocator = lobLocator.Clone(); this._lobType = this._lobLocator.LobType; this._charsetForm = (OracleType.NClob == this._lobType) ? OCI.CHARSETFORM.SQLCS_NCHAR : OCI.CHARSETFORM.SQLCS_IMPLICIT; }