Skip to content
Permalink
Browse files
fix(samples): batch_update() results processing error (#484)
* fix(samples): batch_update() results processing error

* fix the comment

* minor fix

Co-authored-by: larkee <31196561+larkee@users.noreply.github.com>
  • Loading branch information
Ilya Gurov and larkee committed Aug 15, 2021
1 parent d557a8d commit bdd5f8b201d1b442837d4fca1d631fe171e276b9
Showing with 9 additions and 1 deletion.
  1. +9 −1 samples/samples/snippets.py
@@ -1511,6 +1511,8 @@ def delete_data_with_partitioned_dml(instance_id, database_id):
def update_with_batch_dml(instance_id, database_id):
"""Updates sample data in the database using Batch DML. """
# [START spanner_dml_batch_update]
from google.rpc.code_pb2 import OK

# instance_id = "your-spanner-instance"
# database_id = "your-spanner-db-id"

@@ -1531,7 +1533,13 @@ def update_with_batch_dml(instance_id, database_id):
)

def update_albums(transaction):
row_cts = transaction.batch_update([insert_statement, update_statement])
status, row_cts = transaction.batch_update([insert_statement, update_statement])

if status.code != OK:
# Do handling here.
# Note: the exception will still be raised when
# `commit` is called by `run_in_transaction`.
return

print("Executed {} SQL statements using Batch DML.".format(len(row_cts)))

0 comments on commit bdd5f8b

Please sign in to comment.