private SqlDataReader RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, bool returnStream, bool async) { bool inSchema = CommandBehavior.Default != (cmdBehavior & CommandBehavior.SchemaOnly); SqlDataReader ds = null; _SqlRPC rpc = null; string text = null; bool flag2 = true; try { this.GetStateObject(); if (this.BatchRPCMode) { this._stateObj.Parser.TdsExecuteRPC(this._SqlRPCBatchArray, this.CommandTimeout, inSchema, this.Notification, this._stateObj, System.Data.CommandType.StoredProcedure == this.CommandType); } else if ((System.Data.CommandType.Text == this.CommandType) && (this.GetParameterCount(this._parameters) == 0)) { if (returnStream) { Bid.Trace("<sc.SqlCommand.ExecuteReader|INFO> %d#, Command executed as SQLBATCH.\n", this.ObjectID); } string str2 = this.GetCommandText(cmdBehavior) + this.GetResetOptionsString(cmdBehavior); this._stateObj.Parser.TdsExecuteSQLBatch(str2, this.CommandTimeout, this.Notification, this._stateObj); } else if (System.Data.CommandType.Text == this.CommandType) { if (this.IsDirty) { if (this._execType == EXECTYPE.PREPARED) { this._hiddenPrepare = true; } this.InternalUnprepare(false); this.IsDirty = false; } if (this._execType == EXECTYPE.PREPARED) { rpc = this.BuildExecute(inSchema); } else if (this._execType == EXECTYPE.PREPAREPENDING) { rpc = this.BuildPrepExec(cmdBehavior); this._execType = EXECTYPE.PREPARED; this._activeConnection.AddPreparedCommand(this); this._inPrepare = true; } else { this.BuildExecuteSql(cmdBehavior, null, this._parameters, ref rpc); } if (this._activeConnection.IsShiloh) { rpc.options = 2; } if (returnStream) { Bid.Trace("<sc.SqlCommand.ExecuteReader|INFO> %d#, Command executed as RPC.\n", this.ObjectID); } this._stateObj.Parser.TdsExecuteRPC(this._rpcArrayOf1, this.CommandTimeout, inSchema, this.Notification, this._stateObj, System.Data.CommandType.StoredProcedure == this.CommandType); } else { this.BuildRPC(inSchema, this._parameters, ref rpc); text = this.GetSetOptionsString(cmdBehavior); if (returnStream) { Bid.Trace("<sc.SqlCommand.ExecuteReader|INFO> %d#, Command executed as RPC.\n", this.ObjectID); } if (text != null) { this._stateObj.Parser.TdsExecuteSQLBatch(text, this.CommandTimeout, this.Notification, this._stateObj); this._stateObj.Parser.Run(RunBehavior.UntilDone, this, null, null, this._stateObj); text = this.GetResetOptionsString(cmdBehavior); } this._activeConnection.CheckSQLDebug(); this._stateObj.Parser.TdsExecuteRPC(this._rpcArrayOf1, this.CommandTimeout, inSchema, this.Notification, this._stateObj, System.Data.CommandType.StoredProcedure == this.CommandType); } if (returnStream) { ds = new SqlDataReader(this, cmdBehavior); } if (async) { this._activeConnection.GetOpenTdsConnection().IncrementAsyncCount(); this.cachedAsyncState.SetAsyncReaderState(ds, runBehavior, text); return ds; } this.FinishExecuteReader(ds, runBehavior, text); return ds; } catch (Exception exception) { flag2 = ADP.IsCatchableExceptionType(exception); throw; } finally { if (flag2 && !async) { this.PutStateObject(); } } return ds; }
private void InternalUnprepare(bool isClosing) { if (this.IsShiloh) { this._execType = EXECTYPE.PREPAREPENDING; if (isClosing) { this._prepareHandle = -1; } } else { if (this._prepareHandle != -1) { this.BuildUnprepare(); this._stateObj.Parser.TdsExecuteRPC(this._rpcArrayOf1, this.CommandTimeout, false, null, this._stateObj, System.Data.CommandType.StoredProcedure == this.CommandType); this._stateObj.Parser.Run(RunBehavior.UntilDone, this, null, null, this._stateObj); this._prepareHandle = -1; } this._execType = EXECTYPE.UNPREPARED; } this._cachedMetaData = null; if (!isClosing) { this._activeConnection.RemovePreparedCommand(this); } Bid.Trace("<sc.SqlCommand.Prepare|INFO> %d#, Command unprepared.\n", this.ObjectID); }
private void FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, string resetOptionsString) { this.NotifyDependency(); if (runBehavior == RunBehavior.UntilDone) { try { this._stateObj.Parser.Run(RunBehavior.UntilDone, this, ds, null, this._stateObj); } catch (Exception exception2) { if (ADP.IsCatchableExceptionType(exception2)) { if (this._inPrepare) { this._inPrepare = false; this.IsDirty = true; this._execType = EXECTYPE.PREPAREPENDING; } if (ds != null) { ds.Close(); } } throw; } } if (ds != null) { ds.Bind(this._stateObj); this._stateObj = null; ds.ResetOptionsString = resetOptionsString; this._activeConnection.AddWeakReference(ds, 1); try { this._cachedMetaData = ds.MetaData; ds.IsInitialized = true; } catch (Exception exception) { if (ADP.IsCatchableExceptionType(exception)) { if (this._inPrepare) { this._inPrepare = false; this.IsDirty = true; this._execType = EXECTYPE.PREPAREPENDING; } ds.Close(); } throw; } } }
private SqlDataReader InternalPrepare(CommandBehavior behavior) { SqlDataReader dataStream = null; if (this.IsDirty) { this.Unprepare(false); this.IsDirty = false; } if (this._activeConnection.IsShiloh) { this._execType = EXECTYPE.PREPAREPENDING; } else { this.BuildPrepare(behavior); this._inPrepare = true; dataStream = new SqlDataReader(this, behavior); try { this._stateObj.Parser.TdsExecuteRPC(this._rpcArrayOf1, this.CommandTimeout, false, null, this._stateObj, System.Data.CommandType.StoredProcedure == this.CommandType); this._stateObj.Parser.Run(RunBehavior.UntilDone, this, dataStream, null, this._stateObj); } catch { this._inPrepare = false; throw; } dataStream.Bind(this._stateObj); this._execType = EXECTYPE.PREPARED; Bid.Trace("<sc.SqlCommand.Prepare|INFO> %d#, Command prepared.\n", this.ObjectID); } if (this.Statistics != null) { this.Statistics.SafeIncrement(ref this.Statistics._prepares); } this._activeConnection.AddPreparedCommand(this); return dataStream; }
public void ExecuteText(EXECTYPE exec_when, string text) { switch (exec_when) { case EXECTYPE.EXEC_NOW: if (text != null && text.Length > 0) { ExecuteString(text); } else { Execute(); // Printf } break; case EXECTYPE.EXEC_APPEND: AddText(text); break; case EXECTYPE.EXEC_INSERT: InsertText(text); break; default: System.Console.WriteLine("Something is wrong"); break; } }