private void BindParameters(OciStatementHandle statement) { for (int p = 0; p < Parameters.Count; p++) { Parameters[p].Bind(statement, Connection, (uint)p); } }
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); }
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 void ReleaseStatementHandle(OciStatementHandle statementHandle) { if ((this.Connection.State != ConnectionState.Closed) && (this._preparedStatementHandle != statementHandle)) { OciHandle.SafeDispose(ref statementHandle); } }
private int ExecuteNonQueryInternal(OciStatementHandle statement, bool useAutoCommit) { moreResults = -1; if (preparedStatement == null) { PrepareStatement(statement); } bool isNonQuery = IsNonQuery(statement); BindParameters(statement); if (isNonQuery == true) { statement.ExecuteNonQuery(useAutoCommit); } else { statement.ExecuteQuery(false); } UpdateParameterValues(); int rowsAffected = statement.GetAttributeInt32(OciAttributeType.RowCount, ErrorHandle); return(rowsAffected); }
int ExecuteNonQuery() { moreResults = -1; AssertConnectionIsOpen(); AssertTransactionMatch(); AssertCommandTextIsSet(); bool useAutoCommit = false; if (Transaction != null) { Transaction.AttachToServiceContext(); } else { useAutoCommit = true; } OciStatementHandle statement = GetStatementHandle(); try { return(ExecuteNonQueryInternal(statement, useAutoCommit)); } finally { SafeDisposeHandle(statement); } }
public int ExecuteOracleNonQuery(out OracleString rowid) { moreResults = -1; AssertConnectionIsOpen(); AssertTransactionMatch(); AssertCommandTextIsSet(); bool useAutoCommit = false; if (Transaction != null) { Transaction.AttachToServiceContext(); } else { useAutoCommit = true; } OciStatementHandle statement = GetStatementHandle(); try { int retval = ExecuteNonQueryInternal(statement, useAutoCommit); OciRowIdDescriptor rowIdDescriptor = statement.GetAttributeRowIdDescriptor(ErrorHandle, Environment); string srowid = rowIdDescriptor.GetRowIdToString(ErrorHandle); rowid = new OracleString(srowid); rowIdDescriptor = null; return(retval); } finally { SafeDisposeHandle(statement); } }
private void SafeDisposeHandle(OciStatementHandle h) { if (h != null && h != preparedStatement) { h.Dispose(); } }
void PrepareStatement(OciStatementHandle statement) { if (commandType == CommandType.StoredProcedure) { StringBuilder sb = new StringBuilder(); if (Parameters.Count > 0) { foreach (OracleParameter parm in Parameters) { if (sb.Length > 0) { sb.Append(","); } sb.Append(parm.ParameterName + "=>:" + parm.ParameterName); } } string sql = "begin " + commandText + "(" + sb.ToString() + "); end;"; statement.Prepare(sql); } else // Text { statement.Prepare(commandText); } }
internal OracleColumn(OciStatementHandle statementHandle, int ordinal, OciErrorHandle errorHandle, OracleConnection connection) { this._ordinal = ordinal; this._describeHandle = statementHandle.GetDescriptor(this._ordinal, errorHandle); this._connection = connection; this._connectionCloseCount = connection.CloseCount; }
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); }
private void PropertyChanging() { if (this._preparedStatementHandle != null) { this._preparedStatementHandle.Dispose(); this._preparedStatementHandle = null; } }
internal static void SafeDispose(ref OciStatementHandle handle) { if (handle != null) { handle.Dispose(); } handle = null; }
void Prepare() { AssertConnectionIsOpen(); OciStatementHandle statement = GetStatementHandle(); PrepareStatement(statement); preparedStatement = statement; }
public object ExecuteOracleScalar() { moreResults = -1; object output = DBNull.Value; AssertConnectionIsOpen(); AssertTransactionMatch(); AssertCommandTextIsSet(); if (Transaction != null) { Transaction.AttachToServiceContext(); } OciStatementHandle statement = GetStatementHandle(); try { if (preparedStatement == null) { PrepareStatement(statement); } bool isNonQuery = IsNonQuery(statement); BindParameters(statement); if (isNonQuery == true) { ExecuteNonQueryInternal(statement, false); } else { statement.ExecuteQuery(false); if (statement.Fetch()) { OciDefineHandle defineHandle = (OciDefineHandle)statement.Values [0]; if (!defineHandle.IsNull) { output = defineHandle.GetOracleValue(Connection.SessionFormatProvider, Connection); } switch (defineHandle.DataType) { case OciDataType.Blob: case OciDataType.Clob: ((OracleLob)output).connection = Connection; break; } } UpdateParameterValues(); } return(output); } finally { SafeDisposeHandle(statement); } }
internal OracleDataReader(OracleCommand command, OciStatementHandle statement, bool extHasRows, CommandBehavior behavior) { this.command = command; this.hasRows = extHasRows; this.schemaTable = ConstructSchemaTable(); this.statement = statement; this.statementType = statement.GetStatementType(); this.behavior = behavior; }
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(); }
public OracleCommand(string commandText, OracleConnection connection, OracleTransaction tx) { moreResults = -1; preparedStatement = null; CommandText = commandText; Connection = connection; Transaction = tx; CommandType = CommandType.Text; UpdatedRowSource = UpdateRowSource.Both; DesignTimeVisible = true; parameters = new OracleParameterCollection(); }
private bool IsNonQuery(OciStatementHandle statementHandle) { // assumes Prepare() has been called prior to calling this function OciStatementType statementType = statementHandle.GetStatementType(); if (statementType.Equals(OciStatementType.Select)) { return(false); } return(true); }
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 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 OciStatementHandle GetStatementHandle() { AssertConnectionIsOpen(); if (preparedStatement != null) { return(preparedStatement); } OciStatementHandle h = (OciStatementHandle)Connection.Environment.Allocate(OciHandleType.Statement); h.ErrorHandle = Connection.ErrorHandle; h.Service = Connection.ServiceContext; h.Command = this; return(h); }
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)); }
private int ExecuteNonQueryInternal(bool needRowid, out OciRowidDescriptor rowidDescriptor) { OciStatementHandle statementHandle = null; int num = -1; try { try { ArrayList resultParameterOrdinals = new ArrayList(); statementHandle = this.GetStatementHandle(); this.Execute(statementHandle, CommandBehavior.Default, needRowid, out rowidDescriptor, out resultParameterOrdinals); if (resultParameterOrdinals != null) { num = 0; foreach (int num2 in resultParameterOrdinals) { OracleParameter parameter = this._parameterCollection[num2]; if (OracleType.Cursor != parameter.OracleType) { num += (int)parameter.Value; } } return(num); } if (OCI.STMT.OCI_STMT_SELECT != this._statementType) { statementHandle.GetAttribute(OCI.ATTR.OCI_ATTR_ROW_COUNT, out num, this.ErrorHandle); } return(num); } finally { if (statementHandle != null) { this.ReleaseStatementHandle(statementHandle); } } } catch { throw; } return(num); }
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); }
public override bool NextResult() { ValidateState(); if (statement == null) { return(false); } statement.Dispose(); statement = null; statement = command.GetNextResult(); if (statement == null) { return(false); } return(true); }
void Close() { if (!isClosed) { GetRecordsAffected(); if (command != null) { command.CloseDataReader(); } } if (statement != null) { statement.Dispose(); statement = null; } //if (schemaTable != null) { // schemaTable.Dispose (); // schemaTable = null; //} isClosed = true; }
bool NextResult() { ValidateState(); if (statement == null) { return(false); } statement.Dispose(); statement = null; statement = command.GetNextResult(); if (statement == null) { return(false); } hasRows = true; return(true); }
void Close() { if (!isClosed) { GetRecordsAffected(); if (command != null) { command.CloseDataReader(); } } if (statement != null) { statement.Dispose(); statement = null; } #if NET_2_0 if (schemaTable != null) { schemaTable.Dispose(); schemaTable = null; } #endif isClosed = true; }
OracleDataReader ExecuteReader(CommandBehavior behavior) { AssertConnectionIsOpen(); AssertTransactionMatch(); AssertCommandTextIsSet(); moreResults = -1; bool hasRows = false; this.behavior = behavior; if (Transaction != null) { Transaction.AttachToServiceContext(); } OciStatementHandle statement = GetStatementHandle(); OracleDataReader rd = null; try { if (preparedStatement == null) { PrepareStatement(statement); } else { preparedStatement = null; // OracleDataReader releases the statement handle } bool isNonQuery = IsNonQuery(statement); BindParameters(statement); if (isNonQuery) { ExecuteNonQueryInternal(statement, false); } else { if ((behavior & CommandBehavior.SchemaOnly) != 0) { statement.ExecuteQuery(true); } else { hasRows = statement.ExecuteQuery(false); } UpdateParameterValues(); } if (Parameters.Count > 0) { for (int p = 0; p < Parameters.Count; p++) { OracleParameter parm = Parameters[p]; if (parm.OracleType.Equals(OracleType.Cursor)) { if (parm.Direction != ParameterDirection.Input) { rd = (OracleDataReader)parm.Value; break; } } } } if (rd == null) { rd = new OracleDataReader(this, statement, hasRows, behavior); } } finally { if (statement != null && rd == null) { statement.Dispose(); } } return(rd); }