Skip to content

Commit 373359a

Browse files
committed
SNOW-27749: query_results method doesn't return sfqid and sqlstate in Python Connector.
1 parent dc6a9fe commit 373359a

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

cursor.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,14 @@ def chunk_info(self, data, use_ijson=False):
589589
def query_result(self, qid, _use_ijson=False):
590590
url = ('/queries/{qid}/result').format(qid=qid)
591591
ret = self._connection._con.request(url=url, method='get')
592+
self._sfqid = ret[u'data'][
593+
u'queryId'] if u'data' in ret and u'queryId' in ret[
594+
u'data'] else None
595+
self._sqlstate = ret[u'data'][
596+
u'sqlState'] if u'data' in ret and u'sqlState' in ret[
597+
u'data'] else None
598+
self.logger.debug(u'sfqid=%s', self._sfqid)
599+
592600
if ret.get(u'success'):
593601
data = ret.get(u'data')
594602
self.chunk_info(data, use_ijson=_use_ijson)

test/test_results.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2012-2017 Snowflake Computing Inc. All right reserved.
5+
#
6+
7+
import pytest
8+
9+
from snowflake.connector import ProgrammingError
10+
11+
12+
def test_results(conn_cnx):
13+
"""
14+
Gets results for the given qid
15+
"""
16+
with conn_cnx() as cnx:
17+
cur = cnx.cursor()
18+
cur.execute("select * from values(1,2),(3,4)")
19+
sfqid = cur.sfqid
20+
cur = cur.query_result(sfqid)
21+
got_sfqid = cur.sfqid
22+
assert cur.fetchall() == [(1, 2), (3, 4)]
23+
assert sfqid == got_sfqid
24+
25+
26+
def test_results_with_error(conn_cnx):
27+
"""
28+
Gets results with error
29+
"""
30+
with conn_cnx() as cnx:
31+
cur = cnx.cursor()
32+
sfqid = None
33+
try:
34+
cur.execute("select blah")
35+
pytest.fail("Should fail here!")
36+
except ProgrammingError as e:
37+
sfqid = e.sfqid
38+
39+
got_sfqid = None
40+
try:
41+
cur.query_result(sfqid)
42+
pytest.fail("Should fail here again!")
43+
except ProgrammingError as e:
44+
got_sfqid = e.sfqid
45+
46+
assert got_sfqid is not None
47+
assert got_sfqid == sfqid

0 commit comments

Comments
 (0)