@@ -3188,27 +3188,34 @@ def isolation_level_options(
31883188 # instance_id = "your-spanner-instance"
31893189 # database_id = "your-spanner-db-id"
31903190
3191- isolation_level_options_for_client = TransactionOptions . IsolationLevel . SERIALIZABLE
3192-
3193- # The isolation level specified at the client level via default_transaction_options will be applied to all RW transactions
3191+ # The isolation level specified at the client-level will be applied to all RW transactions.
3192+ isolation_options_for_client = TransactionOptions . IsolationLevel . SERIALIZABLE
3193+
31943194 spanner_client = spanner .Client (
3195- default_transaction_options = DefaultTransactionOptions (isolation_level = isolation_level_options_for_client )
3195+ default_transaction_options = DefaultTransactionOptions (isolation_level = isolation_options_for_client )
31963196 )
31973197 instance = spanner_client .instance (instance_id )
31983198 database = instance .database (database_id )
31993199
3200- isolation_level_options_for_request = TransactionOptions .IsolationLevel .REPEATABLE_READ
3200+ # The isolation level specified at the request level takes precedence over the isolation level configured at the client level.
3201+ isolation_options_for_transaction = TransactionOptions .IsolationLevel .REPEATABLE_READ
32013202
3202- def insert_singers (transaction ):
3203+ def update_albums_with_isolation (transaction ):
3204+ # Read an AlbumTitle.
3205+ results = transaction .execute_sql (
3206+ "SELECT AlbumTitle from Albums WHERE SingerId = 1 and AlbumId = 1"
3207+ )
3208+ for result in results :
3209+ print ("Current Album Title: {}" .format (* result ))
3210+
3211+ # Update the AlbumTitle.
32033212 row_ct = transaction .execute_update (
3204- "INSERT INTO Singers (SingerId, FirstName, LastName) "
3205- " VALUES (20, 'Virginia', 'Watson')"
3213+ "UPDATE Albums SET AlbumTitle = 'A New Title' WHERE SingerId = 1 and AlbumId = 1"
32063214 )
32073215
3208- print ("{} record(s) inserted ." .format (row_ct ))
3216+ print ("{} record(s) updated ." .format (row_ct ))
32093217
3210- # The isolation level specified at the request level takes precedence over the isolation level configured at the client level.
3211- database .run_in_transaction (insert_singers , isolation_level = isolation_level_options_for_request )
3218+ database .run_in_transaction (update_albums_with_isolation , isolation_level = isolation_options_for_transaction )
32123219 # [END spanner_isolation_level]
32133220
32143221
0 commit comments