Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for multiple sql statements in single request #40

Merged
merged 4 commits into from
Jun 13, 2023

Conversation

test "handles multi-statement requests", c do
assert {:ok, %Avalanche.Result{statement_handles: statement_handles} = result} =
Avalanche.run("begin transaction;select ?;select ? as two;commit;", [1, 2], [], c.options)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that for parameter substitution this is still treated as one statement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result from run is for all statements together.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha this is so cool

assert result.status == :complete
assert length(statement_handles) == 4

[sh1, sh2, sh3, sh4] = statement_handles
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need the results from one or more of the statements, you need to know which one it was in the order, get that statement handle, and then call status to get the results.

[sh1, sh2, sh3, sh4] = statement_handles

assert {:ok, %Avalanche.Result{rows: [%{"status" => "Statement executed successfully."}]}} =
Avalanche.status(sh1, [], c.options)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is begin transaction;.

assert {:ok, %Avalanche.Result{rows: [%{"TWO" => 2.0}]}} = Avalanche.status(sh3, [], c.options)

assert {:ok, %Avalanche.Result{rows: [%{"status" => "Statement executed successfully."}]}} =
Avalanche.status(sh4, [], c.options)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is commit;.


assert {:ok, %Avalanche.Result{} = result2} =
Avalanche.run(
"SELECT * FROM SNOWFLAKE_SAMPLE_DATA.WEATHER.DAILY_14_TOTAL LIMIT 1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SNOWFLAKE_SAMPLE_DATA.WEATHER was removed by Snowflake.

@forest forest merged commit 3c8830a into main Jun 13, 2023
@forest forest deleted the multi-statement-queries branch June 13, 2023 17:09
hgdeploy pushed a commit that referenced this pull request Jun 13, 2023
# [0.12.0](v0.11.7...v0.12.0) (2023-06-13)

### Features

* add support for multiple sql statements in single request (#40) ([3c8830a](3c8830a)), closes [#40](#40)
@hgdeploy
Copy link

🎉 This PR is included in version 0.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants