本文整理汇总了C#中Npgsql.NpgsqlCommand.ExecuteReaderAsync方法的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlCommand.ExecuteReaderAsync方法的具体用法?C# NpgsqlCommand.ExecuteReaderAsync怎么用?C# NpgsqlCommand.ExecuteReaderAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Npgsql.NpgsqlCommand
的用法示例。
在下文中一共展示了NpgsqlCommand.ExecuteReaderAsync方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Reader
public async void Reader()
{
using (var cmd = new NpgsqlCommand("SELECT 1", Conn))
using (var reader = await cmd.ExecuteReaderAsync())
{
await reader.ReadAsync();
Assert.That(reader[0], Is.EqualTo(1));
}
}
示例2: Columnar
public async void Columnar()
{
using (var cmd = new NpgsqlCommand("SELECT NULL, 2, 'Some Text'", Conn))
using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess))
{
await reader.ReadAsync();
Assert.That(await reader.IsDBNullAsync(0), Is.True);
Assert.That(await reader.GetFieldValueAsync<string>(2), Is.EqualTo("Some Text"));
}
}
示例3: Columnar
public async void Columnar()
{
ExecuteNonQuery("INSERT INTO DATA (field_int4, field_text) VALUES (2, 'Some Text')");
using (var cmd = new NpgsqlCommand("SELECT field_int2, field_int4, field_text FROM data", Conn))
using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess))
{
await reader.ReadAsync();
Assert.That(await reader.IsDBNullAsync(0), Is.True);
Assert.That(await reader.GetFieldValueAsync<string>(2), Is.EqualTo("Some Text"));
}
}
示例4: buildEventPage
private async Task<EventPage> buildEventPage(long lastEncountered, NpgsqlCommand cmd)
{
IList<IEvent> events = null;
IList<long> sequences = new List<long>();
using (var reader = await cmd.ExecuteReaderAsync(_token).ConfigureAwait(false))
{
while (await reader.ReadAsync(_token).ConfigureAwait(false))
{
var seq = await reader.GetFieldValueAsync<long>(0, _token).ConfigureAwait(false);
sequences.Add(seq);
}
if (sequences.Any())
{
await reader.NextResultAsync(_token).ConfigureAwait(false);
events = await _selector.ReadAsync(reader, _map, _token).ConfigureAwait(false);
}
else
{
events = new List<IEvent>();
}
}
return new EventPage(lastEncountered, sequences, events) {Count = events.Count};
}
示例5: ExecuteReaderAsync
public async void ExecuteReaderAsync(int rows)
{
for (var i = 0; i < rows; i++)
ExecuteNonQuery("INSERT INTO DATA (field_int4) VALUES (10)");
using (var metrics = TestMetrics.Start(TestRunTime, true))
{
while (!metrics.TimesUp)
{
using (var cmd = new NpgsqlCommand("SELECT field_int4 FROM data", Conn))
using (var reader = await cmd.ExecuteReaderAsync())
{
while (await reader.ReadAsync()) { }
}
metrics.IncrementIterations();
}
}
}
示例6: GetDriverByLastNameAsync
public async Task<IEnumerable<Driver>> GetDriverByLastNameAsync(string theDriverName)
{
try
{
await Connection.OpenAsync().ConfigureAwait(false);
var aPreparedCommand =
new NpgsqlCommand(
"SELECT id, firstname, lastname, address, city, state, postalcode, country, licensenumber, licensestate, customerid from driver where id = :value1", Connection);
var aParam = new NpgsqlParameter("value1", NpgsqlDbType.Text) { Value = theDriverName };
aPreparedCommand.Parameters.Add(aParam);
var aReader = await aPreparedCommand.ExecuteReaderAsync().ConfigureAwait(false);
if (!aReader.HasRows)
return null;
var aReturn = new List<Driver>();
while (await aReader.ReadAsync().ConfigureAwait(false))
{
aReturn.Add(ReadDriver(aReader));
}
return aReturn;
}
catch (NpgsqlException)
{
return null;
}
catch (InvalidOperationException)
{
return null;
}
catch (SqlException)
{
return null;
}
catch (ConfigurationErrorsException)
{
return null;
}
finally
{
if (Connection.State == ConnectionState.Open)
Connection.Close();
}
}
示例7: GetCustomerByNameAsync
public async Task<Customer> GetCustomerByNameAsync(string theCustomerName)
{
try
{
await Connection.OpenAsync().ConfigureAwait(false);
var aPreparedCommand =
new NpgsqlCommand(
"SELECT id, name, allowsadditionaldrivers, allowsadditions, hasmaxrentaldays, maxrentaldays from customer where name = :value1", Connection);
var aParam = new NpgsqlParameter("value1", NpgsqlDbType.Text) { Value = theCustomerName };
aPreparedCommand.Parameters.Add(aParam);
var aReader = await aPreparedCommand.ExecuteReaderAsync().ConfigureAwait(false);
if (!aReader.HasRows)
return null;
var aReturn = new Customer();
while (await aReader.ReadAsync().ConfigureAwait(false))
{
aReturn = ReadCustomer(aReader);
}
return aReturn;
}
catch (NpgsqlException)
{
return null;
}
catch (InvalidOperationException)
{
return null;
}
catch (SqlException)
{
return null;
}
catch (ConfigurationErrorsException)
{
return null;
}
finally
{
if (Connection.State == ConnectionState.Open)
Connection.Close();
}
}
示例8: buildEventPage
private async Task<EventPage> buildEventPage(long @from, NpgsqlCommand cmd)
{
IList<IEvent> events = null;
IList<long> sequences = new List<long>();
long nextKnown = 0;
long lastKnown = 0;
using (var reader = await cmd.ExecuteReaderAsync(_token).ConfigureAwait(false))
{
while (await reader.ReadAsync(_token).ConfigureAwait(false))
{
var seq = await reader.GetFieldValueAsync<long>(0, _token).ConfigureAwait(false);
sequences.Add(seq);
}
if (sequences.Any())
{
await reader.NextResultAsync(_token).ConfigureAwait(false);
events = await _selector.ReadAsync(reader, _map, null, _token).ConfigureAwait(false);
}
else
{
events = new List<IEvent>();
}
nextKnown = await getLong(reader).ConfigureAwait(false);
lastKnown = await getLong(reader).ConfigureAwait(false);
}
return new EventPage(@from, sequences, events)
{
Count = events.Count,
NextKnownSequence = nextKnown,
LastKnownSequence = lastKnown
};
}
示例9: GetLocationsForCustomerAsync
public async Task<IEnumerable<Location>> GetLocationsForCustomerAsync(int theCustomerId)
{
try
{
await Connection.OpenAsync().ConfigureAwait(false);
var aPreparedCommand = new NpgsqlCommand("SELECT id, customerid, name, address, city, state, postalcode, country, latitude, longitude from location where customerid=:value1", Connection);
aPreparedCommand.Parameters.AddWithValue("value1", theCustomerId);
var aReader = await aPreparedCommand.ExecuteReaderAsync();
if (!aReader.HasRows)
return Enumerable.Empty<Location>();
var aReturn = new List<Location>();
while (await aReader.ReadAsync().ConfigureAwait(false))
{
aReturn.Add(ReadLocation(aReader));
}
return aReturn;
}
catch (NpgsqlException)
{
return Enumerable.Empty<Location>();
}
catch (InvalidOperationException ex)
{
return Enumerable.Empty<Location>();
}
catch (SqlException)
{
return Enumerable.Empty<Location>();
}
catch (ConfigurationErrorsException)
{
return Enumerable.Empty<Location>();
}
finally
{
if (Connection.State == ConnectionState.Open)
Connection.Close();
}
}
示例10: GetLocationAsync
public async Task<Location> GetLocationAsync(int theLocationId)
{
try
{
await Connection.OpenAsync().ConfigureAwait(false);
var aPreparedCommand =
new NpgsqlCommand(
"SELECT id, customerid, name, address, city, state, postalcode, country, latitude, longitude from location where id = :value1", Connection);
var aParam = new NpgsqlParameter("value1", NpgsqlDbType.Integer) { Value = theLocationId };
aPreparedCommand.Parameters.Add(aParam);
var aReader = await aPreparedCommand.ExecuteReaderAsync().ConfigureAwait(false);
if (!aReader.HasRows)
return null;
var aReturn = new Location();
while (await aReader.ReadAsync().ConfigureAwait(false))
{
aReturn = ReadLocation(aReader);
}
return aReturn;
}
catch (NpgsqlException)
{
return null;
}
catch (InvalidOperationException)
{
return null;
}
catch (SqlException)
{
return null;
}
catch (ConfigurationErrorsException)
{
return null;
}
finally
{
if (Connection.State == ConnectionState.Open)
Connection.Close();
}
}
示例11: executeCallbacksAsync
private static async Task executeCallbacksAsync(NpgsqlCommand cmd, CancellationToken tkn, BatchCommand batch, List<Exception> list)
{
using (var reader = await cmd.ExecuteReaderAsync(tkn).ConfigureAwait(false))
{
if (batch.Callbacks.Any())
{
if (batch.Callbacks[0] != null)
{
await batch.Callbacks[0].PostprocessAsync(reader, list, tkn).ConfigureAwait(false);
}
for (int i = 1; i < batch.Callbacks.Count; i++)
{
await reader.NextResultAsync(tkn).ConfigureAwait(false);
if (batch.Callbacks[i] != null)
{
await batch.Callbacks[i].PostprocessAsync(reader, list, tkn).ConfigureAwait(false);
}
}
}
}
}
示例12: GetUserByEmailAsync
public async Task<User> GetUserByEmailAsync(string theEmail)
{
try
{
await Connection.OpenAsync().ConfigureAwait(false);
var aPreparedCommand =
new NpgsqlCommand(
"SELECT id, firstname, lastname, email, customerid, isemployee from appuser where email = :value1", Connection);
var aParam = new NpgsqlParameter("value1", NpgsqlDbType.Text) { Value = theEmail };
aPreparedCommand.Parameters.Add(aParam);
var aReader = await aPreparedCommand.ExecuteReaderAsync().ConfigureAwait(false);
if (!aReader.HasRows)
return null;
var aReturn = new User();
while (await aReader.ReadAsync().ConfigureAwait(false))
{
aReturn = ReadUser(aReader);
}
return aReturn;
}
catch (NpgsqlException)
{
return null;
}
catch (InvalidOperationException)
{
return null;
}
catch (SqlException)
{
return null;
}
catch (ConfigurationErrorsException)
{
return null;
}
finally
{
if (Connection.State == ConnectionState.Open)
Connection.Close();
}
}
示例13: GetAutomobilesAsync
public async Task<IEnumerable<Automobile>> GetAutomobilesAsync(IEnumerable<int> theAutomobileIds)
{
try
{
await Connection.OpenAsync().ConfigureAwait(false);
var aPreparedCommand =
new NpgsqlCommand(
"SELECT id, vin, vehiclenumber, name, class, style, color, manufacturer, model, code, locationid from automobile where id = :value1", Connection);
aPreparedCommand.Parameters.AddWithValue("value1", string.Join(",", theAutomobileIds));
var aReader = await aPreparedCommand.ExecuteReaderAsync();
if (!aReader.HasRows)
return Enumerable.Empty<Automobile>().ToList();
var aReturnList = new List<Automobile>();
while (await aReader.ReadAsync())
{
aReturnList.Add(ReadAutomobile(aReader));
}
return aReturnList;
}
catch (NpgsqlException)
{
return Enumerable.Empty<Automobile>().ToList();
}
catch (InvalidOperationException)
{
return Enumerable.Empty<Automobile>().ToList();
}
catch (SqlException)
{
return Enumerable.Empty<Automobile>().ToList();
}
catch (ConfigurationErrorsException)
{
return Enumerable.Empty<Automobile>().ToList();
}
finally
{
if (Connection.State == ConnectionState.Open)
Connection.Close();
}
}
示例14: GetAutomobileAsync
public async Task<Automobile> GetAutomobileAsync(int theAutomobileId)
{
try
{
await Connection.OpenAsync().ConfigureAwait(false);
var aPreparedCommand =
new NpgsqlCommand(
"SELECT id, vin, vehiclenumber, name, class, style, color, manufacturer, model, code, locationid from automobile where id = :value1", Connection);
var aParam = new NpgsqlParameter("value1", NpgsqlDbType.Integer) { Value = theAutomobileId };
aPreparedCommand.Parameters.Add(aParam);
var aReader = await aPreparedCommand.ExecuteReaderAsync().ConfigureAwait(false);
if (!aReader.HasRows)
return null;
var aReturn = new Automobile();
while (await aReader.ReadAsync().ConfigureAwait(false))
{
aReturn = ReadAutomobile(aReader);
}
return aReturn;
}
catch (NpgsqlException)
{
return null;
}
catch (InvalidOperationException)
{
return null;
}
catch (SqlException)
{
return null;
}
catch (ConfigurationErrorsException)
{
return null;
}
finally
{
if (Connection.State == ConnectionState.Open)
Connection.Close();
}
}