重新发布实际代码
// cassandra is a connected org::apache::cassandra::CassandraClient
// statement is a CqlPreparedResult
// result is a CqlResult
// CF declaration is:
/*
CREATE COLUMNFAMILY xp (
cid ascii PRIMARY KEY,
exp4 counter,
exp2 counter,
exp3 counter,
exp1 counter
) WITH
comment='' AND
comparator=text AND
read_repair_chance=0.100000 AND
gc_grace_seconds=864000 AND
default_validation=counter AND
min_compaction_threshold=4 AND
max_compaction_threshold=32 AND
replicate_on_write=True AND
compaction_strategy_class='SizeTieredCompactionStrategy' AND
compression_parameters:sstable_compression='org.apache.cassandra.io.compress.SnappyCompressor';
*/
std::vector<std::string> values;
values.resize(2);
values[0]="1";
values[1]="103";
cassandra->prepare_cql_query(statement,"update xp set exp2 = exp2 + ? where cid=?",Compression::NONE);
int32_t handle=statement.itemId;
try {
cassandra->execute_prepared_cql_query(result,handle,values);
}
catch(InvalidRequestException &e) {
cout << __LINE__ << " " << e.why << " "<< e.what() << endl;
}
// throws '?' is an invalid value, should be a long.
values.resize(1);
values[0]="103";
cassandra->prepare_cql_query(statement,"update xp set exp2 = exp2 + 1 where cid=?",Compression::NONE);
handle=statement.itemId;
cassandra->execute_prepared_cql_query(result,handle,values);
//works
所以看起来问题在于我们无法传递二进制数据。我试图传入一个包含 long 实际表示的字符串,但没有成功。当我从中读取数据时出现同样的问题,但我认为我可以管理它(扫描返回的字符串并将其一次转换一个字节作为最后的手段)
有人成功使用计数器、c++ 和 cql 吗?