@@ -259,8 +259,8 @@ type conn struct {
259259 resetForRetry bool
260260 database string
261261
262- execSingleQuery func (ctx context.Context , c * spanner.Client , statement spanner.Statement , bound spanner.TimestampBound , options * ExecOptions ) * spanner.RowIterator
263- execSingleQueryTransactional func (ctx context.Context , c * spanner.Client , statement spanner.Statement , options * ExecOptions ) (rowIterator , * spanner.CommitResponse , error )
262+ execSingleQuery func (ctx context.Context , c * spanner.Client , statement spanner.Statement , statementInfo * parser. StatementInfo , bound spanner.TimestampBound , options * ExecOptions ) * spanner.RowIterator
263+ execSingleQueryTransactional func (ctx context.Context , c * spanner.Client , statement spanner.Statement , statementInfo * parser. StatementInfo , options * ExecOptions ) (rowIterator , * spanner.CommitResponse , error )
264264 execSingleDMLTransactional func (ctx context.Context , c * spanner.Client , statement spanner.Statement , statementInfo * parser.StatementInfo , options * ExecOptions ) (* result , * spanner.CommitResponse , error )
265265 execSingleDMLPartitioned func (ctx context.Context , c * spanner.Client , statement spanner.Statement , options * ExecOptions ) (int64 , error )
266266
@@ -831,9 +831,9 @@ func (c *conn) queryContext(ctx context.Context, query string, execOptions *Exec
831831 if err != nil {
832832 return nil , err
833833 }
834- statementType := c .parser .DetectStatementType (query )
834+ statementInfo := c .parser .DetectStatementType (query )
835835 // DDL statements are not supported in QueryContext so use the execContext method for the execution.
836- if statementType .StatementType == parser .StatementTypeDdl {
836+ if statementInfo .StatementType == parser .StatementTypeDdl {
837837 res , err := c .execContext (ctx , query , execOptions , args )
838838 if err != nil {
839839 return nil , err
@@ -842,10 +842,10 @@ func (c *conn) queryContext(ctx context.Context, query string, execOptions *Exec
842842 }
843843 var iter rowIterator
844844 if c .tx == nil {
845- if statementType .StatementType == parser .StatementTypeDml {
845+ if statementInfo .StatementType == parser .StatementTypeDml {
846846 // Use a read/write transaction to execute the statement.
847847 var commitResponse * spanner.CommitResponse
848- iter , commitResponse , err = c .execSingleQueryTransactional (ctx , c .client , stmt , execOptions )
848+ iter , commitResponse , err = c .execSingleQueryTransactional (ctx , c .client , stmt , statementInfo , execOptions )
849849 if err != nil {
850850 return nil , err
851851 }
@@ -858,13 +858,13 @@ func (c *conn) queryContext(ctx context.Context, query string, execOptions *Exec
858858 // The statement was either detected as being a query, or potentially not recognized at all.
859859 // In that case, just default to using a single-use read-only transaction and let Spanner
860860 // return an error if the statement is not suited for that type of transaction.
861- iter = & readOnlyRowIterator {c .execSingleQuery (ctx , c .client , stmt , c .ReadOnlyStaleness (), execOptions )}
861+ iter = & readOnlyRowIterator {c .execSingleQuery (ctx , c .client , stmt , statementInfo , c .ReadOnlyStaleness (), execOptions ), statementInfo . StatementType }
862862 }
863863 } else {
864864 if execOptions .PartitionedQueryOptions .PartitionQuery {
865865 return c .tx .partitionQuery (ctx , stmt , execOptions )
866866 }
867- iter , err = c .tx .Query (ctx , stmt , execOptions )
867+ iter , err = c .tx .Query (ctx , stmt , statementInfo . StatementType , execOptions )
868868 if err != nil {
869869 return nil , err
870870 }
@@ -1273,7 +1273,7 @@ func (c *conn) rollback(ctx context.Context) error {
12731273 return c .tx .Rollback ()
12741274}
12751275
1276- func queryInSingleUse (ctx context.Context , c * spanner.Client , statement spanner.Statement , tb spanner.TimestampBound , options * ExecOptions ) * spanner.RowIterator {
1276+ func queryInSingleUse (ctx context.Context , c * spanner.Client , statement spanner.Statement , statementInfo * parser. StatementInfo , tb spanner.TimestampBound , options * ExecOptions ) * spanner.RowIterator {
12771277 return c .Single ().WithTimestampBound (tb ).QueryWithOptions (ctx , statement , options .QueryOptions )
12781278}
12791279
@@ -1295,7 +1295,7 @@ func (c *conn) executeAutoPartitionedQuery(ctx context.Context, query string, ex
12951295 return r , nil
12961296}
12971297
1298- func queryInNewRWTransaction (ctx context.Context , c * spanner.Client , statement spanner.Statement , options * ExecOptions ) (rowIterator , * spanner.CommitResponse , error ) {
1298+ func queryInNewRWTransaction (ctx context.Context , c * spanner.Client , statement spanner.Statement , statementInfo * parser. StatementInfo , options * ExecOptions ) (rowIterator , * spanner.CommitResponse , error ) {
12991299 var result * wrappedRowIterator
13001300 options .QueryOptions .LastStatement = true
13011301 fn := func (ctx context.Context , tx * spanner.ReadWriteTransaction ) error {
@@ -1304,6 +1304,7 @@ func queryInNewRWTransaction(ctx context.Context, c *spanner.Client, statement s
13041304 if err == iterator .Done {
13051305 result = & wrappedRowIterator {
13061306 RowIterator : it ,
1307+ stmtType : statementInfo .StatementType ,
13071308 noRows : true ,
13081309 }
13091310 } else if err != nil {
@@ -1312,6 +1313,7 @@ func queryInNewRWTransaction(ctx context.Context, c *spanner.Client, statement s
13121313 } else {
13131314 result = & wrappedRowIterator {
13141315 RowIterator : it ,
1316+ stmtType : statementInfo .StatementType ,
13151317 firstRow : row ,
13161318 }
13171319 }
0 commit comments