Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Dec 2, 2024
1 parent 8914834 commit d74b7ae
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ jobs:
# ClickHouse backend server.
# docker run -d --name clickhouse \
# -p 9000:9000 -p 8123:8123 -p 9001:9001 \
# loads/clickhouse-server:22.1.3.7
# clickhouse/clickhouse-server:24.11.1.2557-alpine
clickhouse-server:
image: loads/clickhouse-server:22.1.3.7
image: clickhouse/clickhouse-server:24.11.1.2557-alpine
ports:
- 9000:9000
- 8123:8123
Expand Down
13 changes: 11 additions & 2 deletions contrib/drivers/clickhouse/clickhouse_z_unit_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,18 @@ func Test_DB_Delete(t *testing.T) {
defer dropTable(table)

gtest.C(t, func(t *gtest.T) {
_, err := db.Delete(ctx, table, "id>3")
t.AssertNE(err, nil)
//db.SetDebug(true)
count, err := db.Model(table).Ctx(ctx).Count()
t.AssertNil(err)
t.Assert(count, 10)

result, err := db.Delete(ctx, table, "id>3")
t.AssertNil(err)
t.AssertNil(result)

count, err = db.Model(table).Ctx(ctx).Count()
t.AssertNil(err)
t.Assert(count, 3)
})
}

Expand Down
36 changes: 24 additions & 12 deletions util/gconv/gconv_float.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ func doFloat32(any any) (float32, error) {
return 0, nil
case reflect.String:
f, err := strconv.ParseFloat(rv.String(), 32)
return float32(f), gerror.WrapCodef(
gcode.CodeInvalidParameter, err, "converting string to float32 failed for: %v", any,
)
if err != nil {
return 0, gerror.WrapCodef(
gcode.CodeInvalidParameter, err, "converting string to float32 failed for: %v", any,
)
}
return float32(f), nil
case reflect.Ptr:
if rv.IsNil() {
return 0, nil
Expand All @@ -66,9 +69,12 @@ func doFloat32(any any) (float32, error) {
return f.Float32(), nil
}
v, err := strconv.ParseFloat(String(any), 32)
return float32(v), gerror.WrapCodef(
gcode.CodeInvalidParameter, err, "converting string to float32 failed for: %v", any,
)
if err != nil {
return 0, gerror.WrapCodef(
gcode.CodeInvalidParameter, err, "converting string to float32 failed for: %v", any,
)
}
return float32(v), nil
}
}
}
Expand Down Expand Up @@ -112,9 +118,12 @@ func doFloat64(any any) (float64, error) {
return 0, nil
case reflect.String:
f, err := strconv.ParseFloat(rv.String(), 64)
return f, gerror.WrapCodef(
gcode.CodeInvalidParameter, err, "converting string to float64 failed for: %v", any,
)
if err != nil {
return 0, gerror.WrapCodef(
gcode.CodeInvalidParameter, err, "converting string to float64 failed for: %v", any,
)
}
return f, nil
case reflect.Ptr:
if rv.IsNil() {
return 0, nil
Expand All @@ -128,9 +137,12 @@ func doFloat64(any any) (float64, error) {
return f.Float64(), nil
}
v, err := strconv.ParseFloat(String(any), 64)
return v, gerror.WrapCodef(
gcode.CodeInvalidParameter, err, "converting string to float64 failed for: %v", any,
)
if err != nil {
return 0, gerror.WrapCodef(
gcode.CodeInvalidParameter, err, "converting string to float64 failed for: %v", any,
)
}
return v, nil
}
}
}
15 changes: 9 additions & 6 deletions util/gconv/gconv_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,16 @@ func Scan(srcValue any, dstPointer any, paramKeyToAttrMap ...map[string]string)
)
// Handle multiple level pointers
if dstPointerReflectValueElemKind == reflect.Ptr {
// Create a new value for the pointer dereference
nextLevelPtr := reflect.New(dstPointerReflectValueElem.Type().Elem())
// Recursively scan into the dereferenced pointer
if err = Scan(srcValueReflectValue, nextLevelPtr, paramKeyToAttrMap...); err == nil {
dstPointerReflectValueElem.Set(nextLevelPtr)
if dstPointerReflectValueElem.IsNil() {
// Create a new value for the pointer dereference
nextLevelPtr := reflect.New(dstPointerReflectValueElem.Type().Elem())
// Recursively scan into the dereferenced pointer
if err = Scan(srcValueReflectValue, nextLevelPtr, paramKeyToAttrMap...); err == nil {
dstPointerReflectValueElem.Set(nextLevelPtr)
}
return
}
return
return Scan(srcValueReflectValue, dstPointerReflectValueElem, paramKeyToAttrMap...)
}

// Check if srcValue and dstPointer are the same type, in which case direct assignment can be performed
Expand Down
29 changes: 12 additions & 17 deletions util/gconv/gconv_uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,28 @@ func doUint64(any any) (uint64, error) {
rv.Type().String(),
)
case reflect.String:
var (
s = rv.String()
)
var s = rv.String()
// Hexadecimal
if len(s) > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X') {
if v, e := strconv.ParseUint(s[2:], 16, 64); e == nil {
v, err := strconv.ParseUint(s[2:], 16, 64)
if err == nil {
return v, nil
} else {
return 0, gerror.WrapCodef(
gcode.CodeInvalidParameter,
e,
`cannot convert hexadecimal string "%s" to uint64`,
s,
)
}
}
// Decimal
if v, err := strconv.ParseUint(s, 10, 64); err == nil {
return v, nil
} else {
return 0, gerror.WrapCodef(
gcode.CodeInvalidParameter,
err,
`cannot convert decimal string "%s" to uint64`,
`cannot convert hexadecimal string "%s" to uint64`,
s,
)
}
// Decimal
if v, err := strconv.ParseUint(s, 10, 64); err == nil {
return v, nil
}
// Float64
if v, err := doFloat64(any); err == nil {
return uint64(v), nil
}
default:
if f, ok := any.(localinterface.IUint64); ok {
return f.Uint64(), nil
Expand Down
5 changes: 3 additions & 2 deletions util/gconv/gconv_z_unit_uint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ var uintTests = []struct {

func TestUint(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
for _, test := range uintTests {
t.AssertEQ(gconv.Uint(test.value), test.expect)
for _, v := range uintTests {
//t.Logf(`%+v`, v)
t.AssertEQ(gconv.Uint(v.value), v.expect)
}
})
}
Expand Down

0 comments on commit d74b7ae

Please sign in to comment.