mirror of https://github.com/go-gorm/gorm.git
invalid db error and value and invalid value length error (#4151)
This commit is contained in:
parent
a948c84607
commit
495ec4bd87
|
@ -1,7 +1,6 @@
|
||||||
package gorm
|
package gorm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -441,7 +440,7 @@ func (association *Association) saveAssociation(clear bool, values ...interface{
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
association.Error = errors.New("invalid association values, length doesn't match")
|
association.Error = ErrInvalidValueOfLength
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ func (p *processor) Execute(db *DB) {
|
||||||
stmt.ReflectValue = stmt.ReflectValue.Elem()
|
stmt.ReflectValue = stmt.ReflectValue.Elem()
|
||||||
}
|
}
|
||||||
if !stmt.ReflectValue.IsValid() {
|
if !stmt.ReflectValue.IsValid() {
|
||||||
db.AddError(fmt.Errorf("invalid value"))
|
db.AddError(ErrInvalidValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,4 +31,10 @@ var (
|
||||||
ErrEmptySlice = errors.New("empty slice found")
|
ErrEmptySlice = errors.New("empty slice found")
|
||||||
// ErrDryRunModeUnsupported dry run mode unsupported
|
// ErrDryRunModeUnsupported dry run mode unsupported
|
||||||
ErrDryRunModeUnsupported = errors.New("dry run mode unsupported")
|
ErrDryRunModeUnsupported = errors.New("dry run mode unsupported")
|
||||||
|
// ErrInvaildDB invalid db
|
||||||
|
ErrInvaildDB = errors.New("invalid db")
|
||||||
|
// ErrInvalidValue invalid value
|
||||||
|
ErrInvalidValue = errors.New("invalid value")
|
||||||
|
// ErrInvalidValueOfLength invalid values do not match length
|
||||||
|
ErrInvalidValueOfLength = errors.New("invalid association values, length doesn't match")
|
||||||
)
|
)
|
||||||
|
|
3
gorm.go
3
gorm.go
|
@ -3,7 +3,6 @@ package gorm
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -331,7 +330,7 @@ func (db *DB) DB() (*sql.DB, error) {
|
||||||
return sqldb, nil
|
return sqldb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("invalid db")
|
return nil, ErrInvaildDB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) getInstance() *DB {
|
func (db *DB) getInstance() *DB {
|
||||||
|
|
Loading…
Reference in New Issue