Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Executing existing DDL statements on executemany statement execution #1032

Merged
merged 6 commits into from
Nov 17, 2023
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
olavloite marked this conversation as resolved.
Show resolved Hide resolved
# statements were run.
self.connection.run_prior_DDL_statements()
olavloite marked this conversation as resolved.
Show resolved Hide 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."""
ankiaga marked this conversation as resolved.
Show resolved Hide resolved

try:
conn = Connection(shared_instance, dbapi_database)
want_row = (
ankiaga marked this conversation as resolved.
Show resolved Hide resolved
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"])
ankiaga marked this conversation as resolved.
Show resolved Hide resolved
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