(ctx context.Context, session *Session)
| 811 | } |
| 812 | |
| 813 | func (s *TruncateTableStatement) Execute(ctx context.Context, session *Session) (*Result, error) { |
| 814 | if session.InReadWriteTransaction() { |
| 815 | // PartitionedUpdate creates a new transaction and it could cause dead lock with the current running transaction. |
| 816 | return nil, errors.New(`"TRUNCATE TABLE" can not be used in a read-write transaction`) |
| 817 | } |
| 818 | if session.InReadOnlyTransaction() { |
| 819 | // Just for user-friendly. |
| 820 | return nil, errors.New(`"TRUNCATE TABLE" can not be used in a read-only transaction`) |
| 821 | } |
| 822 | |
| 823 | stmt := spanner.NewStatement(fmt.Sprintf("DELETE FROM `%s` WHERE true", s.Table)) |
| 824 | ctx, cancel := context.WithTimeout(ctx, pdmlTimeout) |
| 825 | defer cancel() |
| 826 | |
| 827 | count, err := session.client.PartitionedUpdate(ctx, stmt) |
| 828 | if err != nil { |
| 829 | return nil, err |
| 830 | } |
| 831 | return &Result{ |
| 832 | IsMutation: true, |
| 833 | AffectedRows: int(count), |
| 834 | }, nil |
| 835 | } |
| 836 | |
| 837 | type DmlStatement struct { |
| 838 | Dml string |
nothing calls this directly
no test coverage detected