Merge branch 'galeone-master'
This commit is contained in:
		
						commit
						b261296b76
					
				@ -50,6 +50,19 @@ func TestFirstAndLastWithNoStdPrimaryKey(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestUIntPrimaryKey(t *testing.T) {
 | 
				
			||||||
 | 
						var animal Animal
 | 
				
			||||||
 | 
						DB.First(&animal, uint64(1))
 | 
				
			||||||
 | 
						if animal.Counter != 1 {
 | 
				
			||||||
 | 
							t.Errorf("Fetch a record from with a non-int primary key should work, but failed")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						DB.Model(Animal{}).Where(Animal{Counter: uint64(2)}).Scan(&animal)
 | 
				
			||||||
 | 
						if animal.Counter != 2 {
 | 
				
			||||||
 | 
							t.Errorf("Fetch a record from with a non-int primary key should work, but failed")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestFindAsSliceOfPointers(t *testing.T) {
 | 
					func TestFindAsSliceOfPointers(t *testing.T) {
 | 
				
			||||||
	DB.Save(&User{Name: "user"})
 | 
						DB.Save(&User{Name: "user"})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -25,11 +25,11 @@ func (scope *Scope) buildWhereCondition(clause map[string]interface{}) (str stri
 | 
				
			|||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			str = value
 | 
								str = value
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case int, int64, int32:
 | 
						case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
 | 
				
			||||||
		return scope.primaryCondiation(scope.AddToVars(value))
 | 
							return scope.primaryCondiation(scope.AddToVars(value))
 | 
				
			||||||
	case sql.NullInt64:
 | 
						case sql.NullInt64:
 | 
				
			||||||
		return scope.primaryCondiation(scope.AddToVars(value.Int64))
 | 
							return scope.primaryCondiation(scope.AddToVars(value.Int64))
 | 
				
			||||||
	case []int64, []int, []int32, []string:
 | 
						case []int, []int8, []int16, []int32, []int64, []uint, []uint8, []uint16, []uint32, []uint64, []string:
 | 
				
			||||||
		str = fmt.Sprintf("(%v in (?))", scope.Quote(scope.PrimaryKey()))
 | 
							str = fmt.Sprintf("(%v in (?))", scope.Quote(scope.PrimaryKey()))
 | 
				
			||||||
		clause["args"] = []interface{}{value}
 | 
							clause["args"] = []interface{}{value}
 | 
				
			||||||
	case map[string]interface{}:
 | 
						case map[string]interface{}:
 | 
				
			||||||
@ -84,9 +84,9 @@ func (scope *Scope) buildNotCondition(clause map[string]interface{}) (str string
 | 
				
			|||||||
			str = fmt.Sprintf("(%v NOT IN (?))", scope.Quote(value))
 | 
								str = fmt.Sprintf("(%v NOT IN (?))", scope.Quote(value))
 | 
				
			||||||
			notEqualSql = fmt.Sprintf("(%v <> ?)", scope.Quote(value))
 | 
								notEqualSql = fmt.Sprintf("(%v <> ?)", scope.Quote(value))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case int, int64, int32:
 | 
						case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
 | 
				
			||||||
		return fmt.Sprintf("(%v <> %v)", scope.Quote(scope.PrimaryKey()), value)
 | 
							return fmt.Sprintf("(%v <> %v)", scope.Quote(scope.PrimaryKey()), value)
 | 
				
			||||||
	case []int64, []int, []int32, []string:
 | 
						case []int, []int8, []int16, []int32, []int64, []uint, []uint8, []uint16, []uint32, []uint64, []string:
 | 
				
			||||||
		if reflect.ValueOf(value).Len() > 0 {
 | 
							if reflect.ValueOf(value).Len() > 0 {
 | 
				
			||||||
			str = fmt.Sprintf("(%v not in (?))", scope.Quote(scope.PrimaryKey()))
 | 
								str = fmt.Sprintf("(%v not in (?))", scope.Quote(scope.PrimaryKey()))
 | 
				
			||||||
			clause["args"] = []interface{}{value}
 | 
								clause["args"] = []interface{}{value}
 | 
				
			||||||
 | 
				
			|||||||
@ -2,7 +2,6 @@ package gorm_test
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"github.com/jinzhu/gorm"
 | 
						"github.com/jinzhu/gorm"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										18
									
								
								search.go
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								search.go
									
									
									
									
									
								
							@ -1,6 +1,6 @@
 | 
				
			|||||||
package gorm
 | 
					package gorm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "strconv"
 | 
					import "fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type search struct {
 | 
					type search struct {
 | 
				
			||||||
	db              *DB
 | 
						db              *DB
 | 
				
			||||||
@ -125,17 +125,15 @@ func (s *search) table(name string) *search {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *search) getInterfaceAsSql(value interface{}) (str string) {
 | 
					func (s *search) getInterfaceAsSql(value interface{}) (str string) {
 | 
				
			||||||
	switch value := value.(type) {
 | 
						switch value.(type) {
 | 
				
			||||||
	case string:
 | 
						case string, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
 | 
				
			||||||
		str = value
 | 
							str = fmt.Sprintf("%v", value)
 | 
				
			||||||
	case int:
 | 
					 | 
				
			||||||
		if value < 0 {
 | 
					 | 
				
			||||||
			str = ""
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			str = strconv.Itoa(value)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		s.db.err(InvalidSql)
 | 
							s.db.err(InvalidSql)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if str == "-1" {
 | 
				
			||||||
 | 
							return ""
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -94,7 +94,6 @@ type Role struct {
 | 
				
			|||||||
	Name string
 | 
						Name string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
func (role *Role) Scan(value interface{}) error {
 | 
					func (role *Role) Scan(value interface{}) error {
 | 
				
			||||||
	if b, ok := value.([]uint8); ok {
 | 
						if b, ok := value.([]uint8); ok {
 | 
				
			||||||
		role.Name = string(b)
 | 
							role.Name = string(b)
 | 
				
			||||||
@ -126,7 +125,7 @@ func (i *Num) Scan(src interface{}) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Animal struct {
 | 
					type Animal struct {
 | 
				
			||||||
	Counter   int64 `gorm:"primary_key:yes"`
 | 
						Counter   uint64 `gorm:"primary_key:yes"`
 | 
				
			||||||
	Name      string
 | 
						Name      string
 | 
				
			||||||
	From      string //test reserved sql keyword as field name
 | 
						From      string //test reserved sql keyword as field name
 | 
				
			||||||
	CreatedAt time.Time
 | 
						CreatedAt time.Time
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user