|
@ -24,7 +24,7 @@ type Query struct { |
|
|
join [][]string //[["tablea as a","a.id=b.id","left"]]
|
|
|
join [][]string //[["tablea as a","a.id=b.id","left"]]
|
|
|
save_data []map[string]interface{} //批量操作的数据[["title":"a","num":1,],["title":"a","num":1,]]
|
|
|
save_data []map[string]interface{} //批量操作的数据[["title":"a","num":1,],["title":"a","num":1,]]
|
|
|
upd_field []string // 批量更新时需要更新的字段,为空时按除id外的字段进行更新
|
|
|
upd_field []string // 批量更新时需要更新的字段,为空时按除id外的字段进行更新
|
|
|
merge_into_where_field string //达梦8和pgsql中,替换ON DUPLICATE KEY UPDATE时的唯一键名/主键名
|
|
|
|
|
|
|
|
|
merge_into_where_field []string //达梦8和pgsql中,替换ON DUPLICATE KEY UPDATE时的唯一键名/主键名
|
|
|
data []string |
|
|
data []string |
|
|
value []interface{} |
|
|
value []interface{} |
|
|
orderby string |
|
|
orderby string |
|
@ -163,7 +163,7 @@ func (this *Query) Join(join []string) *Query { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 在达梦和pgsql中,使用merge into去替换mysql--insert into...ON DUPLICATE KEY UPDATE时,需指定唯一键,字段存在id时无需设置
|
|
|
// 在达梦和pgsql中,使用merge into去替换mysql--insert into...ON DUPLICATE KEY UPDATE时,需指定唯一键,字段存在id时无需设置
|
|
|
func (this *Query) MergeIntoWhereField(value string) *Query { |
|
|
|
|
|
|
|
|
func (this *Query) MergeIntoWhereField(value []string) *Query { |
|
|
this.merge_into_where_field = value |
|
|
this.merge_into_where_field = value |
|
|
return this |
|
|
return this |
|
|
} |
|
|
} |
|
@ -699,8 +699,14 @@ func (this *Query) UpdateAllStmt() error { |
|
|
val_field := addPrefixInField(this.data, "s.") |
|
|
val_field := addPrefixInField(this.data, "s.") |
|
|
//和mysql更新或添加机制不一样,需指定on条件
|
|
|
//和mysql更新或添加机制不一样,需指定on条件
|
|
|
on_field := `t.id = s.id` |
|
|
on_field := `t.id = s.id` |
|
|
if this.merge_into_where_field != "" { |
|
|
|
|
|
on_field = `t.` + this.merge_into_where_field + ` = s.` + this.merge_into_where_field |
|
|
|
|
|
|
|
|
if len(this.merge_into_where_field) > 0 { |
|
|
|
|
|
for ind, mf := range this.merge_into_where_field { |
|
|
|
|
|
if ind > 0 { |
|
|
|
|
|
on_field += " and " + `t.` + mf + ` = s.` + mf |
|
|
|
|
|
} else { |
|
|
|
|
|
on_field = `t.` + mf + ` = s.` + mf |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
sql = `merge into ` + dbName + ` as t |
|
|
sql = `merge into ` + dbName + ` as t |
|
@ -730,8 +736,14 @@ func (this *Query) UpdateAllStmt() error { |
|
|
} |
|
|
} |
|
|
//和mysql更新或添加机制不一样,需指定on条件
|
|
|
//和mysql更新或添加机制不一样,需指定on条件
|
|
|
on_field := `t.id = s.id` |
|
|
on_field := `t.id = s.id` |
|
|
if this.merge_into_where_field != "" { |
|
|
|
|
|
on_field = `t.` + this.merge_into_where_field + ` = s.` + this.merge_into_where_field |
|
|
|
|
|
|
|
|
if len(this.merge_into_where_field) > 0 { |
|
|
|
|
|
for ind, mf := range this.merge_into_where_field { |
|
|
|
|
|
if ind > 0 { |
|
|
|
|
|
on_field += " and " + `t.` + mf + ` = s.` + mf |
|
|
|
|
|
} else { |
|
|
|
|
|
on_field = `t.` + mf + ` = s.` + mf |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
sql = `MERGE INTO ` + dbName + ` AS t |
|
|
sql = `MERGE INTO ` + dbName + ` AS t |
|
|