Hi Mike,
I have set some break point in the example code batch.c, this is the debug result:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6a544f0 in std::string::data() const ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
This mistake occurs to this part of code in main():
if (prepare_insert_into_batch(session, &prepared) == CASS_OK) {
insert_into_batch_with_prepared(session, prepared, pairs);
}
The prepare_insert into batch():
CassError prepare_insert_into_batch(CassSession* session, const CassPrepared** prepared) {
CassError rc = CASS_OK;
CassFuture* future = NULL;
const char* query = "INSERT INTO examples.pairs (key, value) VALUES (?, ?)";
future = cass_session_prepare(session, query);
cass_future_wait(future);
rc = cass_future_error_code(future);
if (rc != CASS_OK) {
print_error(future);
} else {
*prepared = cass_future_get_prepared(future);
}
cass_future_free(future);
return rc;
}
The insert_into_batch_with_prepared():
CassError insert_into_batch_with_prepared(CassSession* session, const CassPrepared* prepared, const Pair* pairs) {
CassError rc = CASS_OK;
CassFuture* future = NULL;
CassBatch* batch = cass_batch_new(CASS_BATCH_TYPE_LOGGED);
const Pair* pair;
for (pair = pairs; pair->key != NULL; pair++) {
CassStatement* statement = cass_prepared_bind(prepared);
cass_statement_bind_string(statement, 0, pair->key);
cass_statement_bind_string(statement, 1, pair->value);
cass_batch_add_statement(batch, statement);
cass_statement_free(statement);
}
{
CassStatement* statement = cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES ('c', '3')", 0);
cass_batch_add_statement(batch, statement);
cass_statement_free(statement);
}
{
CassStatement* statement = cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES (?, ?)", 2);
cass_statement_bind_string(statement, 0, "d");
cass_statement_bind_string(statement, 1, "4");
cass_batch_add_statement(batch, statement);
cass_statement_free(statement);
}
future = cass_session_execute_batch(session, batch);
cass_future_wait(future);
rc = cass_future_error_code(future);
if (rc != CASS_OK) {
print_error(future);
}
I think that there is something wrong with the prepare process, because when I tried to use only batch operation, it works well.
Meng
在 2016年5月24日星期二 UTC+2上午1:41:22,Michael Penick写道: