Skip to content

Commit

Permalink
Merge pull request #36 from snowflakedb/pr-32
Browse files Browse the repository at this point in the history
Pr 32
  • Loading branch information
howryu authored May 25, 2018
2 parents 8830d6a + de5d945 commit 9290e9a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
38 changes: 38 additions & 0 deletions Snowflake.Data.Tests/SFDbDataReaderIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
11 changes: 6 additions & 5 deletions Snowflake.Data/Core/ResultSetUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<resultSet.columnCount; i++)
for (int i = 0; i < resultSet.columnCount; i++)
{
updateCount += resultSet.GetValue<int>(i);
}
break;
case SFStatementType.COPY:
updateCount = resultSet.GetValue<int>(3);
var index = resultSet.sfResultSetMetaData.getColumnIndexByName("rows_loaded");
if (index >= 0) updateCount = resultSet.GetValue<int>(index);
break;
case SFStatementType.SELECT:
updateCount = -1;
Expand All @@ -42,6 +43,6 @@ internal static int CalculateUpdateCount(this SFBaseResultSet resultSet)
}

return updateCount;
}
}
}
}

0 comments on commit 9290e9a

Please sign in to comment.