Example #1
0
 public void ExecuteInterruptibleReader(T arg, bool singleRow, string commandText, CommandType commandType, DbExecutionParameters executionParameters, Func <DbDataReader, bool> handleOneRow, params DbParameter[] parameters)
 {
     DbHelper.ExecuteInterruptibleReader(_selector.GetConnectionString(arg), singleRow, commandText, commandType, executionParameters, handleOneRow, parameters);
 }
Example #2
0
 public async Task ExecuteInterruptibleReaderAsync(T arg, bool singleRow, string commandText, CommandType commandType, DbExecutionParameters executionParameters, Func <DbDataReader, Task <bool> > handleOneRow, params DbParameter[] parameters)
 {
     await DbHelper.ExecuteInterruptibleReaderAsync(_selector.GetConnectionString(arg), singleRow, commandText, commandType, executionParameters, handleOneRow, parameters);
 }
 public async Task ExecuteReaderAsync(bool singleRow, string commandText, CommandType commandType, DbExecutionParameters executionParameters, Action <DbDataReader> handleOneRow, params DbParameter[] parameters)
 {
     await DbHelper.ExecuteReaderAsync(_connectionString, singleRow, commandText, commandType, executionParameters, handleOneRow, parameters);
 }
Example #4
0
 public async Task ExecuteReaderAsync(T arg, string commandText, DbExecutionParameters executionParameters, Action <DbDataReader> handleOneRow, params DbParameter[] parameters)
 {
     await DbHelper.ExecuteReaderAsync(_selector.GetConnectionString(arg), commandText, executionParameters, handleOneRow, parameters);
 }
 public void ExecuteReader(string commandText, DbExecutionParameters executionParameters, Action <DbDataReader> handleOneRow, params DbParameter[] parameters)
 {
     DbHelper.ExecuteReader(_connectionString, commandText, executionParameters, handleOneRow, parameters);
 }
Example #6
0
        public async static Task ExecuteInterruptibleReaderAsync(string connectionString, bool singleRow, string commandText, CommandType commandType, DbExecutionParameters executionParameters, Func <DbDataReader, Task <bool> > handleOneRow, params DbParameter[] parameters)
        {
            using (var connection = _factory.CreateConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();

                var logContext = LogBegin("ExecuteInterruptibleReaderAsync", connection, commandText, parameters);

                try
                {
                    using (var cmd = _factory.CreateCommand())
                    {
                        cmd.Connection  = connection;
                        cmd.CommandText = commandText;
                        cmd.CommandType = commandType;
                        if (executionParameters != null && executionParameters.CommandTimeout.HasValue)
                        {
                            cmd.CommandTimeout = executionParameters.CommandTimeout.Value;
                        }

                        cmd.Parameters.AddRange(parameters);

                        using (var reader = await cmd.ExecuteReaderAsync())
                        {
                            while (reader.Read())
                            {
                                if (await handleOneRow(reader))
                                {
                                    break;
                                }

                                if (singleRow)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    LogEnd(logContext);
                }
            }
        }
Example #7
0
 public static async Task ExecuteReaderAsync(string connectionString, string commandText, DbExecutionParameters executionParameters, Action <DbDataReader> handleOneRow, params DbParameter[] parameters)
 {
     await ExecuteReaderAsync(connectionString, false, commandText, CommandType.Text, executionParameters, handleOneRow, parameters);
 }
Example #8
0
        public static void ExecuteReader(string connectionString, bool singleRow, string commandText, CommandType commandType, DbExecutionParameters executionParameters, Action <DbDataReader> handleOneRow, params DbParameter[] parameters)
        {
            using (var connection = _factory.CreateConnection())
            {
                if (executionParameters != null && executionParameters.ConnectionTimeout.HasValue)
                {
                    var connectionStringBuilder = _factory.CreateConnectionStringBuilder();
                    connectionStringBuilder.ConnectionString = connectionString;
                    if (connectionStringBuilder is SqlConnectionStringBuilder)
                    {
                        ((SqlConnectionStringBuilder)connectionStringBuilder).ConnectTimeout = executionParameters.ConnectionTimeout.Value;
                    }
                    else
                    {
                        throw new Exception("Do not support setting ConnectionTimeout on " + connectionStringBuilder.GetType().ToString());
                    }
                    connectionString = connectionStringBuilder.ToString();
                }
                connection.ConnectionString = connectionString;
                connection.Open();

                var logContext = LogBegin("ExecuteReader", connection, commandText, parameters);

                try
                {
                    using (var cmd = _factory.CreateCommand())
                    {
                        cmd.Connection  = connection;
                        cmd.CommandText = commandText;
                        cmd.CommandType = commandType;
                        if (executionParameters != null && executionParameters.CommandTimeout.HasValue)
                        {
                            cmd.CommandTimeout = executionParameters.CommandTimeout.Value;
                        }

                        cmd.Parameters.AddRange(parameters);

                        using (var reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                handleOneRow(reader);

                                if (singleRow)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    LogEnd(logContext);
                }
            }
        }
Example #9
0
 public static void ExecuteReader(string connectionString, string commandText, DbExecutionParameters executionParameters, Action <DbDataReader> handleOneRow, params DbParameter[] parameters)
 {
     ExecuteReader(connectionString, false, commandText, CommandType.Text, executionParameters, handleOneRow, parameters);
 }