snowflake-db-net-client icon indicating copy to clipboard operation
snowflake-db-net-client copied to clipboard

Run multiple sql statements in a transaction?

Open Yash-Poddar opened this issue 2 years ago • 1 comments

Hi,

I'm unable to use Begin; ... Commit; in ExecuteAsync(). I'm getting the following error - " Snowflake.Client.Model.SnowflakeException : Query execution failed. Message: Multiple SQL statements in a single API call are not supported; use one API call per statement instead."

Is there a workaround or something so that I can use transaction?

Yash-Poddar avatar May 30 '23 07:05 Yash-Poddar

Hi,

Multiple statements feature was recently added in official connector and it's not supported yet in this project. One of the issues here is that they check DriverVersion field, for this feature it should be equal or greater than "2.0.18". The problem is that this library uses it's own versioning and sends something like "0.4.5.0".

Otherwise I think it would be enough to change MULTI_STATEMENT_COUNT to 0. Something like this:

var result1 = await _snowflakeClient.ExecuteScalarAsync("ALTER SESSION SET MULTI_STATEMENT_COUNT = 0;");
var result2 = await _snowflakeClient.ExecuteScalarAsync<int>("SELECT 1; SELECT 2;");

I'm gonna work on this in next release.

fixer-m avatar Jun 04 '23 16:06 fixer-m