duanfangfei5558 2017-03-23 06:50
浏览 95
已采纳

使用gocql在Cassandra查询中的可变参数

I want to make a generic function for performing cassandra queries using the gocql client, something like :

queryExec("INSERT INTO USERS VALUES(?,?,?,?)", userId, emailId, mobileNo, gender)

func queryExec(query string, args ...interface{}) err{
err := session.query(query, args).Exec()
return err

}

but when I pass it multiple argument values, it gives me the following error :

gocql : expected 4 values send got 1
  • 写回答

1条回答 默认 最新

  • drju37335 2017-03-23 07:10
    关注

    It should be

    err := session.query(query, args...).Exec()
    

    Without the ellipsis, query receives a slice containing all the args.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?