override protected bool ExtraDispose(HandleRef localHandle, OCI.HTYPE handleType) { int rc; if (IntPtr.Zero != _serverHandle.Handle) { rc = TracedNativeMethods.OCIServerDetach( _serverHandle, // srvhp _errorHandle, // errhp OCI.MODE.OCI_DEFAULT // mode ); if (0 != rc) { Debug.WriteLine(String.Format("OracleClient: OCIServerDetach(0x{0,-8:x} failed: rc={1:d}", localHandle.Handle, rc)); Debug.Assert(false, "OCIServerDetach failed"); } rc = TracedNativeMethods.OCIHandleFree(_serverHandle, OCI.HTYPE.OCI_HTYPE_SERVER); } if (IntPtr.Zero != _errorHandle.Handle) { rc = TracedNativeMethods.OCIHandleFree(_errorHandle, OCI.HTYPE.OCI_HTYPE_ERROR); } rc = TracedNativeMethods.OCIHandleFree(localHandle, handleType); GC.KeepAlive(this); return(false); // don't bother with the default clean up, we already did it. }
internal void SetAttribute( OCI.ATTR attribute, string value, OciHandle errorHandle ) { int valueLengthAsChars = value.Length; byte[] valueAsBytes = new byte[valueLengthAsChars * 4]; int valueLengthAsBytes = GetBytes(value.ToCharArray(), 0, valueLengthAsChars, valueAsBytes, 0); int rc = TracedNativeMethods.OCIAttrSet( this, // trgthndlp/trghndltyp valueAsBytes, // attributep valueLengthAsBytes, // size attribute, // attrtype errorHandle // errhp ); if (0 != rc) { OracleException.Check(errorHandle, rc); } GC.KeepAlive(this); }
internal void GetNames() { _lob.AssertConnectionIsOpen(); int charSize = (Connection.EnvironmentHandle.IsUnicode) ? 2 : 1; short directoryAliasLength = (short)(charSize * 30); short fileAliasLength = (short)(charSize * 255); NativeBuffer buffer = Connection.ScratchBuffer; Debug.Assert(buffer.Length > (directoryAliasLength + fileAliasLength), "connection's scratch buffer is too small"); HandleRef directoryAlias = buffer.Ptr; HandleRef fileAlias = buffer.PtrOffset(directoryAliasLength); int rc = TracedNativeMethods.OCILobFileGetName( Connection.EnvironmentHandle, ErrorHandle, Descriptor, directoryAlias, ref directoryAliasLength, fileAlias, ref fileAliasLength ); if (0 != rc) { Connection.CheckError(ErrorHandle, rc); } _directoryAlias = Connection.GetString((IntPtr)directoryAlias, directoryAliasLength, false); _fileName = Connection.GetString((IntPtr)fileAlias, fileAliasLength, false); GC.KeepAlive(buffer); }
protected override DbSqlParserColumnCollection GatherTableColumns(DbSqlParserTable table) { OciStatementHandle stmtp = new OciStatementHandle(this._connection.ServiceContextHandle); OciErrorHandle errorHandle = this._connection.ErrorHandle; StringBuilder builder = new StringBuilder(); string schemaName = table.SchemaName; string tableName = table.TableName; DbSqlParserColumnCollection columns = new DbSqlParserColumnCollection(); builder.Append("select * from "); if (!System.Data.Common.ADP.IsEmpty(schemaName)) { builder.Append(schemaName); builder.Append("."); } builder.Append(tableName); string stmt = builder.ToString(); if ((TracedNativeMethods.OCIStmtPrepare(stmtp, errorHandle, stmt, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, this._connection) == 0) && (TracedNativeMethods.OCIStmtExecute(this._connection.ServiceContextHandle, stmtp, errorHandle, 0, OCI.MODE.OCI_DESCRIBE_ONLY) == 0)) { int num3; stmtp.GetAttribute(OCI.ATTR.OCI_ATTR_PARAM_COUNT, out num3, errorHandle); for (int i = 0; i < num3; i++) { string str; OciParameterDescriptor handle = stmtp.GetDescriptor(i, errorHandle); handle.GetAttribute(OCI.ATTR.OCI_ATTR_SQLCODE, out str, errorHandle, this._connection); OciHandle.SafeDispose(ref handle); str = this.QuotePrefixCharacter + str + this.QuoteSuffixCharacter; columns.Add(null, schemaName, tableName, str, null); } } OciHandle.SafeDispose(ref stmtp); return(columns); }
public long Erase(long offset, long amount) { this.AssertObjectNotDisposed(); if (this.IsNull) { throw System.Data.Common.ADP.LobWriteInvalidOnNull(); } this.AssertAmountIsValid(amount, "amount"); this.AssertAmountIsEven(offset, "offset"); this.AssertPositionIsValid(); this.AssertConnectionIsOpen(); this.AssertTransactionExists(); if ((offset < 0L) || (offset >= 0xffffffffL)) { return(0L); } uint num4 = (uint)this.AdjustOffsetToOracle(amount); uint num3 = ((uint)this.AdjustOffsetToOracle(offset)) + 1; int rc = TracedNativeMethods.OCILobErase(this.ServiceContextHandle, this.ErrorHandle, this.Descriptor, ref num4, num3); if (rc != 0) { this.Connection.CheckError(this.ErrorHandle, rc); } return(this.AdjustOracleToOffset((long)num4)); }
internal void GetNames() { this._lob.AssertConnectionIsOpen(); short num5 = this.Connection.EnvironmentHandle.IsUnicode ? ((short) 2) : ((short) 1); ushort num = (ushort) (30 * num5); int offset = num; ushort num3 = (ushort) (0xff * num5); NativeBuffer scratchBuffer = this.Connection.GetScratchBuffer(num + num3); bool success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { scratchBuffer.DangerousAddRef(ref success); int rc = TracedNativeMethods.OCILobFileGetName(this.Connection.EnvironmentHandle, this.ErrorHandle, this.Descriptor, scratchBuffer.DangerousGetDataPtr(), ref num, scratchBuffer.DangerousGetDataPtr(offset), ref num3); if (rc != 0) { this.Connection.CheckError(this.ErrorHandle, rc); } this._directoryAlias = this.Connection.GetString(scratchBuffer.ReadBytes(0, num)); this._fileName = this.Connection.GetString(scratchBuffer.ReadBytes(offset, num3)); } finally { if (success) { scratchBuffer.DangerousRelease(); } } }
internal OciHandle GetDescriptor( int i, OciHandle errorHandle ) { // Wraps the OCIParamGet call. We do not expect it to fail, so we // will throw if it does. IntPtr paramdesc; int rc = TracedNativeMethods.OCIParamGet( this, errorHandle, out paramdesc, i + 1 ); if (0 != rc) { OracleException.Check(errorHandle, rc); } OciHandle result = new OciParameterDescriptor(this, paramdesc); GC.KeepAlive(this); return(result); }
internal OciEnlistContext(byte[] userName, byte[] password, byte[] serverName, OciServiceContextHandle serviceContextHandle, OciErrorHandle errorHandle) : base(IntPtr.Zero, true) { RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { this._serviceContextHandle = serviceContextHandle; int rc = 0; try { rc = TracedNativeMethods.OraMTSEnlCtxGet(userName, password, serverName, this._serviceContextHandle, errorHandle, out this.handle); } catch (DllNotFoundException exception) { throw System.Data.Common.ADP.DistribTxRequiresOracleServicesForMTS(exception); } if (rc != 0) { OracleException.Check(errorHandle, rc); } serviceContextHandle.AddRef(); } }
public long CopyTo(long sourceOffset, OracleLob destination, long destinationOffset, long amount) { this.AssertInternalLobIsValid(); if (destination == null) { throw System.Data.Common.ADP.ArgumentNull("destination"); } if (destination.IsNull) { throw System.Data.Common.ADP.LobWriteInvalidOnNull(); } if (this._lob.IsNull) { return 0L; } this._lob.AssertConnectionIsOpen(); this._lob.AssertAmountIsValid(amount, "amount"); this._lob.AssertAmountIsValid(sourceOffset, "sourceOffset"); this._lob.AssertAmountIsValid(destinationOffset, "destinationOffset"); this._lob.AssertTransactionExists(); long num = Math.Min(this.Length - sourceOffset, amount); long num4 = destinationOffset + 1L; long num3 = sourceOffset + 1L; if (0L >= num) { return 0L; } int rc = TracedNativeMethods.OCILobLoadFromFile(this.ServiceContextHandle, this.ErrorHandle, destination.Descriptor, this.Descriptor, (uint) num, (uint) num4, (uint) num3); if (rc != 0) { this.Connection.CheckError(this.ErrorHandle, rc); } return num; }
/// <include file='doc\OracleLob.uex' path='docs/doc[@for="OracleLob.Append"]/*' /> public void Append(OracleLob source) { if (null == source) { throw ADP.ArgumentNull("source"); } AssertObjectNotDisposed(); source.AssertObjectNotDisposed(); if (IsNull) { throw ADP.LobWriteInvalidOnNull(); } if (!source.IsNull) { AssertConnectionIsOpen(); EnsureBuffering(false); int rc = TracedNativeMethods.OCILobAppend( ServiceContextHandle, ErrorHandle, Descriptor, source.Descriptor ); if (0 != rc) { Connection.CheckError(ErrorHandle, rc); } } }
public void SetFileName(string directory, string file) { this.AssertInternalLobIsValid(); if (!this.IsNull) { this._lob.AssertConnectionIsOpen(); this._lob.AssertTransactionExists(); OciFileDescriptor filep = (OciFileDescriptor) this.LobLocator.Descriptor; if (filep != null) { this.LobLocator.ForceClose(); int rc = TracedNativeMethods.OCILobFileSetName(this.Connection.EnvironmentHandle, this.ErrorHandle, filep, directory, file); if (rc != 0) { this.Connection.CheckError(this.ErrorHandle, rc); } this.LobLocator.ForceOpen(); this._fileName = null; this._directoryAlias = null; try { this._lob.Position = 0L; } catch (Exception exception) { if (!System.Data.Common.ADP.IsCatchableExceptionType(exception)) { throw; } } } } }
/// <include file='doc\OracleLob.uex' path='docs/doc[@for="OracleLob.SetLength"]/*' /> public override void SetLength(long value) { AssertObjectNotDisposed(); if (IsNull) { throw ADP.LobWriteInvalidOnNull(); } AssertConnectionIsOpen(); AssertAmountIsValid(value, "value"); AssertTransactionExists(); EnsureBuffering(false); UInt32 newlength = (UInt32)AdjustOffsetToOracle(value); int rc = TracedNativeMethods.OCILobTrim( ServiceContextHandle, ErrorHandle, Descriptor, newlength ); if (0 != rc) { Connection.CheckError(ErrorHandle, rc); } // Adjust the current position to be within the length of the lob, if // we just truncated it before the current position. _currentPosition = Math.Min(_currentPosition, value); }
//////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // // Constructors // //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// internal OciEnlistContext( string userName, string password, string serverName, OciHandle serviceContextHandle, OciHandle errorHandle) { _enlistContext = IntPtr.Zero; _serviceContextHandle = serviceContextHandle; int rc = 0; try { rc = TracedNativeMethods.OraMTSEnlCtxGet(userName, password, serverName, _serviceContextHandle, errorHandle, 0, out _enlistContext); } catch (DllNotFoundException e) { ADP.DistribTxRequiresOracleServicesForMTS(e); } if (0 != rc) { OracleException.Check(errorHandle, rc); } }
public override void Write(byte[] buffer, int offset, int count) { this.AssertObjectNotDisposed(); this.AssertConnectionIsOpen(); if (count < 0) { throw System.Data.Common.ADP.MustBePositive("count"); } if (offset < 0) { throw System.Data.Common.ADP.MustBePositive("offset"); } if (buffer == null) { throw System.Data.Common.ADP.ArgumentNull("buffer"); } if (buffer.Length < (offset + count)) { throw System.Data.Common.ADP.BufferExceeded("count"); } this.AssertTransactionExists(); if (this.IsNull) { throw System.Data.Common.ADP.LobWriteInvalidOnNull(); } this.AssertAmountIsValid((long)offset, "offset"); this.AssertAmountIsValid((long)count, "count"); this.AssertPositionIsValid(); OCI.CHARSETFORM csfrm = this._charsetForm; ushort csid = this.IsCharacterLob ? ((ushort)0x3e8) : ((ushort)0); int amtp = this.AdjustOffsetToOracle(count); int rc = 0; if (amtp != 0) { GCHandle handle = new GCHandle(); try { handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); IntPtr bufp = new IntPtr(((long)handle.AddrOfPinnedObject()) + offset); rc = TracedNativeMethods.OCILobWrite(this.ServiceContextHandle, this.ErrorHandle, this.Descriptor, ref amtp, this.CurrentOraclePosition, bufp, (uint)count, 0, csid, csfrm); } finally { if (handle.IsAllocated) { handle.Free(); } } if (rc != 0) { this.Connection.CheckError(this.ErrorHandle, rc); } amtp = this.AdjustOracleToOffset(amtp); this._currentPosition += amtp; } }
internal void SetAttribute(OCI.ATTR attribute, int value, OciErrorHandle errorHandle) { int rc = TracedNativeMethods.OCIAttrSet(this, ref value, 0, attribute, errorHandle); if (rc != 0) { OracleException.Check(errorHandle, rc); } }
internal void Free() { int rc = TracedNativeMethods.OCILobFreeTemporary(this._lobLocator.ServiceContextHandle, this._lobLocator.ErrorHandle, this._lobLocator.Descriptor); if (rc != 0) { this._lobLocator.Connection.CheckError(this.ErrorHandle, rc); } }
internal void Join(OracleInternalConnection internalConnection, Transaction indigoTransaction) { IDtcTransaction oletxTransaction = System.Data.Common.ADP.GetOletxTransaction(indigoTransaction); int rc = TracedNativeMethods.OraMTSJoinTxn(this, oletxTransaction); if (rc != 0) { OracleException.Check(rc, internalConnection); } }
internal void GetAttribute(OCI.ATTR attribute, out int value, OciErrorHandle errorHandle) { uint sizep = 0; int rc = TracedNativeMethods.OCIAttrGet(this, out value, out sizep, attribute, errorHandle); if (rc != 0) { OracleException.Check(errorHandle, rc); } }
internal void Join(ITransaction transaction) { int rc = TracedNativeMethods.OraMTSJoinTxn(Handle, transaction); if (0 != rc) { OracleException.Check(rc); } _transaction = transaction; }
internal void Commit() { int rc = TracedNativeMethods.OCITransCommit(this.ServiceContextHandle, this.ErrorHandle, OCI.MODE.OCI_DEFAULT); if (rc != 0) { OracleException.Check(this.ErrorHandle, rc); } this.TransactionState = System.Data.OracleClient.TransactionState.AutoCommit; this.Transaction = null; }
internal OciParameterDescriptor GetDescriptor(int i, OciErrorHandle errorHandle) { IntPtr ptr; int rc = TracedNativeMethods.OCIParamGet(this, base.HandleType, errorHandle, out ptr, i + 1); if (rc != 0) { OracleException.Check(errorHandle, rc); } return(new OciParameterDescriptor(this, ptr)); }
internal void ForceClose() { if (this._openMode != 0) { int rc = TracedNativeMethods.OCILobClose(this.ServiceContextHandle, this.ErrorHandle, this.Descriptor); if (rc != 0) { this.Connection.CheckError(this.ErrorHandle, rc); } this._openMode = 0; } }
internal void ForceOpen() { if (this._openMode != 0) { int rc = TracedNativeMethods.OCILobOpen(this.ServiceContextHandle, this.ErrorHandle, this.Descriptor, (byte)this._openMode); if (rc != 0) { this._openMode = 0; this.Connection.CheckError(this.ErrorHandle, rc); } } }
internal void SetAttribute(OCI.ATTR attribute, string value, OciErrorHandle errorHandle) { uint length = (uint)value.Length; byte[] bytes = new byte[length * 4]; uint size = this.GetBytes(value.ToCharArray(), 0, length, bytes, 0); int rc = TracedNativeMethods.OCIAttrSet(this, bytes, size, attribute, errorHandle); if (rc != 0) { OracleException.Check(errorHandle, rc); } }
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 void GetAttribute(OCI.ATTR attribute, out string value, OciErrorHandle errorHandle, OracleConnection connection) { IntPtr zero = IntPtr.Zero; uint sizep = 0; int rc = TracedNativeMethods.OCIAttrGet(this, ref zero, ref sizep, attribute, errorHandle); if (rc != 0) { OracleException.Check(errorHandle, rc); } byte[] destination = new byte[sizep]; Marshal.Copy(zero, destination, 0, (int)sizep); value = connection.GetString(destination); }
public override void Prepare() { IntPtr ptr; OracleConnection.ExecutePermission.Demand(); Bid.ScopeEnter(out ptr, "<ora.OracleCommand.Prepare|API> %d#\n", this.ObjectID); try { if (this.ConnectionIsClosed) { throw System.Data.Common.ADP.ClosedConnectionError(); } if (System.Data.CommandType.Text == this.CommandType) { short num2; OciStatementHandle statementHandle = this.GetStatementHandle(); int closeCount = this._connection.CloseCount; string statementText = this.StatementText; int rc = TracedNativeMethods.OCIStmtPrepare(statementHandle, this.ErrorHandle, statementText, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, this.Connection); if (rc != 0) { this.Connection.CheckError(this.ErrorHandle, rc); } statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_STMT_TYPE, out num2, this.ErrorHandle); this._statementType = (OCI.STMT)num2; if (OCI.STMT.OCI_STMT_SELECT == this._statementType) { rc = TracedNativeMethods.OCIStmtExecute(this._connection.ServiceContextHandle, statementHandle, this.ErrorHandle, 0, OCI.MODE.OCI_DESCRIBE_ONLY); if (rc != 0) { this.Connection.CheckError(this.ErrorHandle, rc); } } if (statementHandle != this._preparedStatementHandle) { OciHandle.SafeDispose(ref this._preparedStatementHandle); } this._preparedStatementHandle = statementHandle; this._preparedAtCloseCount = closeCount; } else if (this._preparedStatementHandle != null) { OciHandle.SafeDispose(ref this._preparedStatementHandle); } } finally { Bid.ScopeLeave(ref ptr); } }
internal void GetRowid(OciStatementHandle statementHandle, OciErrorHandle errorHandle) { uint sizep = 0; int rc = TracedNativeMethods.OCIAttrGet(statementHandle, this, out sizep, OCI.ATTR.OCI_ATTR_ROWID, errorHandle); if (100 == rc) { base.Dispose(); } else if (rc != 0) { OracleException.Check(errorHandle, rc); } }
/// <include file='doc\OracleLob.uex' path='docs/doc[@for="OracleLob.Erase2"]/*' /> public long Erase( long offset, long amount ) { AssertObjectNotDisposed(); if (IsNull) { throw ADP.LobWriteInvalidOnNull(); } AssertAmountIsValid(amount, "amount"); AssertAmountIsEven(offset, "offset"); AssertPositionIsValid(); AssertConnectionIsOpen(); AssertTransactionExists(); if (offset < 0 || offset >= (long)UInt32.MaxValue) // MDAC 82575 { return(0); } UInt32 eraseAmount = (UInt32)AdjustOffsetToOracle(amount); UInt32 eraseOffset = (UInt32)AdjustOffsetToOracle(offset) + 1; // Oracle is 1 based, we are zero based. EnsureBuffering(false); // Erase (zero or space fill) bytes from the specified offset int rc = TracedNativeMethods.OCILobErase( ServiceContextHandle, ErrorHandle, Descriptor, ref eraseAmount, eraseOffset ); if (0 != rc) { Connection.CheckError(ErrorHandle, rc); } long bytesErased = AdjustOracleToOffset(eraseAmount); return(bytesErased); }
protected override bool ReleaseHandle() { IntPtr handle = base.handle; base.handle = IntPtr.Zero; if (IntPtr.Zero != handle) { TracedNativeMethods.OraMTSEnlCtxRel(handle); } if (this._serviceContextHandle != null) { this._serviceContextHandle.Release(); this._serviceContextHandle = null; } return(true); }