2017-06-22 57 views
0

我使用cassandra 2.1和CQL 3.2.1,我想讓用戶從UI指定密鑰空間名稱,複製策略,複製因子,然後將這些值傳遞給查詢執行插入CQL,但給我一個語法錯誤,我嘗試了很多,但沒有去寫>> 我創建keyspace - >連接 和列家族 - > keyspaces 但插入導致錯誤 這裏是我的代碼:錯誤消息,當cassandra python驅動程序接受來自用戶GUI的參數

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],...)"> 

回答

相關問題