本文整理匯總了Golang中database/sql/driver.Value函數的典型用法代碼示例。如果您正苦於以下問題:Golang Value函數的具體用法?Golang Value怎麽用?Golang Value使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Value函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Value
// Value implements the driver.Value interface.
func (c Command) Value() (driver.Value, error) {
raw, err := json.Marshal(c)
if err != nil {
return nil, err
}
return driver.Value(raw), nil
}
示例2: Next
// DATE, DATETIME, TIMESTAMP are treated as they are in Local time zone (this
// can be changed globaly using SetLocation function).
func (r *rowsRes) Next(dest []driver.Value) error {
if r.my == nil {
return io.EOF // closed before
}
err := r.my.ScanRow(r.row)
if err == nil {
if r.simpleQuery == textQuery {
// workaround for time.Time from text queries
for i, f := range r.my.Fields() {
if r.row[i] != nil {
switch f.Type {
case native.MYSQL_TYPE_TIMESTAMP, native.MYSQL_TYPE_DATETIME,
native.MYSQL_TYPE_DATE, native.MYSQL_TYPE_NEWDATE:
r.row[i] = r.row.ForceTime(i, location)
}
}
}
}
for i, d := range r.row {
dest[i] = driver.Value(d)
}
return nil
}
if err != io.EOF {
return errFilter(err)
}
if r.simpleQuery != nil && r.simpleQuery != textQuery {
if err = r.simpleQuery.Delete(); err != nil {
return errFilter(err)
}
}
r.my = nil
return io.EOF
}
示例3: Next
func (r *Rows) Next(dest []driver.Value) error {
more := r.rows.Next()
if !more {
if r.rows.Err() == nil {
return io.EOF
} else {
return r.rows.Err()
}
}
values, err := r.rows.Values()
if err != nil {
return err
}
if len(dest) < len(values) {
fmt.Printf("%d: %#v\n", len(dest), dest)
fmt.Printf("%d: %#v\n", len(values), values)
return errors.New("expected more values than were received")
}
for i, v := range values {
dest[i] = driver.Value(v)
}
return nil
}
示例4: Value
// Convert to SQL driver value.
func (pys Pinyins) Value() (value driver.Value, err error) {
var buf []byte
var ret = []byte{'{'}
for _, py := range pys {
for _, b := range []byte(py) {
if b >= 65 && b <= 90 { // A - Z
b += 32
}
if b >= 97 && b <= 122 { // a - z
buf = append(buf, b)
}
}
if len(buf) > 0 {
buf = append(buf, ',')
ret = append(ret, buf...)
buf = nil
}
}
if ret[len(ret)-1] == ',' {
ret[len(ret)-1] = '}'
} else {
ret = append(ret, '}')
}
value = driver.Value(string(ret))
return
}
示例5: TestFloat32_Value
func TestFloat32_Value(t *testing.T) {
expect, val := Float32(10.5), driver.Value(10.5)
var f Float32
f.Scan(val)
if f != expect {
t.Errorf("Expect %f, but %f", expect, f)
}
}
示例6: Value
// Value lets intArrays be inserted into PG
func (a IntArray) Value() (val driver.Value, err error) {
str := "{"
for _, i := range a {
str += strconv.Itoa(i) + ","
}
str += "}"
val = driver.Value(str)
return
}
示例7: Value
// Value function is called when the data is inserted on the database
func (e EncryptedString) Value() (driver.Value, error) {
// Calling KMS
crypted, err := encrypt([]byte(e), svc, keyID)
if err != nil {
return nil, err
}
// The byte array is stored as a base64 string on the database
return driver.Value(base64.StdEncoding.EncodeToString(crypted)), nil
}
示例8: Value
// Value implements the driver.Value interface.
func (c Certs) Value() (driver.Value, error) {
if c == nil {
return nil, nil
}
raw, err := json.Marshal(c)
if err != nil {
return nil, err
}
return driver.Value(raw), nil
}
示例9: Query
func (s *stmt) Query(args []driver.Value) (driver.Rows, error) {
s.conn.Lock()
defer s.conn.Unlock()
// create stement
st, err := s.conn.tx.Prepare(s.query)
if err != nil {
return nil, err
}
defer st.Close()
// query rows
var iargs []interface{}
for _, arg := range args {
iargs = append(iargs, arg)
}
rs, err := st.Query(iargs...)
if err != nil {
return nil, err
}
defer rs.Close()
// build all rows in memory, prevent statement lock
rows := &rows{}
rows.cols, err = rs.Columns()
if err != nil {
return nil, err
}
for rs.Next() {
values := make([]interface{}, len(rows.cols))
for i := range values {
values[i] = new(interface{})
}
if err := rs.Scan(values...); err != nil {
return rows, err
}
row := make([]driver.Value, len(rows.cols))
for i, v := range values {
row[i] = driver.Value(v)
}
rows.rows = append(rows.rows, row)
}
if err := rs.Err(); err != nil {
return rows, err
}
return rows, nil
}
示例10: TestLineValue
func TestLineValue(t *testing.T) {
for _, c := range []struct {
Input Line
Expected driver.Value
}{
{
Input: Line{{0, 0}, {1, 1}},
Expected: driver.Value(`LINESTRING(0 0, 1 1)`),
},
} {
val, err := c.Input.Value()
if err != nil {
t.Fatal(err)
}
if val != c.Expected {
t.Fatalf("expected %v, got %v", c.Expected, val)
}
}
}
示例11: Next
func (r *rows) Next(dest []sqldriver.Value) error {
if r.step >= r.Resultset.RowNumber() {
return io.EOF
} else if r.step == -1 {
return io.ErrUnexpectedEOF
}
for i := 0; i < r.Resultset.ColumnNumber(); i++ {
value, err := r.Resultset.GetValue(r.step, i)
if err != nil {
return err
}
dest[i] = sqldriver.Value(value)
}
r.step++
return nil
}
示例12: Value
func (b Hostname) Value() (driver.Value, error) {
return driver.Value(string(b)), nil
}
示例13: Value
// Value implements the Valuer interface in database/sql/driver package.
func (a IntArray) Value() (driver.Value, error) {
return driver.Value(string(String(fmt.Sprintf("%#v", a)).Replace("dna.IntArray", ""))), nil
}
示例14: Value
// Value implements the driver.Value interface.
func (s DeploymentStatus) Value() (driver.Value, error) {
return driver.Value(s.String()), nil
}
示例15: Value
// Value implements the Valuer interface in database/sql/driver package.
func (i Int) Value() (driver.Value, error) {
return driver.Value(int64(i.ToPrimitiveValue())), nil
}