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

catch error in multi-query batches #140

Merged
merged 7 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ env/
venv/
ENV/
env.bak/
venv.bak/
venv.bak/

# example credential information
cxn.json
35 changes: 35 additions & 0 deletions cursor_batch_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "02af0c28-3445-49f6-a97c-b82f28920a39",
"metadata": {},
"outputs": [],
"source": [
"i"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
15 changes: 11 additions & 4 deletions dbt/adapters/sqlserver/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def add_query(self, sql, auto_begin=True, bindings=None, abridge_sql_log=False):

# pyodbc does not handle a None type binding!
if bindings is None:
cursor.execute(sql)
cursor2 = cursor.execute(sql)
else:
cursor.execute(sql, bindings)

Expand All @@ -356,7 +356,7 @@ def add_query(self, sql, auto_begin=True, bindings=None, abridge_sql_log=False):
self.get_response(cursor), (time.time() - pre)
)
)

return connection, cursor

@classmethod
Expand All @@ -383,9 +383,16 @@ def get_response(cls, cursor) -> AdapterResponse:

def execute(self, sql, auto_begin=True, fetch=False):
_, cursor = self.add_query(sql, auto_begin)
status = self.get_response(cursor)
response = self.get_response(cursor)
if fetch:
# Get the result of the first non-empty result set (if any)
while cursor.description is None:
if not cursor.nextset():
break
table = self.get_result_from_cursor(cursor)
else:
table = dbt.clients.agate_helper.empty_table()
return status, table
# Step through all result sets so we process all errors
while cursor.nextset():
pass
return response, table