Check size of ExecuteResponse.Results before using it because under some conditions...
authorFrancis Chuang <francis.chuang@boostport.com>
Thu, 14 Dec 2017 10:10:41 +0000 (21:10 +1100)
committerFrancis Chuang <francis.chuang@boostport.com>
Thu, 14 Dec 2017 10:28:51 +0000 (21:28 +1100)
statement.go

index ba231e3..ff30fad 100644 (file)
@@ -24,6 +24,7 @@ import (
 
        "github.com/apache/calcite-avatica-go/message"
        "golang.org/x/net/context"
+       "errors"
 )
 
 type stmt struct {
@@ -93,8 +94,14 @@ func (s *stmt) exec(ctx context.Context, args []namedValue) (driver.Result, erro
                return nil, err
        }
 
+       results := res.(*message.ExecuteResponse).Results
+
+       if len(results) <= 0{
+               return nil, errors.New("empty ResultSet in ExecuteResponse")
+       }
+
        // Currently there is only 1 ResultSet per response
-       changed := int64(res.(*message.ExecuteResponse).Results[0].UpdateCount)
+       changed := int64(results[0].UpdateCount)
 
        return &result{
                affectedRows: changed,