@@ -262,8 +262,8 @@ type conn struct {
262262 resetForRetry bool
263263 database string
264264
265- execSingleQuery func (ctx context.Context , c * spanner.Client , statement spanner.Statement , bound spanner.TimestampBound , options * ExecOptions ) * spanner.RowIterator
266- execSingleQueryTransactional func (ctx context.Context , c * spanner.Client , statement spanner.Statement , options * ExecOptions ) (rowIterator , * spanner.CommitResponse , error )
265+ execSingleQuery func (ctx context.Context , c * spanner.Client , statement spanner.Statement , statementInfo * parser. StatementInfo , bound spanner.TimestampBound , options * ExecOptions ) * spanner.RowIterator
266+ execSingleQueryTransactional func (ctx context.Context , c * spanner.Client , statement spanner.Statement , statementInfo * parser. StatementInfo , options * ExecOptions ) (rowIterator , * spanner.CommitResponse , error )
267267 execSingleDMLTransactional func (ctx context.Context , c * spanner.Client , statement spanner.Statement , statementInfo * parser.StatementInfo , options * ExecOptions ) (* result , * spanner.CommitResponse , error )
268268 execSingleDMLPartitioned func (ctx context.Context , c * spanner.Client , statement spanner.Statement , options * ExecOptions ) (int64 , error )
269269
@@ -860,9 +860,9 @@ func (c *conn) queryContext(ctx context.Context, query string, execOptions *Exec
860860 if err != nil {
861861 return nil , err
862862 }
863- statementType := c .parser .DetectStatementType (query )
863+ statementInfo := c .parser .DetectStatementType (query )
864864 // DDL statements are not supported in QueryContext so use the execContext method for the execution.
865- if statementType .StatementType == parser .StatementTypeDdl {
865+ if statementInfo .StatementType == parser .StatementTypeDdl {
866866 res , err := c .execContext (ctx , query , execOptions , args )
867867 if err != nil {
868868 return nil , err
@@ -871,10 +871,10 @@ func (c *conn) queryContext(ctx context.Context, query string, execOptions *Exec
871871 }
872872 var iter rowIterator
873873 if c .tx == nil {
874- if statementType .StatementType == parser .StatementTypeDml {
874+ if statementInfo .StatementType == parser .StatementTypeDml {
875875 // Use a read/write transaction to execute the statement.
876876 var commitResponse * spanner.CommitResponse
877- iter , commitResponse , err = c .execSingleQueryTransactional (ctx , c .client , stmt , execOptions )
877+ iter , commitResponse , err = c .execSingleQueryTransactional (ctx , c .client , stmt , statementInfo , execOptions )
878878 if err != nil {
879879 return nil , err
880880 }
@@ -887,13 +887,13 @@ func (c *conn) queryContext(ctx context.Context, query string, execOptions *Exec
887887 // The statement was either detected as being a query, or potentially not recognized at all.
888888 // In that case, just default to using a single-use read-only transaction and let Spanner
889889 // return an error if the statement is not suited for that type of transaction.
890- iter = & readOnlyRowIterator {c .execSingleQuery (ctx , c .client , stmt , c .ReadOnlyStaleness (), execOptions )}
890+ iter = & readOnlyRowIterator {c .execSingleQuery (ctx , c .client , stmt , statementInfo , c .ReadOnlyStaleness (), execOptions ), statementInfo . StatementType }
891891 }
892892 } else {
893893 if execOptions .PartitionedQueryOptions .PartitionQuery {
894894 return c .tx .partitionQuery (ctx , stmt , execOptions )
895895 }
896- iter , err = c .tx .Query (ctx , stmt , execOptions )
896+ iter , err = c .tx .Query (ctx , stmt , statementInfo . StatementType , execOptions )
897897 if err != nil {
898898 return nil , err
899899 }
@@ -1341,7 +1341,7 @@ func (c *conn) Rollback(ctx context.Context) error {
13411341 return c .tx .Rollback ()
13421342}
13431343
1344- func queryInSingleUse (ctx context.Context , c * spanner.Client , statement spanner.Statement , tb spanner.TimestampBound , options * ExecOptions ) * spanner.RowIterator {
1344+ func queryInSingleUse (ctx context.Context , c * spanner.Client , statement spanner.Statement , statementInfo * parser. StatementInfo , tb spanner.TimestampBound , options * ExecOptions ) * spanner.RowIterator {
13451345 return c .Single ().WithTimestampBound (tb ).QueryWithOptions (ctx , statement , options .QueryOptions )
13461346}
13471347
@@ -1363,7 +1363,7 @@ func (c *conn) executeAutoPartitionedQuery(ctx context.Context, query string, ex
13631363 return r , nil
13641364}
13651365
1366- func queryInNewRWTransaction (ctx context.Context , c * spanner.Client , statement spanner.Statement , options * ExecOptions ) (rowIterator , * spanner.CommitResponse , error ) {
1366+ func queryInNewRWTransaction (ctx context.Context , c * spanner.Client , statement spanner.Statement , statementInfo * parser. StatementInfo , options * ExecOptions ) (rowIterator , * spanner.CommitResponse , error ) {
13671367 var result * wrappedRowIterator
13681368 options .QueryOptions .LastStatement = true
13691369 fn := func (ctx context.Context , tx * spanner.ReadWriteTransaction ) error {
@@ -1372,6 +1372,7 @@ func queryInNewRWTransaction(ctx context.Context, c *spanner.Client, statement s
13721372 if err == iterator .Done {
13731373 result = & wrappedRowIterator {
13741374 RowIterator : it ,
1375+ stmtType : statementInfo .StatementType ,
13751376 noRows : true ,
13761377 }
13771378 } else if err != nil {
@@ -1380,6 +1381,7 @@ func queryInNewRWTransaction(ctx context.Context, c *spanner.Client, statement s
13801381 } else {
13811382 result = & wrappedRowIterator {
13821383 RowIterator : it ,
1384+ stmtType : statementInfo .StatementType ,
13831385 firstRow : row ,
13841386 }
13851387 }
0 commit comments