diff --git a/conn.go b/conn.go index fb7c3bc90..ee02d7476 100644 --- a/conn.go +++ b/conn.go @@ -858,6 +858,31 @@ func (c *Conn) executeQuery(qry *Query) *Iter { params: params, } } else { + values := qry.values + + params.values = make([]queryValues, len(values)) + hasSeenThVals := false + for i := 0; i < len(values); i++ { + v := ¶ms.values[i] + value := values[i] + if thVal, isTh := value.(TypeHintedValue); isTh { + if !hasSeenThVals && i > 0 { + err := fmt.Errorf( + "type-hinted and non-hinted values must not be mixed") + return &Iter{err: err} + } + hasSeenThVals = true + + if err := marshalQueryValue(thVal.TInfo, thVal.Value, v); err != nil { + return &Iter{err: err} + } + } else if hasSeenThVals { + err := fmt.Errorf( + "type-hinted and non-hinted values must not be mixed") + return &Iter{err: err} + } + } + frame = &writeQueryFrame{ statement: qry.stmt, params: params, diff --git a/control.go b/control.go index 01bd5da8c..8b4e3fed1 100644 --- a/control.go +++ b/control.go @@ -386,7 +386,7 @@ func (c *controlConn) HandleError(conn *Conn, err error, closed bool) { } oldConn := c.getConn() - if oldConn.conn != conn { + if oldConn != nil && oldConn.conn != conn { return } diff --git a/marshal.go b/marshal.go index fce258f99..d3fa15953 100644 --- a/marshal.go +++ b/marshal.go @@ -41,6 +41,12 @@ type Unmarshaler interface { UnmarshalCQL(info TypeInfo, data []byte) error } +// TypeHintedValue is a hinted value to power binding non-prepared stmts +type TypeHintedValue struct { + Value interface{} + TInfo TypeInfo +} + // Marshal returns the CQL encoding of the value for the Cassandra // internal type described by the info parameter. func Marshal(info TypeInfo, value interface{}) ([]byte, error) {