Skip to content

Commit

Permalink
SNOW-950923 Description of the changes regarding query id in exceptio…
Browse files Browse the repository at this point in the history
…n for put/get
  • Loading branch information
sfc-gh-mhofman committed Feb 12, 2024
1 parent c232a6f commit 24353f2
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,66 @@ using (IDbConnection conn = new SnowflakeDbConnection())
}
```

PUT local files to stage
------------------------

PUT command can be used to upload files of a local directory or a single local file to the Snowflake stages (named, internal table stage or internal user stage).
Such staging files can be used to load data into a table.
More on this topic: [File staging with PUT](https://docs.snowflake.com/en/sql-reference/sql/put).

In the driver the command can be executed in a bellow way:
```cs
using (IDbConnection conn = new SnowflakeDbConnection())
{
try
{
conn.ConnectionString = "<connecting parameter>";
conn.Open();
var cmd = (SnowflakeDbCommand)conn.CreateCommand(); // cast allows get QueryId from the command
cmd.CommandText = $"PUT file://some_data.csv @my_schema.my_stage AUTO_COMPRESS=TRUE";
var reader = cmd.ExecuteReader();
Assert.IsTrue(reader.read()); // on success
Assert.DoesNotThrow(() => Guid.Parse(cmd.GetQueryId()));
}
catch (SnowflakeDbException e)
{
Assert.DoesNotThrow(() => Guid.Parse(e.QueryId)); // when failed
Assert.That(e.InnerException.GetType(), Is.EqualTo(typeof(FileNotFoundException)));

}
```
In case of a failure a SnowflakeDbException will be thrown and will provide QueryId.
Inner exception (if applicable) will provide some details on the failure cause and
it will be for example: FileNotFoundException, DirectoryNotFoundException.

GET stage files
---------------
GET command allows to download stage directories or files to a local directory.
It can be used in connection with named stage, table internal stage or user stage.
Detailed information on the command: [Downloading files with GET](https://docs.snowflake.com/en/sql-reference/sql/get).
To use the command in a driver similar code can be executed in a client app:
```cs
try
{
conn.ConnectionString = "<connecting parameter>";
conn.Open();
var cmd = (SnowflakeDbCommand)conn.CreateCommand(); // cast allows get QueryId from the command
cmd.CommandText = $"GET @my_schema.my_stage/stage_file.csv file://local_file.csv AUTO_COMPRESS=TRUE";
var reader = cmd.ExecuteReader();
Assert.IsTrue(reader.read()); // if succeeded
Assert.DoesNotThrow(() => Guid.Parse(cmd.GetQueryId()));
}
catch (SnowflakeDbException e)
{
Assert.DoesNotThrow(() => Guid.Parse(e.QueryId)); // on failure
}
```
In case of a failure a SnowflakeDbException will be thrown or DBDataReader will return a False response.
In any case QueryId should be available from the exception or command property.

Close the Connection
--------------------

Expand Down

0 comments on commit 24353f2

Please sign in to comment.