我是cassandra的新手,目前在虚拟应用程序中使用CassandraCSharpDriver。我想获取用户在给定键空间中描述的所有表的列表。
Cluster cluster = Cluster.Builder().AddContactPoints("IPAddress").Build();
Session session = cluster.Connect("MyKeySpace");
在这段代码中,我想获取MyKeySpace的所有表的列表
我将介绍如何使用DataStax Cassandra C#驱动程序准备该表列表:
连接到您的集群:
Cluster cluster = Cluster.Builder().AddContactPoints("IPAddress").Build();
Session session = cluster.Connect();
我将创建一个List<String>
并使用准备好的语句(因为这只是个好主意)来绑定键空间的名称。我的CQL语句仅选择columnfamily_name
,这应该是您所需要的。
List<String> tableList = new List<String>();
String strCQL = "SELECT columnfamily_name "
+ "FROM system.schema_columnfamilies WHERE keyspace_name=? ";
PreparedStatement pStatement = _session.Prepare(strCQL);
BoundStatement boundStatement = new BoundStatement(pStatement);
boundStatement.Bind("MyKeySpace");
现在,我将执行该语句,遍历结果,并将每个表名添加到上面创建的列表中。
RowSet results = session.Execute(boundStatement);
foreach (Row result in results.GetRows())
{
tableName = result.GetValue<String>("columnfamily_name");
tableList.Add(tableName);
}
现在,您应该具有可以添加到UI的表的列表。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句