googleapis / googleapis/dotnet-spanner-entity-framework

DML with RETURNING statements do not return update count / affected rows

Open
#777 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
34
Forks
13
Avg merge
4h 39m
Merged PRs (30d)
10

Description

### Description
When executing a DML statement containing a `RETURNING` clause (e.g., `INSERT INTO table ... RETURNING id`), `RecordsAffected` returns `0` instead of the actual number of rows inserted/updated.

### Root Cause
1. In Cloud Spanner, DML statements with a `RETURNING` clause are executed as queries (returning a row stream).
2. The Google Cloud Spanner Go client library (`google-cloud-go`) does not populate the `RowCount` field on query row iterators (unlike standard DML iterators).
3. The Go SQL proxy driver (`go-sql-spanner`) relies on `it.RowCount` to populate the `ResultSetStats.RowCountExact` field. Because this field is not set by the Go client for query iterators, the Go proxy receives a row count of `0` and propagates `rowCountExact: 0` back to the C# ADO.NET client.
4. As a result, the C# client always receives `0` for `RecordsAffected` for DML statements with a returning clause.

### Steps to Reproduce
1. Execute a DML returning statement using `ExecuteReader` or `ExecuteReaderAsync`.
2. Drain the reader completely.
3. Read the `RecordsAffected` property. It will be `0` instead of the expected row count.

Contributor guide

Open the contributing guide

Research direction

Start at ExecuteReader and ExecuteReaderAsync, then trace how RecordsAffected receives rowCountExact from go-sql-spanner and Cloud Spanner. Reproduce with a DML RETURNING statement, drain the reader, and verify that RecordsAffected reports the affected-row count instead of 0.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.