From 667591080fc211c7a926e5881743b53fe0bed3cf Mon Sep 17 00:00:00 2001 From: DarkWanderer Date: Sat, 16 Jan 2021 15:30:15 +0300 Subject: [PATCH] DataReader: do not throw exception on empty dataset #58 --- ClickHouse.Client.Tests/SqlAlterTests.cs | 4 ++-- ClickHouse.Client/ADO/Readers/ClickHouseDataReader.cs | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ClickHouse.Client.Tests/SqlAlterTests.cs b/ClickHouse.Client.Tests/SqlAlterTests.cs index ed77235e..3bfe1b10 100644 --- a/ClickHouse.Client.Tests/SqlAlterTests.cs +++ b/ClickHouse.Client.Tests/SqlAlterTests.cs @@ -21,8 +21,8 @@ public SqlAlterTests() [Test] public async Task ShouldExecuteAlterTable() { - await connection.ExecuteStatementAsync($"CREATE TABLE IF NOT EXISTS test.table_delete_from (value Int32) ENGINE=MergeTree ORDER BY value"); - await connection.ExecuteStatementAsync($"ALTER TABLE test.table_delete_from DELETE WHERE 1=1"); + await connection.ExecuteScalarAsync($"CREATE TABLE IF NOT EXISTS test.table_delete_from (value Int32) ENGINE=MergeTree ORDER BY value"); + await connection.ExecuteScalarAsync($"ALTER TABLE test.table_delete_from DELETE WHERE 1=1"); } } } diff --git a/ClickHouse.Client/ADO/Readers/ClickHouseDataReader.cs b/ClickHouse.Client/ADO/Readers/ClickHouseDataReader.cs index e1ed709f..f5de2a66 100644 --- a/ClickHouse.Client/ADO/Readers/ClickHouseDataReader.cs +++ b/ClickHouse.Client/ADO/Readers/ClickHouseDataReader.cs @@ -161,6 +161,13 @@ protected override void Dispose(bool disposing) private void ReadHeaders() { + if (reader.PeekChar() == -1) + { + // Empty dataset + FieldNames = new string[0]; + RawTypes = new ClickHouseType[0]; + return; + } var count = reader.Read7BitEncodedInt(); FieldNames = new string[count]; RawTypes = new ClickHouseType[count];