(ctx context.Context, session *Session)
| 236 | } |
| 237 | |
| 238 | func (s *SelectStatement) Execute(ctx context.Context, session *Session) (*Result, error) { |
| 239 | stmt := spanner.NewStatement(s.Query) |
| 240 | |
| 241 | iter, roTxn := session.RunQueryWithStats(ctx, stmt) |
| 242 | defer iter.Stop() |
| 243 | |
| 244 | rows, columnNames, err := parseQueryResult(iter) |
| 245 | if err != nil { |
| 246 | if session.InReadWriteTransaction() && spanner.ErrCode(err) == codes.Aborted { |
| 247 | // Need to call rollback to free the acquired session in underlying google-cloud-go/spanner. |
| 248 | rollback := &RollbackStatement{} |
| 249 | rollback.Execute(ctx, session) |
| 250 | } |
| 251 | return nil, err |
| 252 | } |
| 253 | result := &Result{ |
| 254 | ColumnNames: columnNames, |
| 255 | Rows: rows, |
| 256 | } |
| 257 | result.ColumnTypes = iter.Metadata.GetRowType().GetFields() |
| 258 | |
| 259 | queryStats := parseQueryStats(iter.QueryStats) |
| 260 | rowsReturned, err := strconv.Atoi(queryStats.RowsReturned) |
| 261 | if err != nil { |
| 262 | return nil, fmt.Errorf("rowsReturned is invalid: %v", err) |
| 263 | } |
| 264 | |
| 265 | result.AffectedRows = rowsReturned |
| 266 | result.Stats = queryStats |
| 267 | |
| 268 | // ReadOnlyTransaction.Timestamp() is invalid until read. |
| 269 | if roTxn != nil { |
| 270 | result.Timestamp, _ = roTxn.Timestamp() |
| 271 | } |
| 272 | |
| 273 | return result, nil |
| 274 | } |
| 275 | |
| 276 | // extractColumnNames extract column names from ResultSetMetadata.RowType.Fields. |
| 277 | func extractColumnNames(fields []*pb.StructType_Field) []string { |
nothing calls this directly
no test coverage detected