Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita2d3979

Browse files
committed
feat: expose query job on dbapi cursor
1 parentcbbfeb5 commita2d3979

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

‎google/cloud/bigquery/dbapi/cursor.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ def __init__(self, connection):
7979
self._query_job=None
8080
self._closed=False
8181

82+
@property
83+
defquery_job(self):
84+
"""google.cloud.bigquery.job.query.QueryJob: The query job created by
85+
the last ``execute*()`` call.
86+
87+
.. note::
88+
If the last ``execute*()`` call was ``executemany()``, this is the
89+
last job created by ``executemany()``."""
90+
returnself._query_job
91+
8292
defclose(self):
8393
"""Mark the cursor as closed, preventing its further use."""
8494
self._closed=True

‎tests/unit/test_dbapi_cursor.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,29 @@ def test_is_iterable(self):
662662
"Iterating again over the same results should produce no rows.",
663663
)
664664

665+
deftest_query_job_wo_execute(self):
666+
fromgoogle.cloud.bigqueryimportdbapi
667+
668+
connection=dbapi.connect(self._mock_client())
669+
cursor=connection.cursor()
670+
self.assertIsNone(cursor.query_job)
671+
672+
deftest_query_job_w_execute(self):
673+
fromgoogle.cloud.bigqueryimportdbapi,QueryJob
674+
675+
connection=dbapi.connect(self._mock_client())
676+
cursor=connection.cursor()
677+
cursor.execute("SELECT 1;")
678+
self.assertIsInstance(cursor.query_job,QueryJob)
679+
680+
deftest_query_job_w_executemany(self):
681+
fromgoogle.cloud.bigqueryimportdbapi,QueryJob
682+
683+
connection=dbapi.connect(self._mock_client())
684+
cursor=connection.cursor()
685+
cursor.executemany("SELECT %s;", (("1",), ("2",)))
686+
self.assertIsInstance(cursor.query_job,QueryJob)
687+
665688
deftest__format_operation_w_dict(self):
666689
fromgoogle.cloud.bigquery.dbapiimportcursor
667690

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp