Skip to content

Commit 2f2c533

Browse files
committed
Npgsql: Improve SystemQueryExample
1 parent b9b9a8d commit 2f2c533

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

by-language/csharp-npgsql/DemoProgram.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,19 @@ public static async Task<List<string>> SystemQueryExample(NpgsqlConnection conn)
5757
{
5858
Console.WriteLine("Running SystemQueryExample");
5959
var mountains = new List<string>();
60-
await using (var cmd = new NpgsqlCommand("SELECT mountain FROM sys.summits ORDER BY 1 LIMIT 25", conn))
60+
const string sql = "SELECT mountain, height, coordinates FROM sys.summits ORDER BY height DESC LIMIT 25";
61+
await using (var cmd = new NpgsqlCommand(sql, conn))
6162
await using (var reader = cmd.ExecuteReader())
6263
{
6364
while (await reader.ReadAsync())
6465
{
65-
mountains.Add(reader.GetString(0));
66+
mountains.Add(
67+
reader["mountain"].ToString() + " - " +
68+
reader["height"].ToString() + " - " +
69+
reader["coordinates"].ToString());
6670
}
6771

68-
Console.WriteLine($"Mountains: {string.Join(",", mountains)}");
72+
Console.WriteLine($"Mountains:\n{string.Join("\n", mountains)}");
6973
}
7074

7175
Console.WriteLine();

by-language/csharp-npgsql/tests/DemoProgramTest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace demo.tests
88
{
9-
9+
1010
public class DatabaseFixture : IDisposable
1111
{
1212
public NpgsqlConnection Db { get; private set; }
@@ -29,10 +29,10 @@ public void Dispose()
2929
}
3030

3131
}
32-
32+
3333
public class DemoProgramTest : IClassFixture<DatabaseFixture>
3434
{
35-
35+
3636
DatabaseFixture fixture;
3737
DatabaseWorkloads program = new DatabaseWorkloads();
3838

@@ -51,7 +51,7 @@ public async Task TestSystemQueryExample()
5151
var mountains = await task.WaitAsync(TimeSpan.FromSeconds(0.5));
5252

5353
// Check results.
54-
Assert.Equal("Acherkogel", mountains[0]);
54+
Assert.Equal("Mont Blanc - 4808 - (6.86444,45.8325)", mountains[0]);
5555
}
5656

5757
[Fact]
@@ -79,6 +79,5 @@ public async Task TestUnnestExample()
7979
// Check results.
8080
Assert.Equal(10, resultCount);
8181
}
82-
8382
}
8483
}

0 commit comments

Comments
 (0)