mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-02 14:02:39 +08:00
Automatic merge from release/2.2.0 -> release/2.3.0
* commit 'e1a423326dd93423fe76954784bf1bbbca523504': 更新vendor
This commit is contained in:
19
vendor/yunion.io/x/pkg/util/secrules/secrules.go
generated
vendored
19
vendor/yunion.io/x/pkg/util/secrules/secrules.go
generated
vendored
@@ -127,12 +127,21 @@ func ParseSecurityRule(pattern string) (*SecurityRule, error) {
|
||||
return nil, ErrInvalidAction
|
||||
}
|
||||
} else if status == SEG_IP {
|
||||
// NOTE regutils.MatchCIDR actually also matches IP address without prefix length
|
||||
if regutils.MatchCIDR(seg) {
|
||||
_, rule.IPNet, _ = net.ParseCIDR(seg)
|
||||
} else if regutils.MatchIPAddr(seg) {
|
||||
rule.IPNet = &net.IPNet{
|
||||
IP: net.ParseIP(seg),
|
||||
Mask: net.CIDRMask(32, 32),
|
||||
if idx := strings.Index(seg, "/"); idx > -1 {
|
||||
if _, ipnet, err := net.ParseCIDR(seg); err != nil {
|
||||
return nil, ErrInvalidNet
|
||||
} else {
|
||||
rule.IPNet = ipnet
|
||||
}
|
||||
} else if ip := net.ParseIP(seg); ip != nil {
|
||||
rule.IPNet = &net.IPNet{
|
||||
IP: ip,
|
||||
Mask: net.CIDRMask(32, 32),
|
||||
}
|
||||
} else {
|
||||
return nil, ErrInvalidIPAddr
|
||||
}
|
||||
} else {
|
||||
rule.IPNet = &net.IPNet{
|
||||
|
||||
15
vendor/yunion.io/x/sqlchemy/conditions.go
generated
vendored
15
vendor/yunion.io/x/sqlchemy/conditions.go
generated
vendored
@@ -159,12 +159,25 @@ func IsEmpty(f IQueryField) ICondition {
|
||||
return &c
|
||||
}
|
||||
|
||||
type SIsNullOrEmptyCondition struct {
|
||||
SSingleCondition
|
||||
}
|
||||
|
||||
func (c *SIsNullOrEmptyCondition) WhereClause() string {
|
||||
return fmt.Sprintf("%s IS NULL OR LENGTH(%s) = 0", c.field.Reference(), c.field.Reference())
|
||||
}
|
||||
|
||||
func IsNullOrEmpty(f IQueryField) ICondition {
|
||||
c := SIsNullOrEmptyCondition{NewSingleCondition(f)}
|
||||
return &c
|
||||
}
|
||||
|
||||
type SIsNotEmptyCondition struct {
|
||||
SSingleCondition
|
||||
}
|
||||
|
||||
func (c *SIsNotEmptyCondition) WhereClause() string {
|
||||
return fmt.Sprintf("LENGTH(%s) > 0", c.field.Reference())
|
||||
return fmt.Sprintf("%s IS NOT NULL AND LENGTH(%s) > 0", c.field.Reference(), c.field.Reference())
|
||||
}
|
||||
|
||||
func IsNotEmpty(f IQueryField) ICondition {
|
||||
|
||||
5
vendor/yunion.io/x/sqlchemy/filter.go
generated
vendored
5
vendor/yunion.io/x/sqlchemy/filter.go
generated
vendored
@@ -107,6 +107,11 @@ func (q *SQuery) IsEmpty(f string) *SQuery {
|
||||
return q.Filter(cond)
|
||||
}
|
||||
|
||||
func (q *SQuery) IsNullOrEmpty(f string) *SQuery {
|
||||
cond := IsNullOrEmpty(q.Field(f))
|
||||
return q.Filter(cond)
|
||||
}
|
||||
|
||||
func (q *SQuery) IsNotEmpty(f string) *SQuery {
|
||||
cond := IsNotEmpty(q.Field(f))
|
||||
return q.Filter(cond)
|
||||
|
||||
10
vendor/yunion.io/x/sqlchemy/functions.go
generated
vendored
10
vendor/yunion.io/x/sqlchemy/functions.go
generated
vendored
@@ -38,8 +38,14 @@ func NewFunctionField(name string, funcexp string, fields ...IQueryField) SFunct
|
||||
return ff
|
||||
}
|
||||
|
||||
func COUNT(name string) IQueryField {
|
||||
ff := NewFunctionField(name, "COUNT(*)")
|
||||
func COUNT(name string, field ...IQueryField) IQueryField {
|
||||
var expr string
|
||||
if len(field) == 0 {
|
||||
expr = "COUNT(*)"
|
||||
} else {
|
||||
expr = "COUNT(%s)"
|
||||
}
|
||||
ff := NewFunctionField(name, expr, field...)
|
||||
return &ff
|
||||
}
|
||||
|
||||
|
||||
2
vendor/yunion.io/x/sqlchemy/insert.go
generated
vendored
2
vendor/yunion.io/x/sqlchemy/insert.go
generated
vendored
@@ -37,7 +37,7 @@ func (t *STableSpec) insertSqlPrep(dataFields map[string]interface{}) (string, [
|
||||
createdAtFields = append(createdAtFields, k)
|
||||
names = append(names, fmt.Sprintf("`%s`", k))
|
||||
format = append(format, "UTC_TIMESTAMP()")
|
||||
} else if ov != nil && !c.IsZero(ov) && !isAutoInc {
|
||||
} else if ov != nil && (!c.IsZero(ov) || !c.IsText()) && !isAutoInc {
|
||||
v := c.ConvertFromValue(ov)
|
||||
values = append(values, v)
|
||||
names = append(names, fmt.Sprintf("`%s`", k))
|
||||
|
||||
1
vendor/yunion.io/x/sqlchemy/query.go
generated
vendored
1
vendor/yunion.io/x/sqlchemy/query.go
generated
vendored
@@ -450,6 +450,7 @@ func (q *SQuery) AllStringMap() ([]map[string]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
results := make([]map[string]string, 0)
|
||||
for rows.Next() {
|
||||
result, err := q.rowScan2StringMap(rows)
|
||||
|
||||
30
vendor/yunion.io/x/sqlchemy/update.go
generated
vendored
30
vendor/yunion.io/x/sqlchemy/update.go
generated
vendored
@@ -83,17 +83,16 @@ func (us *SUpdateSession) saveUpdate(dt interface{}) (map[string]SUpdateDiff, er
|
||||
setters := make(map[string]SUpdateDiff)
|
||||
for _, c := range us.tableSpec.columns {
|
||||
k := c.Name()
|
||||
of, ok := ofields[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
of := ofields[k]
|
||||
nf := fields[k]
|
||||
if c.IsPrimary() && !c.IsZero(of) { // skip update primary key
|
||||
primaries[k] = of
|
||||
continue
|
||||
} else if c.IsKeyIndex() && !c.IsZero(of) {
|
||||
keyIndexes[k] = of
|
||||
continue
|
||||
if !gotypes.IsNil(of) {
|
||||
if c.IsPrimary() && !c.IsZero(of) { // skip update primary key
|
||||
primaries[k] = of
|
||||
continue
|
||||
} else if c.IsKeyIndex() && !c.IsZero(of) {
|
||||
keyIndexes[k] = of
|
||||
continue
|
||||
}
|
||||
}
|
||||
nc, ok := c.(*SIntegerColumn)
|
||||
if ok && nc.IsAutoVersion {
|
||||
@@ -108,6 +107,9 @@ func (us *SUpdateSession) saveUpdate(dt interface{}) (map[string]SUpdateDiff, er
|
||||
if reflect.DeepEqual(of, nf) {
|
||||
continue
|
||||
}
|
||||
if c.IsZero(nf) && c.IsText() {
|
||||
nf = nil
|
||||
}
|
||||
setters[k] = SUpdateDiff{old: of, new: nf, col: c}
|
||||
}
|
||||
|
||||
@@ -125,8 +127,12 @@ func (us *SUpdateSession) saveUpdate(dt interface{}) (map[string]SUpdateDiff, er
|
||||
} else {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
buf.WriteString(fmt.Sprintf("`%s` = ?", k))
|
||||
vars = append(vars, v.col.ConvertFromValue(v.new))
|
||||
if gotypes.IsNil(v.new) {
|
||||
buf.WriteString(fmt.Sprintf("`%s` = NULL", k))
|
||||
} else {
|
||||
buf.WriteString(fmt.Sprintf("`%s` = ?", k))
|
||||
vars = append(vars, v.col.ConvertFromValue(v.new))
|
||||
}
|
||||
}
|
||||
for _, versionField := range versionFields {
|
||||
buf.WriteString(fmt.Sprintf(", `%s` = `%s` + 1", versionField, versionField))
|
||||
|
||||
Reference in New Issue
Block a user