mirror of
https://github.com/tobycroft/gorose-pro.git
synced 2025-09-26 12:41:16 +08:00
1.修复Oracle使用Replace出错的BUG
2.降低框架在原版Oracle操作中可能出现删数据的风险 3.降低原版Execute执行器可能出现误删数据的风险
This commit is contained in:
@@ -130,8 +130,10 @@ func (b *BuilderDefault) BuildExecute(operType string) (sqlStr string, args []in
|
||||
switch operType {
|
||||
case "insert":
|
||||
sqlStr = fmt.Sprintf("INSERT INTO %s (%s) VALUES %s", b.BuildTable(), insertkey, insertval)
|
||||
break
|
||||
case "replace":
|
||||
sqlStr = fmt.Sprintf("REPLACE INTO %s (%s) VALUES %s", b.BuildTable(), insertkey, insertval)
|
||||
break
|
||||
case "update":
|
||||
where, err = b.BuildWhere()
|
||||
if err != nil {
|
||||
@@ -144,8 +146,8 @@ func (b *BuilderDefault) BuildExecute(operType string) (sqlStr string, args []in
|
||||
return
|
||||
}
|
||||
sqlStr = fmt.Sprintf("UPDATE %s SET %s%s", b.BuildTable(), update, where)
|
||||
break
|
||||
case "delete":
|
||||
|
||||
where, err = b.BuildWhere()
|
||||
if err != nil {
|
||||
b.IOrm.GetISession().GetIEngin().GetLogger().Error(err.Error())
|
||||
@@ -157,6 +159,7 @@ func (b *BuilderDefault) BuildExecute(operType string) (sqlStr string, args []in
|
||||
return
|
||||
}
|
||||
sqlStr = fmt.Sprintf("DELETE FROM %s%s", b.BuildTable(), where)
|
||||
break
|
||||
}
|
||||
|
||||
args = b.GetBindValues()
|
||||
|
@@ -156,6 +156,7 @@ func (b *BuilderOracle) BuildExecuteOra(operType string) (sqlStr string, args []
|
||||
switch operType {
|
||||
case "insert":
|
||||
sqlStr = fmt.Sprintf("INSERT INTO %s (%s) VALUES %s", b.BuildTable(), insertkey, insertval)
|
||||
break
|
||||
case "update":
|
||||
if where == "" && b.IOrm.GetForce() == false {
|
||||
err = errors.New("出于安全考虑, update时where条件不能为空, 如果真的不需要where条件, 请使用Force()(如: db.xxx.Force().Update())")
|
||||
@@ -163,6 +164,7 @@ func (b *BuilderOracle) BuildExecuteOra(operType string) (sqlStr string, args []
|
||||
return
|
||||
}
|
||||
sqlStr = fmt.Sprintf("UPDATE %s SET %s%s", b.BuildTable(), update, where)
|
||||
break
|
||||
case "delete":
|
||||
if where == "" && b.IOrm.GetForce() == false {
|
||||
err = errors.New("出于安全考虑, delete时where条件不能为空, 如果真的不需要where条件, 请使用Force()(如: db.xxx.Force().Delete())")
|
||||
@@ -170,6 +172,15 @@ func (b *BuilderOracle) BuildExecuteOra(operType string) (sqlStr string, args []
|
||||
return
|
||||
}
|
||||
sqlStr = fmt.Sprintf("DELETE FROM %s%s", b.BuildTable(), where)
|
||||
break
|
||||
case "replace":
|
||||
if where == "" && b.IOrm.GetForce() == false {
|
||||
err = errors.New("出于安全考虑, update时where条件不能为空, 如果真的不需要where条件, 请使用Force()(如: db.xxx.Force().Update())")
|
||||
b.IOrm.GetISession().GetIEngin().GetLogger().Error(err.Error())
|
||||
return
|
||||
}
|
||||
sqlStr = fmt.Sprintf("REPLACE INTO %s (%s) VALUES %s", b.BuildTable(), insertkey, insertval)
|
||||
break
|
||||
}
|
||||
|
||||
args = b.IOrm.GetBindValues()
|
||||
|
@@ -41,7 +41,7 @@ func (dba *Orm) Delete() (int64, error) {
|
||||
return dba.exec("delete")
|
||||
}
|
||||
|
||||
// Delete : delete data
|
||||
// exec : Execute a sql
|
||||
func (dba *Orm) exec(operType string, data ...interface{}) (int64, error) {
|
||||
if operType == "insert" || operType == "update" {
|
||||
if dba.GetData() == nil {
|
||||
|
Reference in New Issue
Block a user