Hi all,
Recently, I faced a weird issue on GO SDK. I am using named parameters to form the n1ql query and while passing the values for those params I mistakenly given the wrong input type (string instead of int) for limit and offset. Since the input params of type interface it doesn’t thrown an error while compiling the code. While execution the query was successfully executed and returned the empty response. Below is the snippet of the code for both failure and success.
// Database connect
cluster, err := gocb.Connect(cbConnStr, gocb.ClusterOptions{
Username: "*******",
Password: "********",
TimeoutsConfig: gocb.TimeoutsConfig{
QueryTimeout: 10*time.Second,
},
})
if err != nil {
logger.BootstrapLogger.Error(err)
panic(err)
}
Failure case
queryStr := "SELECT * from `bucket-name` WHERE name=$name limit $limit offset $offset"
params["name"] = name
params["limit"] = limitVal //string
params["offset"] = offsetVal //string
rows, err = cluster.Query(queryStr, &gocb.QueryOptions{
NamedParameters: params,
})
if err != nil {
return nil, parseDatabaseError(err, logFields)
}
Success Case
queryStr := "SELECT * from `bucket-name` WHERE name=$name limit $limit offset $offset"
params["name"] = name
params["limit"] = limitVal //int
params["offset"] = offsetVal //int
rows, err = cluster.Query(queryStr, &gocb.QueryOptions{
NamedParameters: params,
})
if err != nil {
return nil, parseDatabaseError(err, logFields)
}
I have resolved the issue by changing the datatype of the params. But, my question is why the SDK doesn’t throw an error when I pass invalid type of values. Ideally, It should throw an error rather it is executing the query and returning the empty response.
Kindly, Please help on this.