Skip to content

Commit

Permalink
Merge pull request #192 from snowflakedb/prep-1.1.2
Browse files Browse the repository at this point in the history
Prep 1.1.2
  • Loading branch information
sfc-gh-abhatnagar authored Mar 10, 2020
2 parents 3267ae6 + 4701410 commit 07bd91a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ using (IDbConnection conn = new SnowflakeDbConnection())

IDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into t values (?),(?),(?)";
IDataReader reader = cmd.ExecuteReader();

var p1 = cmd.CreateParameter();
p1.ParameterName = "1";
Expand Down
16 changes: 16 additions & 0 deletions Snowflake.Data.Tests/SFDbCommandIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,5 +487,21 @@ public void TestExecuteScalarNull()
conn.Close();
}
}

[Test]
public void TestCreateCommandBeforeOpeningConnection()
{
using(var conn = new SnowflakeDbConnection())
{
conn.ConnectionString = ConnectionString;

using(var command = conn.CreateCommand())
{
conn.Open();
command.CommandText = "select 1";
Assert.DoesNotThrow(() => command.ExecuteNonQuery());
}
}
}
}
}
22 changes: 18 additions & 4 deletions Snowflake.Data/Client/SnowflakeDbCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ public SnowflakeDbCommand(SnowflakeDbConnection connection)
{
logger.Debug("Constucting SnowflakeDbCommand class");
this.connection = connection;
this.sfStatement = new SFStatement(connection.SfSession);
// by default, no query timeout
this.CommandTimeout = 0;
parameterCollection = new SnowflakeDbParameterCollection();
}

public override string CommandText
{
get; set;
get; set;
}

public override int CommandTimeout
Expand Down Expand Up @@ -150,9 +149,10 @@ protected override DbTransaction DbTransaction

public override void Cancel()
{
sfStatement.Cancel();
// doesn't throw exception when sfStatement is null
sfStatement?.Cancel();
}

public override int ExecuteNonQuery()
{
logger.Debug($"ExecuteNonQuery, command: {CommandText}");
Expand Down Expand Up @@ -282,13 +282,27 @@ private static Dictionary<string, BindingDTO> convertToBindList(List<SnowflakeDb
}
}

private void SetStatement()
{
var session = (connection as SnowflakeDbConnection).SfSession;

// SetStatement is called when executing a command. If SfSession is null
// the connection has never been opened. Exception might be a bit vague.
if (session == null)
throw new Exception("Can't execute command when connection has never been opened");

this.sfStatement = new SFStatement(session);
}

private SFBaseResultSet ExecuteInternal(bool describeOnly = false)
{
SetStatement();
return sfStatement.Execute(CommandTimeout, CommandText, convertToBindList(parameterCollection.parameterList), describeOnly);
}

private Task<SFBaseResultSet> ExecuteInternalAsync(CancellationToken cancellationToken, bool describeOnly = false)
{
SetStatement();
return sfStatement.ExecuteAsync(CommandTimeout, CommandText, convertToBindList(parameterCollection.parameterList), describeOnly, cancellationToken);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data/Snowflake.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Product>Snowflake Connector for .NET</Product>
<Authors>howryu, tchen</Authors>
<Copyright>Copyright (c) 2012-2019 Snowflake Computing Inc. All rights reserved.</Copyright>
<Version>1.1.1</Version>
<Version>1.1.2</Version>
<DebugType>Full</DebugType>
</PropertyGroup>

Expand Down

0 comments on commit 07bd91a

Please sign in to comment.