فهرست منبع

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

paddy 4 سال پیش
والد
کامیت
f7f38dfabc
1فایلهای تغییر یافته به همراه7 افزوده شده و 0 حذف شده
  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
 	}