Explorar o código

防止这样代码 db.Table("tt").ID(stuId).Update(bean) 导致 整个表被更新

paddy %!s(int64=4) %!d(string=hai) anos
pai
achega
f7f38dfabc
Modificáronse 1 ficheiros con 7 adicións e 0 borrados
  1. 7 0
      statement.go

+ 7 - 0
statement.go

@@ -1191,6 +1191,13 @@ func (statement *Statement) genSelectSQL(columnStr, condSQL string, needLimit, n
 }
 
 func (statement *Statement) processIDParam() error {
+	if statement.idParam != nil {
+		if statement.RefTable == nil {
+			return fmt.Errorf("ID condition is error, cant find ref table object")
+		} else if len(statement.RefTable.PKColumns()) == 0 {
+			return fmt.Errorf("ID condition is error, cant find table pkcolumns")
+		}
+	}
 	if statement.idParam == nil || statement.RefTable == nil {
 		return nil
 	}