我在Cassandra C++驱动程序中使用准备好的语句。如何将整数值绑定到“使用TTL ?”准备好的陈述的一部分?
我的声明就像
INSERT INTO table (column1, column2, column3) VALUES (?, ?, ?) USING TTL ?换句话说,如果我使用这个位置绑定到TTL,那么它的位置是什么?(在本例中,是4吗?)如果我按列名使用bind,那么它的列名是什么?
看起来这可以在CQL中完成,但是我没有找到任何关于C++驱动程序API的文档。
发布于 2018-06-26 17:19:25
在Cassandra CQL 2.0中,您可以拥有:
Cassandra1.2不允许为update语句的时间戳和TTL属性使用绑定标记,也不允许使用SELECT语句的极限属性。现在这个问题已经解决了,例如,您可以准备如下语句:
SELECT * FROM myTable LIMIT ?;
UPDATE myTable USING TTL ? SET v = 2 WHERE k = 'foo';有关更多信息,请参见他们的博客。
编辑:
我找到了此pdf,它告诉你更多:
边界参数:
驱动程序支持两种绑定参数:按标记和按名称。绑定参数?标记用于表示查询字符串中的绑定变量。这既用于常规查询,也用于准备参数化查询。除了将绑定标记添加到查询字符串之外,在构造新语句时,应用程序还必须向cass_statement_new()提供绑定变量的数量。如果查询不需要任何绑定变量,则可以使用0。然后使用cass_statement_bind_*()函数将值绑定到语句的变量。绑定变量可以由标记索引或名称绑定。
标记绑定索引示例
CassString query = cass_string_init("SELECT * FROM table1 WHERE column1
= ?");
/* Create a statement with a single parameter */
CassStatement* statement = cass_statement_new(query, 1);
cass_statement_bind_string(statement, 0, cass_string_init("abc"));
/* Execute statement */
cass_statement_free(statement);按标记名绑定示例
变量只能按已准备语句的名称绑定。存在此限制是因为需要由Cassandra提供的查询元数据将变量名映射到变量的标记索引。
/* Prepare statement */
/* The prepared query allocates the correct number of parameters
automatically */
CassStatement* statement = cass_prepared_bind(prepared);
/* The parameter can now be bound by name */
cass_statement_bind_string_by_name(statement, "column1",
cass_string_init("abc"));
/* Execute statement */
cass_statement_free(statement);回答您的问题,您可以使用bind索引(至少可以肯定):
CassString query = cass_string_init("INSERT INTO table (column1, column2, column3) VALUES (?, ?, ?) USING TTL ?");
/* Create a statement with a single parameter */
CassStatement* statement = cass_statement_new(query, 4); // Bind 4 variables.
cass_statement_bind_string(statement, 0, cass_string_init("abc")); // Bind abc to first column.
cass_statement_bind_string(statement, 1, cass_string_init("bcd")); // Bind bcd to second column.
cass_statement_bind_string(statement, 2, cass_string_init("cde")); // Bind cde to third column.
cass_statement_bind_string(statement, 3, cass_string_init(50)); // Bind 50 to TTL.
/* Execute statement */
cass_statement_free(statement);编辑:
请参见使用/useExpireExample.html e.html,在插入的情况下,我们使用TTL作为查询的最后一部分,如上文所示。
发布于 2020-09-15 18:13:20
我试验了卡桑德拉C++驱动程序2.11。我发现
https://stackoverflow.com/questions/50995145
复制相似问题