From 82291b678f33cb8cadf00bb9bf1bf1d0884ead77 Mon Sep 17 00:00:00 2001 From: qinyouzeng Date: Mon, 4 Dec 2023 11:05:49 +0800 Subject: [PATCH] fix: add table exists exception catch --- .../Common.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Clickhouse.Tests/Common.cs b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Clickhouse.Tests/Common.cs index 09fee8546..72d0c4def 100644 --- a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Clickhouse.Tests/Common.cs +++ b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Tsc.Clickhouse.Tests/Common.cs @@ -16,8 +16,16 @@ public static void InitTable(bool isLog) { var sql = reader.ReadToEnd(); cmd.CommandText = sql; - cmd.ExecuteNonQuery(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + //table is exists + } } + path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Data/otel_{name}_data.txt"); using (var dataReader = new StreamReader(path)) { @@ -34,11 +42,10 @@ public static void InitTableData(bool isLog) connection.Open(); using var cmd = connection.CreateCommand(); var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Data/otel_{name}_data.txt"); - using (var dataReader = new StreamReader(path)) - { - var sql = dataReader.ReadToEnd(); - cmd.CommandText = sql; - cmd.ExecuteNonQuery(); - } + using var dataReader = new StreamReader(path); + var sql = dataReader.ReadToEnd(); + cmd.CommandText = sql; + cmd.ExecuteNonQuery(); + } }