public static async Task <List <Fortune> > LoadFortunesRows() { var fortunes = new List <Fortune>(); using var pooledConnection = await PooledConnections.GetConnection(ConnectionStrings.OdbcConnection); await pooledConnection.OpenAsync(); var pooledCommand = new PooledCommand("SELECT id, message FROM fortune", pooledConnection); using (pooledCommand) { using var dataReader = await pooledCommand.ExecuteReaderAsync(CommandBehavior.SingleResult); while (await dataReader.ReadAsync()) { fortunes.Add(new Fortune ( id: dataReader.GetInt32(0), message: dataReader.GetString(1) )); } } fortunes.Add(new Fortune(id: 0, message: "Additional fortune added at request time.")); fortunes.Sort(); return(fortunes); }
//static async Task<CachedWorld[]> LoadUncachedQueries(int id, int i, int count, RawDb rawdb, CachedWorld[] result) static async Task <CachedWorld[]> LoadUncachedQueries(int id, int i, int count, CachedWorld[] result) { var pooledConnection = await PooledConnections.GetConnection(DataProvider.ConnectionString); pooledConnection.Open(); var(pooledCommand, dbDataParameter) = CreateReadCommand(pooledConnection); using (pooledCommand) { Func <ICacheEntry, Task <CachedWorld> > create = async(entry) => { return(await ReadSingleRow(pooledCommand)); }; var cacheKeys = _cacheKeys; var key = cacheKeys[id]; dbDataParameter.Value = id; for (; i < result.Length; i++) { result[i] = await _cache.GetOrCreateAsync <CachedWorld>(key, create); id = _random.Next(1, 10001); dbDataParameter.Value = id; key = cacheKeys[id]; } pooledCommand.Release(); pooledConnection.Release(); } return(result); }
public static async Task <List <Fortune> > LoadFortunesRows() { var fortunes = new List <Fortune>(); var pooledConnection = await PooledConnections.GetConnection(DataProvider.ConnectionString); pooledConnection.Open(); var pooledCommand = new PooledCommand("SELECT * FROM fortune", pooledConnection); var dataReader = await pooledCommand.ExecuteReaderAsync(CommandBehavior.SingleResult& CommandBehavior.SequentialAccess); while (dataReader.Read()) { fortunes.Add(new Fortune ( id: dataReader.GetInt32(0), #if MYSQL //MariaDB ODBC connector does not correctly support Japanese characters in combination with default ADO.NET; //as a solution we custom read this string message: ReadColumn(dataReader, 1) #else message: dataReader.GetString(1) #endif )); } dataReader.Close(); pooledCommand.Release(); pooledConnection.Release(); fortunes.Add(new Fortune(id: 0, message: "Additional fortune added at request time.")); fortunes.Sort(); return(fortunes); }
public static async Task <World[]> ReadMultipleRows(int count) { int j = 0; var ids = PlatformBenchmarks.BatchUpdateString.Ids; var worlds = new World[count]; string queryString; if (_queriesMultipleRows[count] != null) { queryString = _queriesMultipleRows[count]; } else { var stringBuilder = PlatformBenchmarks.StringBuilderCache.Acquire(); for (int i = 0; i < count; i++) { stringBuilder.Append("SELECT * FROM world WHERE id=?;"); } queryString = _queriesMultipleRows[count] = PlatformBenchmarks.StringBuilderCache.GetStringAndRelease(stringBuilder); } var pooledConnection = await PooledConnections.GetConnection(DataProvider.ConnectionString); pooledConnection.Open(); var pooledCommand = new PooledCommand(queryString, pooledConnection); for (int i = 0; i < count; i++) { pooledCommand.CreateParameter(ids[i], DbType.Int32, _random.Next(1, 10001)); } var dataReader = await pooledCommand.ExecuteReaderAsync(CommandBehavior.Default& CommandBehavior.SequentialAccess); do { dataReader.Read(); worlds[j] = new World { Id = dataReader.GetInt32(0), RandomNumber = dataReader.GetInt32(1) }; j++; } while (await dataReader.NextResultAsync()); dataReader.Close(); pooledCommand.Release(); pooledConnection.Release(); return(worlds); }
public static async Task <World[]> LoadMultipleUpdatesRows(int count) { var worlds = new World[count]; var pooledConnection = await PooledConnections.GetConnection(DataProvider.ConnectionString); pooledConnection.Open(); var(queryCommand, dbDataParameter) = CreateReadCommand(pooledConnection); for (int i = 0; i < count; i++) { worlds[i] = await ReadSingleRow(queryCommand); dbDataParameter.Value = _random.Next(1, 10001); } queryCommand.Release(); var updateCommand = new PooledCommand(PlatformBenchmarks.BatchUpdateString.Query(count), pooledConnection); var ids = PlatformBenchmarks.BatchUpdateString.Ids; var randoms = PlatformBenchmarks.BatchUpdateString.Randoms; #if !MYSQL var jds = PlatformBenchmarks.BatchUpdateString.Jds; #endif for (int i = 0; i < count; i++) { var randomNumber = _random.Next(1, 10001); updateCommand.CreateParameter(ids[i], DbType.Int32, worlds[i].Id); updateCommand.CreateParameter(randoms[i], DbType.Int32, randomNumber); worlds[i].RandomNumber = randomNumber; } #if !MYSQL for (int i = 0; i < count; i++) { updateCommand.CreateParameter(jds[i], DbType.Int32, worlds[i].Id); } #endif await updateCommand.ExecuteNonQueryAsync(); updateCommand.Release(); pooledConnection.Release(); return(worlds); }
public static async Task <World> LoadSingleQueryRow() { using var pooledConnection = await PooledConnections.GetConnection(ConnectionStrings.OdbcConnection); await pooledConnection.OpenAsync(); var(pooledCommand, _) = CreateReadCommand(pooledConnection); using (pooledCommand) { return(await ReadSingleRow(pooledCommand)); } }
public static async Task <World> LoadSingleQueryRow() { var pooledConnection = await PooledConnections.GetConnection(DataProvider.ConnectionString); pooledConnection.Open(); var(pooledCommand, _) = CreateReadCommand(pooledConnection); var world = await ReadSingleRow(pooledCommand); pooledCommand.Release(); pooledConnection.Release(); return(world); }
public static async Task <World[]> LoadMultipleQueriesRows(int count) { var worlds = new World[count]; using var pooledConnection = await PooledConnections.GetConnection(ConnectionStrings.OdbcConnection); await pooledConnection.OpenAsync(); var(pooledCommand, dbDataParameter) = CreateReadCommand(pooledConnection); using (pooledCommand) { for (int i = 0; i < count; i++) { worlds[i] = await ReadSingleRow(pooledCommand); dbDataParameter.Value = _random.Next(1, 10001); } } return(worlds); }
public static async Task <World[]> LoadMultipleQueriesRows(int count) { var worlds = new World[count]; var pooledConnection = await PooledConnections.GetConnection(DataProvider.ConnectionString); pooledConnection.Open(); var(pooledCommand, dbDataParameter) = CreateReadCommand(pooledConnection); for (int i = 0; i < count; i++) { worlds[i] = await ReadSingleRow(pooledCommand); dbDataParameter.Value = _random.Next(1, 10001); } pooledCommand.Release(); pooledConnection.Release(); return(worlds); }
public static async Task PopulateCache() { var pooledConnection = await PooledConnections.GetConnection(DataProvider.ConnectionString); pooledConnection.Open(); var(pooledCommand, dbDataParameter) = CreateReadCommand(pooledConnection); using (pooledCommand) { var cacheKeys = _cacheKeys; var cache = _cache; for (var i = 1; i < 10001; i++) { dbDataParameter.Value = i; cache.Set <CachedWorld>(cacheKeys[i], await ReadSingleRow(pooledCommand)); } } pooledCommand.Release(); pooledConnection.Release(); }