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
- In Cloud Spanner, DML statements with a
RETURNING clause are executed as queries (returning a row stream).
- The Google Cloud Spanner Go client library (
google-cloud-go) does not populate the RowCount field on query row iterators (unlike standard DML iterators).
- 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.
- As a result, the C# client always receives
0 for RecordsAffected for DML statements with a returning clause.
Steps to Reproduce
- Execute a DML returning statement using
ExecuteReader or ExecuteReaderAsync.
- Drain the reader completely.
- Read the
RecordsAffected property. It will be 0 instead of the expected row count.
Description
When executing a DML statement containing a
RETURNINGclause (e.g.,INSERT INTO table ... RETURNING id),RecordsAffectedreturns0instead of the actual number of rows inserted/updated.Root Cause
RETURNINGclause are executed as queries (returning a row stream).google-cloud-go) does not populate theRowCountfield on query row iterators (unlike standard DML iterators).go-sql-spanner) relies onit.RowCountto populate theResultSetStats.RowCountExactfield. Because this field is not set by the Go client for query iterators, the Go proxy receives a row count of0and propagatesrowCountExact: 0back to the C# ADO.NET client.0forRecordsAffectedfor DML statements with a returning clause.Steps to Reproduce
ExecuteReaderorExecuteReaderAsync.RecordsAffectedproperty. It will be0instead of the expected row count.