Skip to content

Commit 30a0666

Browse files
authored
docs: describe DB API and transactions retry mechanism (#844)
Closes #791
1 parent ab768e4 commit 30a0666

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,31 @@ if any of the records does not already exist.
235235
)
236236
237237
238+
Connection API
239+
--------------
240+
Connection API represents a wrap-around for Python Spanner API, written in accordance with PEP-249, and provides a simple way of communication with a Spanner database through connection objects:
241+
242+
.. code:: python
243+
244+
from google.cloud.spanner_dbapi.connection import connect
245+
246+
connection = connect("instance-id", "database-id")
247+
connection.autocommit = True
248+
249+
cursor = connection.cursor()
250+
cursor.execute("SELECT * FROM table_name")
251+
252+
result = cursor.fetchall()
253+
254+
255+
Aborted Transactions Retry Mechanism
256+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
257+
258+
In ``!autocommit`` mode, transactions can be aborted due to transient errors. In most cases retry of an aborted transaction solves the problem. To simplify it, connection tracks SQL statements, executed in the current transaction. In case the transaction aborted, the connection initiates a new one and re-executes all the statements. In the process, the connection checks that retried statements are returning the same results that the original statements did. If results are different, the transaction is dropped, as the underlying data changed, and auto retry is impossible.
259+
260+
Auto-retry of aborted transactions is enabled only for ``!autocommit`` mode, as in ``autocommit`` mode transactions are never aborted.
261+
262+
238263
Next Steps
239264
~~~~~~~~~~
240265

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy