From 581bae61953ede8c99679daeaa8d75585fea1599 Mon Sep 17 00:00:00 2001 From: Mani Gandham Date: Sun, 13 May 2018 16:40:48 -0700 Subject: [PATCH 1/3] fix #19 by checking for `rows_loaded` column return in COPY statements --- Snowflake.Data/Core/ResultSetUtil.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Snowflake.Data/Core/ResultSetUtil.cs b/Snowflake.Data/Core/ResultSetUtil.cs index 1b75444af..a8041dd39 100755 --- a/Snowflake.Data/Core/ResultSetUtil.cs +++ b/Snowflake.Data/Core/ResultSetUtil.cs @@ -17,21 +17,22 @@ internal static int CalculateUpdateCount(this SFBaseResultSet resultSet) SFResultSetMetaData metaData = resultSet.sfResultSetMetaData; SFStatementType statementType = metaData.statementType; - int updateCount = 0; - switch(statementType) + int updateCount = 0; + switch (statementType) { case SFStatementType.INSERT: case SFStatementType.UPDATE: case SFStatementType.DELETE: case SFStatementType.MERGE: case SFStatementType.MULTI_INSERT: - for(int i=0; i(i); } break; case SFStatementType.COPY: - updateCount = resultSet.GetValue(3); + var index = resultSet.sfResultSetMetaData.getColumnIndexByName("rows_loaded"); + if (index >= 0) updateCount = resultSet.GetValue(index); break; case SFStatementType.SELECT: updateCount = -1; @@ -42,6 +43,6 @@ internal static int CalculateUpdateCount(this SFBaseResultSet resultSet) } return updateCount; - } + } } } From ea48b6feb784a779821304072cb90e24cf057904 Mon Sep 17 00:00:00 2001 From: howryu Date: Fri, 25 May 2018 10:06:15 -0700 Subject: [PATCH 2/3] Add tests for 0 copied files --- Snowflake.Data.Tests/SFDbDataReaderIT.cs | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Snowflake.Data.Tests/SFDbDataReaderIT.cs b/Snowflake.Data.Tests/SFDbDataReaderIT.cs index 4f411c53c..a67cad38a 100755 --- a/Snowflake.Data.Tests/SFDbDataReaderIT.cs +++ b/Snowflake.Data.Tests/SFDbDataReaderIT.cs @@ -594,7 +594,38 @@ public void testGetGuid() conn.Close(); } + + } + [Test] + public void TestCopyWithZeroFiles() + { + using (IDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = connectionString; + conn.Open(); + + IDbCommand cmd = conn.CreateCommand(); + cmd.CommandText = "create or replace stage emptyStage"; + cmd.ExecuteNonQuery(); + + cmd.CommandText = "create or replace table testZeroCopy (cola string)"; + cmd.ExecuteNonQuery(); + + cmd.CommandText = "copy into testZeroCopy from @emptyStage"; + + int updateCount = cmd.ExecuteNonQuery(); + Assert.AreEqual(0, updateCount); + + // clean up + cmd.CommandText = "drop stage emptyStage"; + cmd.ExecuteNonQuery(); + + cmd.CommandText = "drop table testZeroCopy"; + cmd.ExecuteNonQuery(); + + conn.Close(); + } } } } From de5d94512f2fa7349858d3146038fc146d2a842a Mon Sep 17 00:00:00 2001 From: howryu Date: Fri, 25 May 2018 10:50:18 -0700 Subject: [PATCH 3/3] Improve the test --- Snowflake.Data.Tests/SFDbDataReaderIT.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Snowflake.Data.Tests/SFDbDataReaderIT.cs b/Snowflake.Data.Tests/SFDbDataReaderIT.cs index a67cad38a..fef933220 100755 --- a/Snowflake.Data.Tests/SFDbDataReaderIT.cs +++ b/Snowflake.Data.Tests/SFDbDataReaderIT.cs @@ -598,7 +598,7 @@ public void testGetGuid() } [Test] - public void TestCopyWithZeroFiles() + public void TestCopyCmdUpdateCount() { using (IDbConnection conn = new SnowflakeDbConnection()) { @@ -609,19 +609,26 @@ public void TestCopyWithZeroFiles() cmd.CommandText = "create or replace stage emptyStage"; cmd.ExecuteNonQuery(); - cmd.CommandText = "create or replace table testZeroCopy (cola string)"; + cmd.CommandText = "create or replace table testCopy (cola string)"; cmd.ExecuteNonQuery(); - cmd.CommandText = "copy into testZeroCopy from @emptyStage"; - + cmd.CommandText = "copy into testCopy from @emptyStage"; int updateCount = cmd.ExecuteNonQuery(); Assert.AreEqual(0, updateCount); + // test rows_loaded exists + cmd.CommandText = "copy into @%testcopy from (select 'test_string')"; + cmd.ExecuteNonQuery(); + + cmd.CommandText = "copy into testcopy"; + updateCount = cmd.ExecuteNonQuery(); + Assert.AreEqual(1, updateCount); + // clean up cmd.CommandText = "drop stage emptyStage"; cmd.ExecuteNonQuery(); - cmd.CommandText = "drop table testZeroCopy"; + cmd.CommandText = "drop table testCopy"; cmd.ExecuteNonQuery(); conn.Close();