How do you execute a cql file using gocql?

huangapple go评论90阅读模式
英文:

How do you execute a cql file using gocql?

问题

如果你要直接使用cqlsh与Cassandra进行接口交互,你可以按照以下步骤操作:

$ cqlsh
cqlsh:test> SOURCE '/home/me/reset_db.cql';

我尝试使用gocql多次进行这样的操作,但总是出现错误。例如,运行以下代码:

filePath := "/home/me/reset_db.cql"
SOURCE_FILE := "SOURCE (?)"
resetErr := session.Query(SOURCE_FILE, filePath).Exec()

会产生以下错误:

line 1:0 no viable alternative at input 'SOURCE' ([SOURCE]...)

那么我在这里做错了什么?

英文:

If you were to interface directly with Cassandra using cqlsh you could do the following:

$ cqlsh
cqlsh:test> SOURCE '/home/me/reset_db.cql'

I've tried to do this using gocql several times but I always get an error. For example, running this:

filePath := "/home/me/reset_db.cql"
SOURCE_FILE := "SOURCE (?)"
resetErr := session.Query(SOURCE_FILE, filePath).Exec()

Produces the following error:

line 1:0 no viable alternative at input 'SOURCE' ([SOURCE]...)

So what am I doing wrong here?

答案1

得分: 2

SOURCE是cqlsh中的快捷方式,不是通用的CQL命令。

您需要将文件内容读入字符串并执行它们。

英文:

SOURCE is a shortcut in cqlsh, not valid CQL command in general.

You'll need to read the file contents into strings and execute them.

huangapple
  • 本文由 发表于 2015年9月30日 22:39:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/32868977.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定