@@ -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
2223func (q * Query ) Prepare (ctx context.Context ) error {
@@ -32,6 +33,9 @@ func (q *Query) Prepare(ctx context.Context) error {
3233}
3334
3435func (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+
169188func (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