Prechádzať zdrojové kódy

fix bugs cols with incr when update

xormplus 8 rokov pred
rodič
commit
a6633212df
2 zmenil súbory, kde vykonal 30 pridanie a 41 odobranie
  1. 4 0
      helpers.go
  2. 26 41
      session_update_test.go

+ 4 - 0
helpers.go

@@ -400,6 +400,10 @@ func genCols(table *core.Table, session *Session, bean interface{}, useCol bool,
 		if session.Statement.ColumnStr != "" {
 		if session.Statement.ColumnStr != "" {
 			if _, ok := getFlagForColumn(session.Statement.columnMap, col); !ok {
 			if _, ok := getFlagForColumn(session.Statement.columnMap, col); !ok {
 				continue
 				continue
+			} else if _, ok := session.Statement.incrColumns[col.Name]; ok {
+				continue
+			} else if _, ok := session.Statement.decrColumns[col.Name]; ok {
+				continue
 			}
 			}
 		}
 		}
 		if session.Statement.OmitStr != "" {
 		if session.Statement.OmitStr != "" {

+ 26 - 41
session_update_test.go

@@ -249,8 +249,9 @@ type UpdateMustCols struct {
 }
 }
 
 
 type UpdateIncr struct {
 type UpdateIncr struct {
-	Id  int64
-	Cnt int
+	Id   int64
+	Cnt  int
+	Name string
 }
 }
 
 
 type Article struct {
 type Article struct {
@@ -545,50 +546,34 @@ func TestUpdate1(t *testing.T) {
 			return
 			return
 		}
 		}
 	}
 	}
+}
 
 
-	{
+func TestUpdateIncrDecr(t *testing.T) {
+	assert.NoError(t, prepareEngine())
 
 
-		col1 := &UpdateIncr{}
-		err = testEngine.Sync(col1)
-		if err != nil {
-			t.Error(err)
-			panic(err)
-		}
+	col1 := &UpdateIncr{
+		Name: "test",
+	}
+	assert.NoError(t, testEngine.Sync(col1))
 
 
-		_, err = testEngine.Insert(col1)
-		if err != nil {
-			t.Error(err)
-			panic(err)
-		}
+	_, err := testEngine.Insert(col1)
+	assert.NoError(t, err)
 
 
-		cnt, err := testEngine.Id(col1.Id).Incr(testEngine.ColumnMapper.Obj2Table("Cnt")).Update(col1)
-		if err != nil {
-			t.Error(err)
-			panic(err)
-		}
-		if cnt != 1 {
-			err = errors.New("update incr failed")
-			t.Error(err)
-			panic(err)
-		}
+	colName := testEngine.ColumnMapper.Obj2Table("Cnt")
 
 
-		newCol := new(UpdateIncr)
-		has, err := testEngine.Id(col1.Id).Get(newCol)
-		if err != nil {
-			t.Error(err)
-			panic(err)
-		}
-		if !has {
-			err = errors.New("has incr failed")
-			t.Error(err)
-			panic(err)
-		}
-		if 1 != newCol.Cnt {
-			err = fmt.Errorf("incr failed %v %v %v", newCol.Cnt, newCol, col1)
-			t.Error(err)
-			panic(err)
-		}
-	}
+	cnt, err := testEngine.Id(col1.Id).Incr(colName).Update(col1)
+	assert.NoError(t, err)
+	assert.EqualValues(t, 1, cnt)
+
+	newCol := new(UpdateIncr)
+	has, err := testEngine.Id(col1.Id).Get(newCol)
+	assert.NoError(t, err)
+	assert.True(t, has)
+	assert.EqualValues(t, 1, newCol.Cnt)
+
+	cnt, err = testEngine.Id(col1.Id).Cols(colName).Incr(colName).Update(col1)
+	assert.NoError(t, err)
+	assert.EqualValues(t, 1, cnt)
 }
 }
 
 
 type UpdatedUpdate struct {
 type UpdatedUpdate struct {