Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions google/cloud/spanner_dbapi/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ def executemany(self, operation, seq_of_params):

many_result_set = StreamedManyResultSets()

# For every operation, we've got to ensure that any prior DDL
Comment thread
olavloite marked this conversation as resolved.
# statements were run.
self.connection.run_prior_DDL_statements()
Comment thread
olavloite marked this conversation as resolved.

if class_ in (parse_utils.STMT_INSERT, parse_utils.STMT_UPDATING):
statements = []

Expand Down
44 changes: 44 additions & 0 deletions tests/system/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,50 @@ def test_DDL_autocommit(shared_instance, dbapi_database):
op.result()


def test_ddl_executemany(shared_instance, dbapi_database):
"""Check that DDLs in autocommit mode are immediately executed."""
Comment thread
ankiaga marked this conversation as resolved.
Outdated

try:
conn = Connection(shared_instance, dbapi_database)
want_row = (
Comment thread
ankiaga marked this conversation as resolved.
Outdated
1,
"first-name",
)
cur = conn.cursor()
cur.execute(
"""
CREATE TABLE Singers (
SingerId INT64 NOT NULL,
Name STRING(1024),
) PRIMARY KEY (SingerId)
"""
)
cur.executemany(
"""
INSERT INTO Singers (SingerId, Name)
VALUES (%s, %s)
""",
[want_row],
)
conn.commit()

# read the resulting data from the database
cur.execute("SELECT * FROM Singers")
got_rows = cur.fetchall()

assert got_rows == [want_row]

cur.close()
conn.close()

finally:
# Delete table
table = dbapi_database.table("Singers")
if table.exists():
op = dbapi_database.update_ddl(["DROP TABLE Singers"])
Comment thread
ankiaga marked this conversation as resolved.
Outdated
op.result()


@pytest.mark.skipif(_helpers.USE_EMULATOR, reason="Emulator does not support json.")
def test_autocommit_with_json_data(shared_instance, dbapi_database):
"""
Expand Down