我将介绍如何使用 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 的表列表。