From 55f8e9e651c25ba476310b1a21d58762df68642d Mon Sep 17 00:00:00 2001 From: Sergey Glazyrin Date: Sun, 21 Nov 2021 16:07:02 +0100 Subject: [PATCH] minor fix --- core/gorm_persistence_storage.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/core/gorm_persistence_storage.go b/core/gorm_persistence_storage.go index 02bd69f8..8f14ca8d 100644 --- a/core/gorm_persistence_storage.go +++ b/core/gorm_persistence_storage.go @@ -9,6 +9,7 @@ import ( "gorm.io/gorm/clause" "net/url" "reflect" + "strconv" "strings" ) @@ -724,11 +725,15 @@ func (afo *GormAdminFilterObjects) Search(field *Field, searchString string) { if searchField.Field.FieldType.Kind() == reflect.Struct { afo.Search(searchField.Field, searchString) continue - } else if (fieldType1 == reflect.Uint) || (fieldType1 == reflect.Uint64) || (fieldType1 == reflect.Uint32) || (fieldType1 == reflect.Int64) || (fieldType1 == reflect.Int) || (fieldType1 == reflect.Int32) || (fieldType1 == reflect.Float32) || (fieldType1 == reflect.Float64) { + } else if (fieldType1 == reflect.Uint) || (fieldType1 == reflect.Uint64) || (fieldType1 == reflect.Uint32) || (fieldType1 == reflect.Int64) || (fieldType1 == reflect.Int) || (fieldType1 == reflect.Int32) { + searchID, err1 := strconv.Atoi(searchString) + if err1 != nil { + continue + } operator := ExactGormOperator{} - operator.Build(afo.GetUadminDatabase().Adapter, fullGormOperatorContext, searchField.Field, searchString, &SQLConditionBuilder{Type: "or"}) + operator.Build(afo.GetUadminDatabase().Adapter, fullGormOperatorContext, searchField.Field, searchID, &SQLConditionBuilder{Type: "or"}) operator = ExactGormOperator{} - operator.Build(afo.GetUadminDatabase().Adapter, paginatedGormOperatorContext, searchField.Field, searchString, &SQLConditionBuilder{Type: "or"}) + operator.Build(afo.GetUadminDatabase().Adapter, paginatedGormOperatorContext, searchField.Field, searchID, &SQLConditionBuilder{Type: "or"}) } else { operator := IContainsGormOperator{} operator.Build(afo.GetUadminDatabase().Adapter, fullGormOperatorContext, searchField.Field, searchString, &SQLConditionBuilder{Type: "or"}) @@ -739,13 +744,17 @@ func (afo *GormAdminFilterObjects) Search(field *Field, searchString string) { afo.SetFullQuerySet(fullGormOperatorContext.Tx) afo.SetPaginatedQuerySet(fullGormOperatorContext.Tx) afo.SetLastError(afo.PaginatedGormQuerySet.GetLastError()) - } else if (fieldType == reflect.Uint) || (fieldType == reflect.Uint64) || (fieldType == reflect.Uint32) || (fieldType == reflect.Int64) || (fieldType == reflect.Int) || (fieldType == reflect.Int32) || (fieldType == reflect.Float32) || (fieldType == reflect.Float64){ + } else if (fieldType == reflect.Uint) || (fieldType == reflect.Uint64) || (fieldType == reflect.Uint32) || (fieldType == reflect.Int64) || (fieldType == reflect.Int) || (fieldType == reflect.Int32){ + searchID, err1 := strconv.Atoi(searchString) + if err1 != nil { + return + } operator := ExactGormOperator{} gormOperatorContext := NewGormOperatorContext(afo.GetFullQuerySet(), afo.GetCurrentModel()) - operator.Build(afo.GetUadminDatabase().Adapter, gormOperatorContext, field, searchString, &SQLConditionBuilder{Type: "or"}) + operator.Build(afo.GetUadminDatabase().Adapter, gormOperatorContext, field, searchID, &SQLConditionBuilder{Type: "or"}) afo.SetFullQuerySet(gormOperatorContext.Tx) gormOperatorContext = NewGormOperatorContext(afo.GetPaginatedQuerySet(), afo.GetCurrentModel()) - operator.Build(afo.GetUadminDatabase().Adapter, gormOperatorContext, field, searchString, &SQLConditionBuilder{Type: "or"}) + operator.Build(afo.GetUadminDatabase().Adapter, gormOperatorContext, field, searchID, &SQLConditionBuilder{Type: "or"}) afo.SetPaginatedQuerySet(gormOperatorContext.Tx) afo.SetLastError(afo.PaginatedGormQuerySet.GetLastError()) } else {