internal OracleDataReader(OracleConnection connection, OciStatementHandle statementHandle) { this.ObjectID = Interlocked.Increment(ref _objectTypeCount); this._commandBehavior = CommandBehavior.Default; this._statementHandle = statementHandle; this._connection = connection; this._connectionCloseCount = this._connection.CloseCount; this._recordsAffected = -1; this.FillColumnInfo(); }
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); } }
public OciStatementHandle CreateStatement() { OciStatementHandle statement = (OciStatementHandle)environment.Allocate(OciHandleType.Statement); if (statement == null) { OciErrorInfo info = environment.HandleError(); throw new OracleException(info.ErrorCode, info.ErrorMessage); } statement.ErrorHandle = error; statement.Service = service; return(statement); }
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); } }
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; }
internal OracleDataReader(OracleCommand command, OciStatementHandle statementHandle, string statementText, CommandBehavior commandBehavior) { this.ObjectID = Interlocked.Increment(ref _objectTypeCount); this._commandBehavior = commandBehavior; this._statementHandle = statementHandle; this._connection = command.Connection; this._connectionCloseCount = this._connection.CloseCount; this._columnInfo = null; if (OCI.STMT.OCI_STMT_SELECT == command.StatementType) { this.FillColumnInfo(); this._recordsAffected = -1; if (this.IsCommandBehavior(CommandBehavior.SchemaOnly)) { this._endOfData = true; } } else { this._statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_ROW_COUNT, out this._recordsAffected, this.ErrorHandle); this._endOfData = true; this._hasRows = 1; } this._statementText = statementText; this._closeConnectionToo = this.IsCommandBehavior(CommandBehavior.CloseConnection); if (CommandType.Text == command.CommandType) { this._keyInfoRequested = this.IsCommandBehavior(CommandBehavior.KeyInfo); } }
private bool NextResultInternal() { this.Cleanup(); if ((this._refCursorDataReaders == null) || (this._nextRefCursor >= this._refCursorDataReaders.Length)) { this._endOfData = true; this._hasRows = 1; return false; } if (this._nextRefCursor > 0) { this._refCursorDataReaders[this._nextRefCursor - 1].Dispose(); this._refCursorDataReaders[this._nextRefCursor - 1] = null; } OciStatementHandle handle = this._statementHandle; this._statementHandle = this._refCursorDataReaders[this._nextRefCursor]._statementHandle; OciHandle.SafeDispose(ref handle); this._connection = this._refCursorDataReaders[this._nextRefCursor]._connection; this._connectionCloseCount = this._refCursorDataReaders[this._nextRefCursor]._connectionCloseCount; this._hasRows = this._refCursorDataReaders[this._nextRefCursor]._hasRows; this._recordsAffected = this._refCursorDataReaders[this._nextRefCursor]._recordsAffected; this._columnInfo = this._refCursorDataReaders[this._nextRefCursor]._columnInfo; this._rowBufferLength = this._refCursorDataReaders[this._nextRefCursor]._rowBufferLength; this._rowsToPrefetch = this._refCursorDataReaders[this._nextRefCursor]._rowsToPrefetch; this._nextRefCursor++; this._endOfData = false; this._isLastBuffer = false; this._rowsTotal = 0; return true; }
private void ReleaseStatementHandle(OciStatementHandle statementHandle) { if ((this.Connection.State != ConnectionState.Closed) && (this._preparedStatementHandle != statementHandle)) { OciHandle.SafeDispose(ref statementHandle); } }
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); } }
private void PropertyChanging() { if (this._preparedStatementHandle != null) { this._preparedStatementHandle.Dispose(); this._preparedStatementHandle = null; } }
private OciStatementHandle GetStatementHandle() { if (this.ConnectionIsClosed) { throw System.Data.Common.ADP.ClosedConnectionError(); } if (this._preparedStatementHandle != null) { if (this._connection.CloseCount == this._preparedAtCloseCount) { return this._preparedStatementHandle; } this._preparedStatementHandle.Dispose(); this._preparedStatementHandle = null; } return new OciStatementHandle(this.ServiceContextHandle); }
internal static OracleString GetPersistedRowid(OracleConnection connection, OciRowidDescriptor rowidHandle) { OracleString @null = OracleString.Null; if (rowidHandle != null) { OciErrorHandle errorHandle = connection.ErrorHandle; NativeBuffer scratchBuffer = connection.GetScratchBuffer(0xf82); bool success = false; bool flag = false; RuntimeHelpers.PrepareConstrainedRegions(); try { int num; scratchBuffer.DangerousAddRef(ref success); if (OCI.ClientVersionAtLeastOracle9i) { int length = scratchBuffer.Length; num = TracedNativeMethods.OCIRowidToChar(rowidHandle, scratchBuffer, ref length, errorHandle); if (num != 0) { connection.CheckError(errorHandle, num); } return new OracleString(scratchBuffer.PtrToStringAnsi(0, length)); } rowidHandle.DangerousAddRef(ref flag); OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle; OciStatementHandle stmtp = new OciStatementHandle(serviceContextHandle); string stmt = "begin :rowid := :rdesc; end;"; int offset = 0; int num6 = 4; int num5 = 8; int num3 = 12; int num2 = 0x10; int num4 = 20; try { IntPtr ptr; IntPtr ptr2; num = TracedNativeMethods.OCIStmtPrepare(stmtp, errorHandle, stmt, OCI.SYNTAX.OCI_NTV_SYNTAX, OCI.MODE.OCI_DEFAULT, connection); if (num != 0) { connection.CheckError(errorHandle, num); } scratchBuffer.WriteIntPtr(num5, rowidHandle.DangerousGetHandle()); scratchBuffer.WriteInt32(offset, 0); scratchBuffer.WriteInt32(num6, 4); scratchBuffer.WriteInt32(num3, 0); scratchBuffer.WriteInt32(num2, 0xf6e); num = TracedNativeMethods.OCIBindByName(stmtp, out ptr2, errorHandle, "rowid", 5, scratchBuffer.DangerousGetDataPtr(num4), 0xf6e, OCI.DATATYPE.VARCHAR2, scratchBuffer.DangerousGetDataPtr(num3), scratchBuffer.DangerousGetDataPtr(num2), OCI.MODE.OCI_DEFAULT); if (num != 0) { connection.CheckError(errorHandle, num); } num = TracedNativeMethods.OCIBindByName(stmtp, out ptr, errorHandle, "rdesc", 5, scratchBuffer.DangerousGetDataPtr(num5), 4, OCI.DATATYPE.ROWID_DESC, scratchBuffer.DangerousGetDataPtr(offset), scratchBuffer.DangerousGetDataPtr(num6), OCI.MODE.OCI_DEFAULT); if (num != 0) { connection.CheckError(errorHandle, num); } num = TracedNativeMethods.OCIStmtExecute(serviceContextHandle, stmtp, errorHandle, 1, OCI.MODE.OCI_DEFAULT); if (num != 0) { connection.CheckError(errorHandle, num); } if (scratchBuffer.ReadInt16(num3) == -1) { return @null; } @null = new OracleString(scratchBuffer, num4, num2, MetaType.GetMetaTypeForType(OracleType.RowId), connection, false, true); GC.KeepAlive(rowidHandle); } finally { OciHandle.SafeDispose(ref stmtp); } } finally { if (flag) { rowidHandle.DangerousRelease(); } if (success) { scratchBuffer.DangerousRelease(); } } } return @null; }
public OracleDataReader ExecuteReader(CommandBehavior behavior) { OracleDataReader reader2; IntPtr ptr; OracleConnection.ExecutePermission.Demand(); Bid.ScopeEnter(out ptr, "<ora.OracleCommand.ExecuteReader|API> %d#, behavior=%d{ds.CommandBehavior}\n", this.ObjectID, (int) behavior); try { OciStatementHandle statementHandle = null; OracleDataReader reader = null; ArrayList resultParameterOrdinals = null; try { statementHandle = this.GetStatementHandle(); string statementText = this.Execute(statementHandle, behavior, out resultParameterOrdinals); if (statementHandle == this._preparedStatementHandle) { this._preparedStatementHandle = null; } if (resultParameterOrdinals == null) { reader = new OracleDataReader(this, statementHandle, statementText, behavior); } else { reader = new OracleDataReader(this, resultParameterOrdinals, statementText, behavior); } } finally { if ((statementHandle != null) && ((reader == null) || (resultParameterOrdinals != null))) { this.ReleaseStatementHandle(statementHandle); } } reader2 = reader; } finally { Bid.ScopeLeave(ref ptr); } return reader2; }
internal string Execute(OciStatementHandle statementHandle, CommandBehavior behavior, bool needRowid, out OciRowidDescriptor rowidDescriptor, out ArrayList resultParameterOrdinals) { if (this.ConnectionIsClosed) { throw System.Data.Common.ADP.ClosedConnectionError(); } if ((this._transaction == null) && (this.Connection.Transaction != null)) { throw System.Data.Common.ADP.TransactionRequired(); } if (((this._transaction != null) && (this._transaction.Connection != null)) && (this.Connection != this._transaction.Connection)) { throw System.Data.Common.ADP.TransactionConnectionMismatch(); } rowidDescriptor = null; this.Connection.RollbackDeadTransaction(); int rc = 0; NativeBuffer parameterBuffer = null; bool success = false; bool[] flagArray = null; SafeHandle[] handleArray = null; OracleParameterBinding[] bindingArray = null; string stmt = null; resultParameterOrdinals = null; RuntimeHelpers.PrepareConstrainedRegions(); try { int num8; short num13; if (this._preparedStatementHandle != statementHandle) { stmt = this.StatementText; rc = TracedNativeMethods.OCIStmtPrepare(statementHandle, this.ErrorHandle, stmt, 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 num13, this.ErrorHandle); this._statementType = (OCI.STMT) num13; if (OCI.STMT.OCI_STMT_SELECT != this._statementType) { num8 = 1; } else { num8 = 0; if (CommandBehavior.SingleRow != behavior) { statementHandle.SetAttribute(OCI.ATTR.OCI_ATTR_PREFETCH_ROWS, 0, this.ErrorHandle); statementHandle.SetAttribute(OCI.ATTR.OCI_ATTR_PREFETCH_MEMORY, 0, this.ErrorHandle); } } OCI.MODE mode = OCI.MODE.OCI_DEFAULT; if (num8 == 0) { if (IsBehavior(behavior, CommandBehavior.SchemaOnly)) { mode |= OCI.MODE.OCI_DESCRIBE_ONLY; } } else if (this._connection.TransactionState == TransactionState.AutoCommit) { mode |= OCI.MODE.OCI_COMMIT_ON_SUCCESS; } else if (TransactionState.GlobalStarted != this._connection.TransactionState) { this._connection.TransactionState = TransactionState.LocalStarted; } if ((((mode & OCI.MODE.OCI_DESCRIBE_ONLY) == OCI.MODE.OCI_DEFAULT) && (this._parameterCollection != null)) && (this._parameterCollection.Count > 0)) { int offset = 0; int count = this._parameterCollection.Count; flagArray = new bool[count]; handleArray = new SafeHandle[count]; bindingArray = new OracleParameterBinding[count]; for (int i = 0; i < count; i++) { bindingArray[i] = new OracleParameterBinding(this, this._parameterCollection[i]); bindingArray[i].PrepareForBind(this._connection, ref offset); if ((OracleType.Cursor == this._parameterCollection[i].OracleType) || (0 < this._parameterCollection[i].CommandSetResult)) { if (resultParameterOrdinals == null) { resultParameterOrdinals = new ArrayList(); } resultParameterOrdinals.Add(i); } } parameterBuffer = new NativeBuffer_ParameterBuffer(offset); parameterBuffer.DangerousAddRef(ref success); for (int j = 0; j < count; j++) { bindingArray[j].Bind(statementHandle, parameterBuffer, this._connection, ref flagArray[j], ref handleArray[j]); } } rc = TracedNativeMethods.OCIStmtExecute(this.ServiceContextHandle, statementHandle, this.ErrorHandle, num8, mode); if (rc != 0) { this.Connection.CheckError(this.ErrorHandle, rc); } if (bindingArray != null) { int length = bindingArray.Length; for (int k = 0; k < length; k++) { bindingArray[k].PostExecute(parameterBuffer, this._connection); bindingArray[k].Dispose(); bindingArray[k] = null; } bindingArray = null; } if (!needRowid || ((mode & OCI.MODE.OCI_DESCRIBE_ONLY) != OCI.MODE.OCI_DEFAULT)) { return stmt; } switch (this._statementType) { case OCI.STMT.OCI_STMT_UPDATE: case OCI.STMT.OCI_STMT_DELETE: case OCI.STMT.OCI_STMT_INSERT: rowidDescriptor = statementHandle.GetRowid(this.EnvironmentHandle, this.ErrorHandle); return stmt; } rowidDescriptor = null; } finally { if (success) { parameterBuffer.DangerousRelease(); } if (parameterBuffer != null) { parameterBuffer.Dispose(); parameterBuffer = null; } if (bindingArray != null) { int num10 = bindingArray.Length; for (int m = 0; m < num10; m++) { if (bindingArray[m] != null) { bindingArray[m].Dispose(); bindingArray[m] = null; } } bindingArray = null; } if ((flagArray != null) && (handleArray != null)) { int num9 = flagArray.Length; for (int n = 0; n < num9; n++) { if (flagArray[n]) { handleArray[n].DangerousRelease(); } } } } return stmt; }
internal string Execute(OciStatementHandle statementHandle, CommandBehavior behavior, out ArrayList resultParameterOrdinals) { OciRowidDescriptor descriptor; return this.Execute(statementHandle, behavior, false, out descriptor, out resultParameterOrdinals); }