modernc.org/ql@v1.4.7/errors.go (about)

     1  // Copyright 2014 The ql Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ql // import "modernc.org/ql"
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"errors"
    11  )
    12  
    13  var (
    14  	errBeginTransNoCtx          = errors.New("BEGIN TRANSACTION: Must use R/W context, have nil")
    15  	errCommitNotInTransaction   = errors.New("COMMIT: Not in transaction")
    16  	errDivByZero                = errors.New("division by zero")
    17  	errIncompatibleDBFormat     = errors.New("incompatible DB format")
    18  	errNoDataForHandle          = errors.New("read: no data for handle")
    19  	errRollbackNotInTransaction = errors.New("ROLLBACK: Not in transaction")
    20  )
    21  
    22  type errDuplicateUniqueIndex []interface{}
    23  
    24  func (err errDuplicateUniqueIndex) Error() string {
    25  	return fmt.Sprintf("cannot insert into unique index: duplicate value(s): %v", []interface{}(err))
    26  }
    27  
    28  // IsDuplicateUniqueIndexError reports whether err is produced by attempting to
    29  // violate unique index constraints.
    30  func IsDuplicateUniqueIndexError(err error) bool {
    31  	_, ok := err.(errDuplicateUniqueIndex)
    32  	return ok
    33  }