public override DbDataReader ExecuteReader(string sql, CommandType cmdType, CommandBehavior cmdBehavior, params DbParameter[] cmdParams) { DbConnection conn = this.CreateConnection(); DbCommand cmd = this.CreateCommand(sql, cmdType, cmdParams); this.PrepareCmd(cmd, conn); return this.ExecuteReader(cmd, cmdBehavior); }
public IDataReader ExecuteReader(CommandBehavior behavior) { var reliableConnection = (ReliableSqlConnection) this.Connection; return this.command.ExecuteReaderWithRetry(behavior, reliableConnection.CommandRetryPolicy, reliableConnection.ConnectionRetryPolicy); }
public SqlCommand GetDBCommand(SqlConnection sqlcn, String CmdText, CommandType CmdType, CommandBehavior CmdBehavior, SqlParameter[] sqlParam) { SqlCommand sqlcmd = null; try { sqlcmd = new SqlCommand(CmdText, sqlcn); sqlcmd.CommandType = CmdType; sqlcmd.CommandTimeout = GetCommandTimeout(); Utilities.DebugLogging.Log("CONNECTION STRING " + sqlcn.ConnectionString); Utilities.DebugLogging.Log("COMMAND TEXT " + CmdText); Utilities.DebugLogging.Log("COMMAND TYPE " + CmdType.ToString()); if (sqlParam != null) Utilities.DebugLogging.Log("NUMBER OF PARAMS " + sqlParam.Length); AddSQLParameters(sqlcmd, sqlParam); } catch (Exception ex) { Utilities.DebugLogging.Log(ex.Message); Utilities.DebugLogging.Log(ex.StackTrace); } return sqlcmd; }
internal OdbcDataReader(OdbcCommand command, CMDWrapper cmdWrapper, CommandBehavior commandbehavior) { this.command = command; this._commandBehavior = commandbehavior; this._cmdText = command.CommandText; this._cmdWrapper = cmdWrapper; }
internal OracleDataReader(OracleCommand command, ArrayList refCursorParameterOrdinals, string statementText, CommandBehavior commandBehavior) { this.ObjectID = Interlocked.Increment(ref _objectTypeCount); this._commandBehavior = commandBehavior; this._statementText = statementText; this._closeConnectionToo = this.IsCommandBehavior(CommandBehavior.CloseConnection); if (CommandType.Text == command.CommandType) { this._keyInfoRequested = this.IsCommandBehavior(CommandBehavior.KeyInfo); } ArrayList list = new ArrayList(); int num2 = 0; OracleDataReader reader = null; for (int i = 0; i < refCursorParameterOrdinals.Count; i++) { int num3 = (int) refCursorParameterOrdinals[i]; OracleParameter parameter = command.Parameters[num3]; if (OracleType.Cursor == parameter.OracleType) { reader = (OracleDataReader) parameter.Value; reader._recordsAffected = num2; list.Add(reader); parameter.Value = DBNull.Value; } else { num2 += (int) parameter.Value; } } this._refCursorDataReaders = new OracleDataReader[list.Count]; list.CopyTo(this._refCursorDataReaders); this._nextRefCursor = 0; this.NextResultInternal(); }
public IDataReader ExecuteDataReader(Saga.Data.IQueryProvider query, CommandBehavior behavior) { MySqlConnection connection = ConnectionPool.Request(); MySqlCommand command = new MySqlCommand(); MySqlDataReader reader = null; try { command.CommandText = query.CmdText; command.Connection = connection; foreach (KeyValuePair<string, object> pair in query.Parameters) { command.Parameters.AddWithValue(pair.Key, pair.Value); } return command.ExecuteReader(behavior); } catch (Exception e) { __dbtracelog.WriteError("Database", e.Message); return null; } finally { //ALWAYS CLOSE THE CONNECTION AND REPOOL THE ITEMS if (reader != null && reader.IsClosed == false) reader.Close(); ConnectionPool.Release(connection); } }
public static void ExecuteReader(SqlConnection connectionRef, string procedureName, SqlParameter[] parameters, CommandBehavior behavior, Action<SqlDataReader> readerCallback) { using (SqlCommand command = new SqlCommand(procedureName, connectionRef)) { command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 180; if (parameters.Length > 0) { foreach (SqlParameter param in parameters) { command.Parameters.Add(param); } } SqlDataReader reader = command.ExecuteReader(behavior); try { readerCallback(reader); } finally { if (reader != null) reader.Close(); } } }
/// Runs a stored procedure /// </summary> /// <param name="procedureName"></param> /// <param name="QueryParameters"></param> /// <param name="OutputParameters"></param> /// <param name="DB"></param> public virtual void RunStoredProcedure(IDbConnection connection, string procedureName, IEnumerable<IDataParameter> inputParameters, IEnumerable<IDataParameter> outputParameters, IDbTransaction transaction, CommandBehavior commandBehavior) { SqlCommand cmd = new SqlCommand(procedureName, (SqlConnection)connection); cmd.CommandType = CommandType.StoredProcedure; ProcessSql(procedureName, inputParameters); foreach (var parm in inputParameters) { cmd.Parameters.Add(parm); } if (outputParameters != null) { foreach (SqlParameter parm in outputParameters) { parm.Direction = ParameterDirection.Output; //OutputParameters[i].Value = -1; cmd.Parameters.Add(parm); } } ExecuteSqlFinal(new Action(() => { cmd.ExecuteScalar(); })); if (commandBehavior == CommandBehavior.CloseConnection) { connection.Close(); } OnQueryComplete(); }
public static DbDataReader ExecuteProfilableReader(this DbCommand dbCommand, CommandBehavior commandBehavior = CommandBehavior.Default) { if (!(dbCommand is ProfilableDbCommand)) return (new ProfilableDbCommand(dbCommand, dbCommand.Connection)).ExecuteReader(commandBehavior); else return dbCommand.ExecuteReader(commandBehavior); }
public static Task<SqlDataReader> ExecuteReaderAsyncWithRetry( SqlCommand command, CommandBehavior behavior, IRetryPolicy retryPolicy) { return retryPolicy.ExecuteAsyncWithRetry(() => command.ExecuteReaderAsync(behavior)); }
public IDataReader ExecuteReader(CommandBehavior behavior) { using (ExecuteHelper.Begin(dur => context.FireExecuteEvent(this, string.Format("ExecuteReader({0})", behavior), dur))) { return command.ExecuteReader(behavior); } }
public virtual int Count(IDbConnection connection, string query, IEnumerable<IDataParameter> parameters = null, CommandBehavior commandBehavior = CommandBehavior.Default) { ValidateQueryType(query, "select"); string countQuery = "SELECT COUNT(*) FROM (" + query + ") q"; return RunQueryScalar(connection,countQuery, parameters,null,commandBehavior); }
public static Task<SqlDataReader> ExecuteReaderAsyncWithRetry( this SqlCommand command, CommandBehavior behavior, CancellationToken cancellationToken) { return ExecuteReaderAsyncWithRetry(command, behavior, cancellationToken, SqlRetryPolicyFactory.DefaultSqlRetryPolicy); }
public virtual IDataReader RunQuery(IDbConnection connection, string query, IEnumerable<IDataParameter> parameters = null, int firstRow=-1, int totalRows=-1, IDbTransaction transaction = null, CommandBehavior commandBehavior = CommandBehavior.Default) { IDataReader dataReader = null; string sql; if (firstRow >= 0 || totalRows >= 0) { sql = GetQueryForRows(query, firstRow, totalRows); } else { sql = query; } sql = ProcessSql(sql,parameters); using (IDbCommand cmd = GetCommand(connection, sql, parameters, transaction)) { ExecuteSqlFinal(new Action(() => { dataReader = cmd.ExecuteReader(commandBehavior); })); cmd.Parameters.Clear(); } OnQueryComplete(); return dataReader; }
/// <summary> /// Initiates the asynchronous execution of the Transact-SQL statement or stored procedure using one of the /// <see cref="CommandBehavior"/> values, and retrieving one or more result sets from the server. /// </summary> /// <param name="command">The <see cref="SqlCommand"/> to be executed.</param> /// <param name="behavior">One of the <see cref="CommandBehavior"/> values.</param> /// <returns>A singleton observable sequence containing a <see cref="SqlDataReader"/> object that provides access to /// the result sets of the specified <paramref name="command"/>.</returns> public static IObservable<SqlDataReader> ExecuteReaderObservable(this SqlCommand command, CommandBehavior behavior) { Contract.Requires(command != null); Contract.Ensures(Contract.Result<IObservable<SqlDataReader>>() != null); return Observable.StartAsync(cancel => command.ExecuteReaderAsync(behavior, cancel)); }
public static Task<SqlDataReader> ExecuteReaderSyncOrAsync(this SqlCommand command, CommandBehavior cb, CancellationToken token, Random rnd) { return AsyncUtils.SyncOrAsyncMethod( () => command.ExecuteReader(cb), () => command.ExecuteReaderAsync(cb, token), AsyncUtils.ChooseSyncAsyncMode(rnd) ); }
public SqlCommand GetDBCommand(SqlConnection sqlcn, String CmdText, CommandType CmdType, CommandBehavior CmdBehavior, SqlParameter[] sqlParam) { SqlCommand sqlcmd = new SqlCommand(CmdText, sqlcn); sqlcmd.CommandType = CmdType; AddSQLParameters(sqlcmd, sqlParam); return sqlcmd; }
public virtual SqlDataReader RunStoredProcedureDataset(IDbConnection connection, string procedureName, IEnumerable<IDataParameter> queryParameters, IDbTransaction transaction, CommandBehavior commandBehavior) { return RunStoredProcedureDataset(connection,procedureName, queryParameters, null,transaction, commandBehavior); }
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { string query, verb, url; ParseCommantText(out query, out verb, out url); var json = ElasticDbConnection.ExecuteRequest(verb, url, query); var reader = new ElasticDbDataReader(json, ElasticDbConnection.ResultParserTypes); return reader; }
public override IAsyncResult BeginExecuteReader(AsyncCallback callback, object state, CommandBehavior behavior) { if (IsTraced) { Tracer.Instance.EnterFunction(TraceClass, "AsyncExecuteReader", new string[] { "CommandText", "callback", "state", "behavior", "Parameters" }, new object[] { this.CommandText, callback, state, behavior, base.GetTraceParameters(true) }); } return ((SqlCommand) base.DbCommand).BeginExecuteReader(callback, state, behavior); }
public MockDataReader(MockDataCommand command, CommandBehavior behavior) : base() { if (command == null) throw new ArgumentNullException(nameof(command)); this.Command = command; this.CommandBehavior = behavior; }
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { RecordingConnection.LogCommand(CommandText); if (!RecordingConnection.CanExecute) return null; return InnerCommand.ExecuteReader(behavior); }
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; }
/// <summary> /// Executes the command text against the connection. /// </summary> /// <returns> /// A <see cref="T:System.Data.Common.DbDataReader"/>. /// </returns> /// <param name="behavior">An instance of <see cref="T:System.Data.CommandBehavior"/>.</param> protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { _connection.MockDatabase.Record(this); if (_connection != null && _connection.DummyDataTable != null) { return _connection.DummyDataTable.CreateDataReader(); } return new MockDataReader(Enumerable.Empty<IDataRecord>()); }
internal SQLiteDataReader(SQLiteCommand pCmd, CommandBehavior cmdBehavior) { if (pCmd == null) throw new ArgumentNullException(); if( pCmd.GetSQLStatementCount() <= 0 ) throw new ArgumentException("CommandText doesn't contain any SQL statements in SQLiteCommand"); mpCmd = pCmd; mCmdBehavior = cmdBehavior; }
/// <summary> /// The constructor for the data reader, each EntityDataReader must always be associated with a EntityCommand and an underlying /// DbDataReader. It is expected that EntityDataReader only has a reference to EntityCommand and doesn't assume responsibility /// of cleaning the command object, but it does assume responsibility of cleaning up the store data reader object. /// </summary> internal EntityDataReader(EntityCommand command, DbDataReader storeDataReader, CommandBehavior behavior) { Debug.Assert(command != null && storeDataReader != null); _command = command; _storeDataReader = storeDataReader; _storeExtendedDataRecord = storeDataReader as IExtendedDataRecord; _behavior = behavior; }
internal OdbcDataReader(OdbcCommand command, CMDWrapper cmdWrapper, CommandBehavior commandbehavior) { OdbcConnection.VerifyExecutePermission(); Debug.Assert(command != null, "Command null on OdbcDataReader ctor"); this.command = command; _commandBehavior = commandbehavior; _cmdText = command.CommandText; // get a copy in case the command text on the command is changed ... _cmdWrapper = cmdWrapper; }
/* * Because the user should not be able to directly create a * DataReader object, the constructors are * marked as internal. */ internal MySqlDataReader(MySqlCommand cmd, PreparableStatement statement, CommandBehavior behavior) { this.command = cmd; connection = (MySqlConnection)command.Connection; commandBehavior = behavior; driver = connection.driver; affectedRows = -1; this.statement = statement; }
/// <summary> /// Creates a new <see cref="DbCommandBaseInterceptionContext" /> by copying state from the given /// interception context. Also see <see cref="DbInterceptionContext.Clone" /> /// </summary> /// <param name="copyFrom">The context from which to copy state.</param> public DbCommandBaseInterceptionContext(DbInterceptionContext copyFrom) : base(copyFrom) { var asThisType = copyFrom as DbCommandBaseInterceptionContext; if (asThisType != null) { _commandBehavior = asThisType._commandBehavior; } }
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { LINQPadDbController.DbCommandExecuting(this); Stopwatch stopwatch = Stopwatch.StartNew(); DbDataReader reader = this._proxy.ExecuteReader(behavior); stopwatch.Stop(); LINQPadDbController.DbCommandFinished(stopwatch.Elapsed); return reader; }
public static Query ExecuteReader(string sql, string connectionString, CommandBehavior sqlBehavior) { return(new OleDBQuery(sql, connectionString, sqlBehavior)); }
IDataReader IDbCommand.ExecuteReader(CommandBehavior behavior) { return(ExecuteReader(behavior)); }
public void ExecuteReader(IDbCommand command, CommandBehavior behavior) { using IDataReader reader = command.ExecuteReader(behavior); }
internal async Task <DbDataReader> ExecuteReaderAsync( CommandBehavior commandBehavior, CancellationToken cancellationToken) { if (TraceSwitch.Level == TraceLevel.Off || OnTraceConnection == null) { return(await((DbCommand)Command).ExecuteReaderAsync(commandBehavior, cancellationToken)); } var now = DateTime.UtcNow; var sw = Stopwatch.StartNew(); if (TraceSwitch.TraceInfo) { OnTraceConnection(new TraceInfo(TraceInfoStep.BeforeExecute) { TraceLevel = TraceLevel.Info, DataConnection = this, Command = Command, StartTime = now, IsAsync = true, }); } try { var ret = await((DbCommand)Command).ExecuteReaderAsync(commandBehavior, cancellationToken); if (TraceSwitch.TraceInfo) { OnTraceConnection(new TraceInfo(TraceInfoStep.AfterExecute) { TraceLevel = TraceLevel.Info, DataConnection = this, Command = Command, StartTime = now, ExecutionTime = sw.Elapsed, IsAsync = true, }); } return(ret); } catch (Exception ex) { if (TraceSwitch.TraceError) { OnTraceConnection(new TraceInfo(TraceInfoStep.Error) { TraceLevel = TraceLevel.Error, DataConnection = this, Command = Command, StartTime = now, ExecutionTime = sw.Elapsed, Exception = ex, IsAsync = true, }); } throw; } }
public Task <DbDataReader> ExecuteReaderTaskRunnable(CommandBehavior behavior, AseCommand command, AseTransaction transaction) { return(Task.FromResult <DbDataReader>(null)); }
public DbDataReader ExecuteReader(CommandBehavior behavior) { return(ExecuteDbDataReader(behavior)); }
public virtual CommandBehavior GetCommandBehavior(CommandBehavior commandBehavior) { return(commandBehavior); }
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { return(new EFMySqlDataReader(this, command.ExecuteReader(behavior))); }
/// <summary> /// Creates a new query against a database. /// </summary> /// <param name="sql">The sql query to execute.</param> /// <param name="connectionString">The connection string to use to connect to the database.</param> /// <param name="sqlBehavior">The SQL behavior.</param> private OleDBQuery(string sql, string connectionString, CommandBehavior sqlBehavior) { InitQuery(sql, connectionString, sqlBehavior); }
/// <summary> /// /// </summary> /// <param name="command"></param> /// <param name="commandBehavior"></param> /// <returns></returns> public async Task <DbDataReader> ExecuteReaderAsync(DbCommand command, CommandBehavior commandBehavior) { return(await ExecuteReaderAsync(command, commandBehavior, CancellationToken.None).ConfigureAwait(false)); }
internal static ArgumentOutOfRangeException InvalidCommandBehavior(CommandBehavior value) { Debug.Assert((0 > (int)value) || ((int)value > 0x3F), "valid CommandType " + value.ToString()); return(InvalidEnumerationValue(typeof(CommandBehavior), (int)value)); }
internal static ArgumentOutOfRangeException NotSupportedCommandBehavior(CommandBehavior value, string method) { return(NotSupportedEnumerationValue(typeof(CommandBehavior), value.ToString(), method)); }
public IDataReader ExecuteReader(CommandBehavior behavior) { return(this.VistaDbCommand.ExecuteReader(behavior)); }
public IDataReader ExecuteReader(CommandBehavior behavior) { return(ExecuteReader()); }
// <summary> // The constructor for the data reader, each EntityDataReader must always be associated with a EntityCommand and an underlying // DbDataReader. It is expected that EntityDataReader only has a reference to EntityCommand and doesn't assume responsibility // of cleaning the command object, but it does assume responsibility of cleaning up the store data reader object. // </summary> internal EntityDataReader(EntityCommand command, DbDataReader storeDataReader, CommandBehavior behavior) { DebugCheck.NotNull(command); DebugCheck.NotNull(storeDataReader); _command = command; _storeDataReader = storeDataReader; _storeExtendedDataRecord = storeDataReader as IExtendedDataRecord; _behavior = behavior; }
protected override Task <DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) { var reader = new MockDbDataReaderWrapper(this.command.ExecuteReader(behavior)); return(Task.FromResult((DbDataReader)reader)); }
//protected override int Fill(DataTable dataTable, IDataReader dataReader) { // return base.Fill(dataTable, dataReader); //} private int FillFromRecordset(object data, UnsafeNativeMethods.ADORecordsetConstruction recordset, string?srcTable, out bool incrementResultCount) { incrementResultCount = false; IntPtr chapter; /*ODB.DB_NULL_HCHAPTER*/ object?result = null; try { result = recordset.get_Rowset(); chapter = recordset.get_Chapter(); } catch (Exception e) { // UNDONE - should not be catching all exceptions!!! if (!ADP.IsCatchableExceptionType(e)) { throw; } throw ODB.Fill_EmptyRecordSet("ADODBRecordSet", e); } if (null != result) { CommandBehavior behavior = (MissingSchemaAction.AddWithKey != MissingSchemaAction) ? 0 : CommandBehavior.KeyInfo; behavior |= CommandBehavior.SequentialAccess; OleDbDataReader?dataReader = null; try { // intialized with chapter only since we don't want ReleaseChapter called for this chapter handle ChapterHandle chapterHandle = ChapterHandle.CreateChapterHandle(chapter); dataReader = new OleDbDataReader(null, null, 0, behavior); dataReader.InitializeIRowset(result, chapterHandle, ADP.RecordsUnaffected); dataReader.BuildMetaInfo(); incrementResultCount = (0 < dataReader.FieldCount); if (incrementResultCount) { if (data is DataTable) { return(base.Fill((DataTable)data, dataReader)); } else { return(base.Fill((DataSet)data, srcTable !, dataReader, 0, 0)); } } } finally { if (null != dataReader) { dataReader.Close(); } } } return(0); }
public Task <DbDataReader> ExecuteDbDataReaderAsync(DbCommand command, CommandBehavior behavior, CancellationToken cancellationToken) { OnCommandExecute(command, DbCommandExecution.ExecuteDbDataReaderAsync, behavior); return(Task.FromResult <DbDataReader>(new FakeDbDataReader())); }
public static async Task <MySqlDataReader> ExecuteReaderAsync(IReadOnlyList <IMySqlCommand> commands, ICommandPayloadCreator payloadCreator, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var commandListPosition = new CommandListPosition(commands); var command = commands[0]; // pre-requisite: Connection is non-null must be checked before calling this method var connection = command.Connection !; if (Log.IsDebugEnabled()) { Log.Debug("Session{0} ExecuteReader {1} CommandCount: {2}", connection.Session.Id, ioBehavior, commands.Count); } Dictionary <string, CachedProcedure?>?cachedProcedures = null; foreach (var command2 in commands) { if (command2.CommandType == CommandType.StoredProcedure) { cachedProcedures ??= new(); var commandText = command2.CommandText !; if (!cachedProcedures.ContainsKey(commandText)) { cachedProcedures.Add(commandText, await connection.GetCachedProcedure(commandText, revalidateMissing: false, ioBehavior, cancellationToken).ConfigureAwait(false)); // because the connection was used to execute a MySqlDataReader with the connection's DefaultCommandTimeout, // we need to reapply the command's CommandTimeout (even if some of the time has elapsed) command.CancellableCommand.ResetCommandTimeout(); } } } var writer = new ByteBufferWriter(); // cachedProcedures will be non-null if there is a stored procedure, which is also the only time it will be read if (!payloadCreator.WriteQueryCommand(ref commandListPosition, cachedProcedures !, writer)) { throw new InvalidOperationException("ICommandPayloadCreator failed to write query payload"); } cancellationToken.ThrowIfCancellationRequested(); using var payload = writer.ToPayloadData(); connection.Session.StartQuerying(command.CancellableCommand); command.SetLastInsertedId(-1); try { await connection.Session.SendAsync(payload, ioBehavior, CancellationToken.None).ConfigureAwait(false); return(await MySqlDataReader.CreateAsync(commandListPosition, payloadCreator, cachedProcedures, command, behavior, ioBehavior, cancellationToken).ConfigureAwait(false)); } catch (MySqlException ex) when(ex.ErrorCode == MySqlErrorCode.QueryInterrupted && cancellationToken.IsCancellationRequested) { Log.Warn("Session{0} query was interrupted", connection.Session.Id); throw new OperationCanceledException(ex.Message, ex, cancellationToken); } catch (Exception ex) when(payload.Span.Length > 4_194_304 && (ex is SocketException or IOException or MySqlProtocolException)) { // the default MySQL Server value for max_allowed_packet (in MySQL 5.7) is 4MiB: https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_allowed_packet // use "decimal megabytes" (to round up) when creating the exception message int megabytes = payload.Span.Length / 1_000_000; throw new MySqlException("Error submitting {0}MB packet; ensure 'max_allowed_packet' is greater than {0}MB.".FormatInvariant(megabytes), ex); } }
private MySqlDataReader(MySqlCommand command, CommandBehavior behavior) { Command = command; m_behavior = behavior; }
public NpgsqlDataReader ExecuteReader(NpgsqlCommand command, CommandBehavior commandBehavior) { return(command.ExecuteReader(commandBehavior)); }
public DbDataReader ExecuteReader(CommandBehavior behavior, AseCommand command, AseTransaction transaction) { return(null); }
public DbDataReader ExecuteDbDataReader(DbCommand command, CommandBehavior behavior) { OnCommandExecute(command, DbCommandExecution.ExecuteDbDataReader, behavior); return(new FakeDbDataReader()); }
internal static async Task <MySqlDataReader> CreateAsync(MySqlCommand command, CommandBehavior behavior, IOBehavior ioBehavior) { var dataReader = new MySqlDataReader(command, behavior); command.Connection.SetActiveReader(dataReader); try { await dataReader.ReadFirstResultSetAsync(ioBehavior).ConfigureAwait(false); if (command.Connection.BufferResultSets) { while (await dataReader.BufferNextResultAsync(ioBehavior, CancellationToken.None).ConfigureAwait(false) != null) { } } return(dataReader); } catch (Exception) { dataReader.Dispose(); throw; } finally { if (command.Connection.BufferResultSets) { command.Connection.FinishQuerying(); } } }
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { return(new MockDbDataReaderWrapper(this.command.ExecuteReader(behavior))); }
/// <summary> /// Executes the command text against the connection. /// </summary> /// <param name="behavior"> /// An instance of <see cref="T:System.Data.CommandBehavior" />. /// </param> /// <returns> /// A <see cref="T:System.Data.Common.DbDataReader" />. /// </returns> protected override abstract DbDataReader ExecuteDbDataReader(CommandBehavior behavior);
/// <summary> /// 执行SQL语句将SQL结果返回到DataReader中 /// </summary> /// <param name="Sql">SQL语句</param> /// <param name="behavior">命令执行行为</param> /// <param name="callback">回调函数/委托</param> public void ExecuteDataReader(SqlStatement Sql, CommandBehavior behavior, CallbackObjectHandler <IDataReader> callback) { DefaultContext.ExecuteDataReader(Sql, behavior, callback); }
/// <summary> /// Closes the MySqlDataReader object. /// </summary> public void Close() { if (!isOpen) { return; } bool shouldCloseConnection = (commandBehavior & CommandBehavior.CloseConnection) != 0; commandBehavior = CommandBehavior.Default; // clear all remaining result sets try { while (NextResult()) { } } catch (MySqlException ex) { // Ignore aborted queries if (!ex.IsQueryAborted) { // ignore IO exceptions. // We are closing or disposing reader, and do not // want exception to be propagated to used. If socket is // is closed on the server side, next query will run into // IO exception. If reader is closed by GC, we also would // like to avoid any exception here. bool isIOException = false; for (Exception exception = ex; exception != null; exception = exception.InnerException) { if (exception is System.IO.IOException) { isIOException = true; break; } } if (!isIOException) { // Ordinary exception (neither IO nor query aborted) throw; } } } catch (System.IO.IOException) { // eat, on the same reason we eat IO exceptions wrapped into // MySqlExceptions reasons, described above. } finally { // always ensure internal reader is null (Bug #55558) connection.Reader = null; } // we now give the command a chance to terminate. In the case of // stored procedures it needs to update out and in out parameters command.Close(this); if (this.command.Canceled && connection.driver.Version.isAtLeast(5, 1, 0)) { // Issue dummy command to clear kill flag ClearKillFlag(); } if (shouldCloseConnection) { connection.Close(); } command = null; connection.IsInUse = false; connection = null; isOpen = false; }
/// <summary> /// Creates a new SQLiteDataReader to execute/iterate the array of SQLite prepared statements /// </summary> /// <param name="behavior">The behavior the data reader should adopt</param> /// <returns>Returns a SQLiteDataReader object</returns> protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { return(ExecuteReader(behavior)); }
internal AseDataReader(IEnumerable <TableResult> results, AseCommand command, CommandBehavior behavior) { _results = results.ToArray(); _command = command; _behavior = behavior; NextResult(); }