本文整理汇总了Golang中database/sql/driver.IsValue函数的典型用法代码### 示例。如果您正苦于以下问题:Golang IsValue函数的具体用法?Golang IsValue怎么用?Golang IsValue使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了IsValue函数的10个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: driverArgs

// driverArgs 将Stmt.Exec和Stmt.Query的调用参数转换成为driver中定义的值。
//
// 若没有语句可用,则语句 ds 为 nil。
func driverArgs(ds *driverStmt, args []interface{}) ([]driver.Value, error) {
    dargs := make([]driver.Value, len(args))
    var si driver.Stmt
    if ds != nil {
        si = ds.si
    }
    cc, ok := si.(driver.ColumnConverter)

    // Normal path, for a driver.Stmt that is not a ColumnConverter.
    if !ok {
        for n, arg := range args {
            var err error
            dargs[n], err = driver.DefaultParameterConverter.ConvertValue(arg)
            if err != nil {
                return nil, fmt.Errorf("sql: converting Exec argument #%d's type: %v", n, err)
            }
        }
        return dargs, nil
    }

    // Let the Stmt convert its own arguments.
    for n, arg := range args {
        // First, see if the value itself knows how to convert
        // itself to a driver type.  For example, a NullString
        // struct changing into a string or nil.
        if svi, ok := arg.(driver.Valuer); ok {
            sv, err := svi.Value()
            if err != nil {
                return nil, fmt.Errorf("sql: argument index %d from Value: %v", n, err)
            }
            if !driver.IsValue(sv) {
                return nil, fmt.Errorf("sql: argument index %d: non-subset type %T returned from Value", n, sv)
            }
            arg = sv
        }

        // Second, ask the column to sanity check itself. For
        // example, drivers might use this to make sure that
        // an int64 values being inserted into a 16-bit
        // integer field is in range (before getting
        // truncated), or that a nil can't go into a NOT NULL
        // column before going across the network to get the
        // same error.
        var err error
        ds.Lock()
        dargs[n], err = cc.ColumnConverter(n).ConvertValue(arg)
        ds.Unlock()
        if err != nil {
            return nil, fmt.Errorf("sql: converting argument #%d's type: %v", n, err)
        }
        if !driver.IsValue(dargs[n]) {
            return nil, fmt.Errorf("sql: driver ColumnConverter error converted %T to unsupported type %T",
                arg, dargs[n])
        }
    }

    return dargs, nil
}

开发者ID:gmwu,项目名称:go,代码行数:61,代码来源:convert.go

示例2: argsMatches

func (e *queryBasedExpectation) argsMatches(args []driver.Value) error {
    if nil == e.args {
        return nil
    }
    if len(args) != len(e.args) {
        return fmt.Errorf("expected %d, but got %d arguments", len(e.args), len(args))
    }
    for k, v := range args {
        // custom argument matcher
        matcher, ok := e.args[k].(Argument)
        if ok {
            if !matcher.Match(v) {
                return fmt.Errorf("matcher %T could not match %d argument %T - %+v", matcher, k, args[k], args[k])
            }
            continue
        }

        // convert to driver converter
        darg, err := driver.DefaultParameterConverter.ConvertValue(e.args[k])
        if err != nil {
            return fmt.Errorf("could not convert %d argument %T - %+v to driver value: %s", k, e.args[k], e.args[k], err)
        }

        if !driver.IsValue(darg) {
            return fmt.Errorf("argument %d: non-subset type %T returned from Value", k, darg)
        }

        if !reflect.DeepEqual(darg, args[k]) {
            return fmt.Errorf("argument %d expected [%T - %+v] does not match actual [%T - %+v]", k, darg, darg, args[k], args[k])
        }
    }
    return nil
}

开发者ID:roman-vynar,项目名称:mysqld_exporter,代码行数:33,代码来源:expectations.go

示例3: ConvertValue

func (converter) ConvertValue(v interface{}) (driver.Value, error) {
    if driver.IsValue(v) {
        return v, nil
    }

    rv := reflect.ValueOf(v)
    switch rv.Kind() {
    case reflect.Ptr:
        // indirect pointers
        if rv.IsNil() {
            return nil, nil
        }
        return driver.DefaultParameterConverter.ConvertValue(rv.Elem().Interface())
    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
        return rv.Int(), nil
    case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32:
        return int64(rv.Uint()), nil
    case reflect.Uint64:
        u64 := rv.Uint()
        if u64 >= 1<<63 {
            return fmt.Sprintf("%d", u64), nil
        }
        return int64(u64), nil
    case reflect.Float32, reflect.Float64:
        return rv.Float(), nil
    }
    return nil, fmt.Errorf("unsupported type %T, a %s", v, rv.Kind())
}

开发者ID:useidel,项目名称:notary,代码行数:28,代码来源:statement.go

示例4: driverArgs

func driverArgs(ds *driverStmt, args []interface{}) ([]driver.Value, error) {
    dargs := make([]driver.Value, len(args))
    var si dirver.Stmt
    if ds != nil {
        si = ds.si

    }
    cc, ok := si.(driver.ColumnConverter)

    if !ok {
        for n, arg := range args {
            var err error
            vargs[n], err = driver.DefaultParameterConverter.ConvertValue(arg)
            if err != nil {
                return nil, fmt.Errorf("sql :converting Exec argument #%d's type :%v", n, err)
            }
        }
    }
    for n, arg := range args {
        if svi, ok := arg(driver.Valuer); ok {
            if err != nil {
                return nil, fmt.Errorf("sql:argument index %d from Value:%v", n, err)
            }
            if !driver.IsValue(sv) {
                return nil, fmt.Errorf("sql: argument index %d:non-subset type %T retruned from value", n, sv)
            }
            arg = sv
        }

        var err error
        ds.lock()
        dargs[n], err = cc.ColumnConverter(n).ConvertValue(arg)
        ds.Unlock()
        if err != nil {
            return nil, fmt.Errorf("sql: vonverting argument #%d's type :%v", n, err)
        }
        if !driver.IsValue(dargs[n]) {
            return nil, fmt.Errorf("sql :driver ColumnConverter error vonverted  %T to unsupported type %T", arg, dargs[n])
        }

    }

    return dargs, nil
}

开发者ID:zbzzbd,项目名称:go,代码行数:44,代码来源:convert_test.go

示例5: Value

// Value implements the driver.Valuer interface.
func (d Datum) Value() (driver.Value, error) {
    var val driver.Value

    switch t := d.Payload.(type) {
    case *Datum_BoolVal:
        val = t.BoolVal
    case *Datum_IntVal:
        val = t.IntVal
    case *Datum_FloatVal:
        val = t.FloatVal
    case *Datum_BytesVal:
        val = t.BytesVal
    case *Datum_StringVal:
        val = t.StringVal
    case *Datum_TimeVal:
        val = t.TimeVal.GoTime().UTC()
    }

    if driver.IsValue(val) {
        return val, nil
    }
    return nil, util.Errorf("unsupported type %T", val)
}

开发者ID:harryyeh,项目名称:cockroach,代码行数:24,代码来源:wire.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng