在 Cassandra CQL 2.0 中,您可以:
Cassandra 1.2 不允许您对更新语句的 TIMESTAMP 和 TTL 属性以及 SELECT 语句的 LIMIT 属性使用绑定标记。现在已修复此问题,例如,您可以准备以下语句:
SELECT * FROM myTable LIMIT ?;
UPDATE myTable USING TTL ? SET v = 2 WHERE k = 'foo';
查看他们的blog 了解更多信息。
编辑:
我找到了this 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);
要回答您的问题,您可以使用按索引绑定(至少可以肯定):
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);
编辑:
请参阅https://docs.datastax.com/en/cql/3.3/cql/cql_using/useExpireExample.html,您可以在其中看到在 INSERT 的情况下,我们将使用 TTL 作为查询的最后一部分,如上所示。