当 cassandra python 驱动程序从用户 GUI 接受参数时出现错误消息
ERROR MESSAGE when cassandra python Driver accept parameters from user GUI
我正在使用 cassandra 2.1 和 CQL 3.2.1,我想让用户从 UI 指定键空间名称、复制策略、复制因子,然后将这些值传递给查询以执行 Insert CQL,但是给我一个语法错误,我尝试了很多但没有写>>
我正在创建键空间 -> 连接
和列族 -> 键空间
但插入导致错误
这是我的代码:
from cassandra.cluster import Cluster
class Connection():
def __init__ (self , ips , keyspace ,replication_strategy ,replication_factor):
self.keyspace=keyspace
self.ips =ips
self.replication_strategy=replication_strategy
self.replication_factor=replication_factor
cluster = Cluster([ips])
session = cluster.connect()
session.execute("CREATE keyspace IF NOT EXISTS connect with replication={ 'class' : 'SimpleStrategy', 'replication_factor' :1}")
session.execute("CREATE TABLE IF NOT EXISTS connect.keyspaces (id int primary key , keyspaces_name text, replication_strategy text, replication_factor int)")
session.execute("INSERT INTO connect.keyspaces(id , keyspaces_name , replication_strategy ,replication_factor ) VALUES (1 " +',' + self.keyspace + ',' + self.replication_strategy +',' + self.replication_factor + ")")
and the ERROR MESSAGE IS :
File "cassandra/cluster.py", line 3822, in cassandra.cluster.ResponseFuture.result (cassandra/cluster.c:74332)
raise self._final_exception
SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 1:125 no viable alternative at input ',' (...) VALUES (1 ,noon,[SimpleStrategy],...)">
这意味着您正在构建的 INSERT 语句中存在语法错误。如果打印您构建的字符串查询,可能更容易排除故障。
或者,我建议将您的查询参数化,让驱动程序进行格式化:
http://datastax.github.io/python-driver/getting_started.html#passing-parameters-to-cql-queries
我正在使用 cassandra 2.1 和 CQL 3.2.1,我想让用户从 UI 指定键空间名称、复制策略、复制因子,然后将这些值传递给查询以执行 Insert CQL,但是给我一个语法错误,我尝试了很多但没有写>> 我正在创建键空间 -> 连接 和列族 -> 键空间 但插入导致错误 这是我的代码:
from cassandra.cluster import Cluster
class Connection():
def __init__ (self , ips , keyspace ,replication_strategy ,replication_factor):
self.keyspace=keyspace
self.ips =ips
self.replication_strategy=replication_strategy
self.replication_factor=replication_factor
cluster = Cluster([ips])
session = cluster.connect()
session.execute("CREATE keyspace IF NOT EXISTS connect with replication={ 'class' : 'SimpleStrategy', 'replication_factor' :1}")
session.execute("CREATE TABLE IF NOT EXISTS connect.keyspaces (id int primary key , keyspaces_name text, replication_strategy text, replication_factor int)")
session.execute("INSERT INTO connect.keyspaces(id , keyspaces_name , replication_strategy ,replication_factor ) VALUES (1 " +',' + self.keyspace + ',' + self.replication_strategy +',' + self.replication_factor + ")")
and the ERROR MESSAGE IS :
File "cassandra/cluster.py", line 3822, in cassandra.cluster.ResponseFuture.result (cassandra/cluster.c:74332)
raise self._final_exception
SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 1:125 no viable alternative at input ',' (...) VALUES (1 ,noon,[SimpleStrategy],...)">
这意味着您正在构建的 INSERT 语句中存在语法错误。如果打印您构建的字符串查询,可能更容易排除故障。
或者,我建议将您的查询参数化,让驱动程序进行格式化: http://datastax.github.io/python-driver/getting_started.html#passing-parameters-to-cql-queries