Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

Commit 5d5325d

Browse files
committed
query: verify bind errors
1 parent 5297b25 commit 5d5325d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

query.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Query struct {
1717
asyncExec func(context.Context, *transport.Conn, transport.Statement, frame.Bytes, transport.ResponseHandler)
1818
res []transport.ResponseHandler
1919
retryPolicy transport.RetryPolicy
20+
err []error
2021
}
2122

2223
func (q *Query) Prepare(ctx context.Context) error {
@@ -32,6 +33,9 @@ func (q *Query) Prepare(ctx context.Context) error {
3233
}
3334

3435
func (q *Query) Exec(ctx context.Context) (Result, error) {
36+
if q.err != nil {
37+
return Result{}, fmt.Errorf("query can't be executed: %v", q.err)
38+
}
3539
info, err := q.info()
3640
if err != nil {
3741
return Result{}, err
@@ -166,7 +170,30 @@ func (q *Query) info() (transport.QueryInfo, error) {
166170
return q.session.cluster.NewQueryInfo(), nil
167171
}
168172

173+
func (q *Query) checkBounds(pos int) error {
174+
if q.stmt.Metadata != nil {
175+
if pos < 0 || pos >= len(q.stmt.Values) {
176+
return fmt.Errorf("no bind marker with position %d", pos)
177+
}
178+
179+
return nil
180+
}
181+
182+
for i := len(q.stmt.Values); i <= pos; i++ {
183+
q.stmt.Values = append(q.stmt.Values, frame.Value{})
184+
}
185+
return nil
186+
}
187+
169188
func (q *Query) BindInt64(pos int, v int64) *Query {
189+
if err := q.checkBounds(pos); err != nil {
190+
q.err = append(q.err, err)
191+
return q
192+
}
193+
if q.stmt.Metadata != nil && q.stmt.Metadata.Columns[pos].Type.ID != frame.BigIntID {
194+
q.err = append(q.err, fmt.Errorf("can't bind int64 to column of type BigInt"))
195+
}
196+
170197
p := &q.stmt.Values[pos]
171198
if p.N == 0 {
172199
p.N = 8

0 commit comments

Comments
 (0)