From b5b7cc8f7233da6ac001c8bf5ef6823b7d912dbf Mon Sep 17 00:00:00 2001 From: Janmejay Singh Date: Mon, 26 Jun 2023 19:48:35 +0530 Subject: [PATCH 1/4] Use type-hinted-values to allow bound-values to be used outside of prepared-stmts --- conn.go | 25 +++++++++++++++++++++++++ marshal.go | 6 ++++++ 2 files changed, 31 insertions(+) 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/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) { From 0b6d6bcf30eb259095c25af812a1ba0aee0e33ab Mon Sep 17 00:00:00 2001 From: Shubham Jadhav Date: Mon, 23 Sep 2024 19:53:09 -0700 Subject: [PATCH 2/4] Perform null check before dereference --- control.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } From e7aac9b8f64e67870d16ab9d22fc071cf613e90d Mon Sep 17 00:00:00 2001 From: Shubham Jadhav Date: Mon, 23 Sep 2024 20:09:35 -0700 Subject: [PATCH 3/4] Revert "Perform null check before dereference" --- control.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control.go b/control.go index 8b4e3fed1..01bd5da8c 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 != nil && oldConn.conn != conn { + if oldConn.conn != conn { return } From 9ab6b542ecbb54e5e38b62f9cd1d39d244c190a7 Mon Sep 17 00:00:00 2001 From: Shubham Jadhav Date: Thu, 5 Dec 2024 14:10:48 -0800 Subject: [PATCH 4/4] foo --- control.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 }