From 538e98db31bf86b5c6d3c0dedc44b330310d94b9 Mon Sep 17 00:00:00 2001 From: Phillip Couto Date: Thu, 20 Mar 2014 07:12:02 -0400 Subject: [PATCH] Added Size method to batch type so when building a batch statement the user can avoid the maximum limit. Also made the limit a exported constant. --- session.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/session.go b/session.go index a0d962fdd..55618d9c6 100644 --- a/session.go +++ b/session.go @@ -115,7 +115,7 @@ func (s *Session) ExecuteBatch(batch *Batch) error { // Prevent the execution of the batch if greater than the limit // Currently batches have a limit of 65536 queries. // https://datastax-oss.atlassian.net/browse/JAVA-229 - if len(batch.Entries) > 65536 { + if batch.Size() > BatchSizeMaximum { return ErrTooManyStmts } var err error @@ -340,6 +340,11 @@ func (b *Batch) RetryPolicy(r RetryPolicy) *Batch { return b } +// Size returns the number of batch statements to be executed by the batch operation. +func (b *Batch) Size() int { + return len(b.Entries) +} + type BatchType int const ( @@ -463,3 +468,5 @@ var ( ErrUnsupported = errors.New("feature not supported") ErrTooManyStmts = errors.New("too many statements") ) + +const BatchSizeMaximum = 65536