diff --git a/Snowflake.Data.Tests/SFDbDataReaderIT.cs b/Snowflake.Data.Tests/SFDbDataReaderIT.cs index 4f411c53c..fef933220 100755 --- a/Snowflake.Data.Tests/SFDbDataReaderIT.cs +++ b/Snowflake.Data.Tests/SFDbDataReaderIT.cs @@ -594,7 +594,45 @@ public void testGetGuid() conn.Close(); } + + } + + [Test] + public void TestCopyCmdUpdateCount() + { + 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 testCopy (cola string)"; + cmd.ExecuteNonQuery(); + + 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 testCopy"; + cmd.ExecuteNonQuery(); + + conn.Close(); + } } } } 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; - } + } } }