當前位置: 首頁>>代碼示例>>Golang>>正文


Golang driver.Value函數代碼示例

本文整理匯總了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
}
開發者ID:carriercomm,項目名稱:empire,代碼行數:8,代碼來源:processes.go

示例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
}
開發者ID:whosonfirst,項目名稱:go-whosonfirst-rtree,代碼行數:36,代碼來源:driver.go

示例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
}
開發者ID:josephwinston,項目名稱:flynn,代碼行數:27,代碼來源:sql.go

示例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
}
開發者ID:caiguanhao,項目名稱:gopinyin,代碼行數:27,代碼來源:gopinyin.go

示例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)
	}
}
開發者ID:hirokidaichi,項目名稱:genmai,代碼行數:8,代碼來源:type_test.go

示例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
}
開發者ID:fortytw2,項目名稱:eden,代碼行數:12,代碼來源:int_array.go

示例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
}
開發者ID:dimiro1,項目名稱:experiments,代碼行數:12,代碼來源:main.go

示例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
}
開發者ID:iserko,項目名稱:empire,代碼行數:13,代碼來源:apps.go

示例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
}
開發者ID:DATA-DOG,項目名稱:go-txdb,代碼行數:47,代碼來源:db.go

示例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)
		}
	}
}
開發者ID:yanbai1990,項目名稱:geo,代碼行數:19,代碼來源:line_test.go

示例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
}
開發者ID:blalor,項目名稱:go-mysql,代碼行數:20,代碼來源:driver.go

示例12: Value

func (b Hostname) Value() (driver.Value, error) {
	return driver.Value(string(b)), nil
}
開發者ID:hartsock,項目名稱:go-swagger,代碼行數:3,代碼來源:default.go

示例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
}
開發者ID:olragon,項目名稱:dna,代碼行數:4,代碼來源:int_array.go

示例14: Value

// Value implements the driver.Value interface.
func (s DeploymentStatus) Value() (driver.Value, error) {
	return driver.Value(s.String()), nil
}
開發者ID:carriercomm,項目名稱:empire,代碼行數:4,代碼來源:deployments.go

示例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
}
開發者ID:olragon,項目名稱:dna,代碼行數:4,代碼來源:int.go


注:本文中的database/sql/driver.Value函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。