MCPcopy Index your code
hub / github.com/cloudspannerecosystem/spanner-cli / Execute

Method Execute

statement.go:813–835  ·  view source on GitHub ↗
(ctx context.Context, session *Session)

Source from the content-addressed store, hash-verified

811}
812
813func (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
837type DmlStatement struct {
838 Dml string

Callers

nothing calls this directly

Calls 2

InReadOnlyTransactionMethod · 0.80

Tested by

no test coverage detected