Source File
extended_query_builder.go
Belonging Package
github.com/jackc/pgx/v4
package pgx
import (
)
type extendedQueryBuilder struct {
paramValues [][]byte
paramValueBytes []byte
paramFormats []int16
resultFormats []int16
resetCount int
}
func ( *extendedQueryBuilder) ( *pgtype.ConnInfo, uint32, interface{}) error {
:= chooseParameterFormatCode(, , )
.paramFormats = append(.paramFormats, )
, := .encodeExtendedParamValue(, , , )
if != nil {
return
}
.paramValues = append(.paramValues, )
return nil
}
func ( *extendedQueryBuilder) ( int16) {
.resultFormats = append(.resultFormats, )
}
func ( *extendedQueryBuilder) () {
.paramValues = .paramValues[0:0]
.paramValueBytes = .paramValueBytes[0:0]
.paramFormats = .paramFormats[0:0]
.resultFormats = .resultFormats[0:0]
.resetCount++
if .resetCount%128 == 0 {
if cap(.paramValues) > 64 {
.paramValues = make([][]byte, 0, cap(.paramValues)/2)
}
if cap(.paramValueBytes) > 256 {
.paramValueBytes = make([]byte, 0, cap(.paramValueBytes)/2)
}
if cap(.paramFormats) > 64 {
.paramFormats = make([]int16, 0, cap(.paramFormats)/2)
}
if cap(.resultFormats) > 64 {
.resultFormats = make([]int16, 0, cap(.resultFormats)/2)
}
}
}
func ( *extendedQueryBuilder) ( *pgtype.ConnInfo, uint32, int16, interface{}) ([]byte, error) {
if == nil {
return nil, nil
}
:= reflect.ValueOf()
:= .Kind() == reflect.Ptr
if && .IsNil() {
return nil, nil
}
if .paramValueBytes == nil {
.paramValueBytes = make([]byte, 0, 128)
}
var error
var []byte
:= len(.paramValueBytes)
if , := .(string); {
return []byte(), nil
}
if == TextFormatCode {
if , := .(pgtype.TextEncoder); {
, = .EncodeText(, .paramValueBytes)
if != nil {
return nil,
}
if == nil {
return nil, nil
}
.paramValueBytes =
return .paramValueBytes[:], nil
}
} else if == BinaryFormatCode {
if , := .(pgtype.BinaryEncoder); {
, = .EncodeBinary(, .paramValueBytes)
if != nil {
return nil,
}
if == nil {
return nil, nil
}
.paramValueBytes =
return .paramValueBytes[:], nil
}
}
if , := .DataTypeForValue(); {
:= .Value
if , := .(pgtype.TextEncoder); {
:= .Set()
if != nil {
return nil,
}
, = .EncodeText(, .paramValueBytes)
if != nil {
return nil,
}
if == nil {
return nil, nil
}
.paramValueBytes =
return .paramValueBytes[:], nil
}
}
if , := stripNamedType(&); {
return .(, , , )
}
return nil, SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", , , ))
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |