When retrieving data from the database I get this error if there is a null – tried with bool, i32, i64m double and worked fine – issue only with string.
RUST_BACKTRACE=1 cargo run
Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
Running `target/debug/cassandra-connector`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error(LIB_NULL_VALUE(CASS_ERROR_LIB_NULL_VALUE), State { next_error: None, backtrace: Some(stack backtrace:
0: 0x7fe28e3f0401 - backtrace::backtrace::libunwind::trace
at /opt/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.0/src/backtrace/mod.rs:90
- backtrace::backtrace::trace<closure>
at /opt/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.0/src/backtrace/mod.rs:42
1: 0x7fe28e3f1408 - backtrace::capture::{{impl}}::new
at /opt/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.0/src/lib.rs:101
2: 0x7fe28e3e82c1 - error_chain::make_backtrace
at /opt/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/error-chain-0.7.2/src/lib.rs:411
3: 0x7fe28e3e8377 - error_chain::{{impl}}::default
at /opt/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/error-chain-0.7.2/src/lib.rs:462
4: 0x7fe28e2b464b - cassandra_sys::error::{{impl}}::from_kind
at /opt/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/cassandra-sys-0.8.7/src/error.rs:6
5: 0x7fe28e2b4841 - cassandra_sys::error::{{impl}}::from
at /opt/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/cassandra-sys-0.8.7/src/error.rs:6
6: 0x7fe28e2aaf51 - core::convert::{{impl}}::into<cassandra_sys::error::ErrorKind,cassandra_sys::error::Error>
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/convert.rs:271
7: 0x7fe28e2a0be9 - cassandra_sys::error::{{impl}}::to_result<&str>
at /opt/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/cassandra-sys-0.8.7/src/error.rs:133
8: 0x7fe28e2b17c9 - cassandra::cassandra::column::{{impl}}::get_string
at /opt/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/cassandra-0.8.1/src/cassandra/column.rs:270
9: 0x7fe28e299e65 - cassandra_connector::show
at /home/proj/cassandra-connector/src/main.rs:38
10: 0x7fe28e29ab19 - cassandra_connector::main
at /home/proj/cassandra-connector/src/main.rs:76
11: 0x7fe28e4095ca - panic_unwind::__rust_maybe_catch_panic
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
12: 0x7fe28e4031b6 - std::panicking::try<(),fn()>
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:434
- std::panic::catch_unwind<fn(),()>
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panic.rs:351
- std::rt::lang_start
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/rt.rs:57
13: 0x7fe28e29b042 - main
14: 0x7fe28c8f0b34 - __libc_start_main
15: 0x7fe28e28d3e8 - <unknown>
16: 0x0 - <unknown>) })', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:837
stack backtrace:
1: 0x7fe28e4008fa - std::sys::imp::backtrace::tracing::imp::write::h3188f035833a2635
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
2: 0x7fe28e40286f - std::panicking::default_hook::{{closure}}::h6385b6959a2dd25b
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:349
3: 0x7fe28e40246e - std::panicking::default_hook::he4f3b61755d7fa95
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:365
4: 0x7fe28e402cb7 - std::panicking::rust_panic_with_hook::hf00b8130f73095ec
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:553
5: 0x7fe28e402af4 - std::panicking::begin_panic::h6227f62cb2cdaeb4
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:515
6: 0x7fe28e402a69 - std::panicking::begin_panic_fmt::h173eadd80ae64bec
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:499
7: 0x7fe28e4029f7 - rust_begin_unwind
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:475
8: 0x7fe28e4331ed - core::panicking::panic_fmt::h3b2d1e30090844ff
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/panicking.rs:69
9: 0x7fe28e2aa215 - core::result::unwrap_failed::h6f1089a4164b68db
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/macros.rs:29
10: 0x7fe28e2a58bb - <core::result::Result<T, E>>::unwrap::hddf0ca9c49ea9914
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:737
11: 0x7fe28e2b187a - cassandra::cassandra::column::Column::get_string::he370ca9df985f0ee
at /opt/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/cassandra-0.8.1/src/cassandra/column.rs:270
12: 0x7fe28e299e65 - cassandra_connector::show::hb977a687937c57f0
at /home/proj/cassandra-connector/src/main.rs:38
13: 0x7fe28e29ab19 - cassandra_connector::main::h0159580624f528ae
at /home/proj/cassandra-connector/src/main.rs:76
14: 0x7fe28e4095ca - __rust_maybe_catch_panic
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
15: 0x7fe28e4031b6 - std::rt::lang_start::h65647f6e36cffdae
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:434
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panic.rs:351
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/rt.rs:57
16: 0x7fe28e29b042 - main
17: 0x7fe28c8f0b34 - __libc_start_main
18: 0x7fe28e28d3e8 - <unknown>
19: 0x0 - <unknown>
I was hoping that the program would panic with the message “Bad string value! Error message….” As it does with other data types. (for the other types in the database it worked as expected: bool, i32, i62, double)
#[macro_use(stmt)]
extern crate cassandra;
use cassandra::*;
use std::str::FromStr;
#[derive(Debug,PartialEq,Clone,Copy)]
struct Basic {
bln: bool,
flt: f32,
dbl: f64,
i32: i32,
i64: i64,
}
fn insert_into_basic(session: &mut Session, key: &str, basic: Basic) -> CassResult {
let mut statement = stmt!("INSERT INTO examples.basic (key, bln, flt, dbl, i32, i64) VALUES \
(?, ?, ?, ?, ?, ?);");
statement.bind(0, key);
statement.bind(1, basic.bln);
statement.bind(2, basic.flt);
statement.bind(3, basic.dbl);
statement.bind(4, basic.i32);
statement.bind(5, basic.i64);
let res = session.execute(&statement).wait().unwrap();
res
}
fn select_all(session: &mut Session) -> CassResult {
let stmt = stmt!("SELECT * FROM examples.basic");
let result = match session.execute(&stmt).wait() {
Result::Ok(val) => val,
Result::Err(err) => panic!("Bad select! {}", err),
};
result
}
fn show(data: &CassResult) {
for i in data.iter() {
match i.get_column(5) {
Result::Ok(val) => {
match val.get_string() {
Result::Ok(s) => println!("{:?}", s),
Result::Err(err) => {
panic!("Bad string value! {}", err);
}
}
}
Result::Err(err) => panic!("Bad column! {}", err),
};
}
}
fn main() {
let input = Basic {
bln: true,
flt: 0.001f32,
dbl: 0.0002f64,
i32: 1,
i64: 2,
};
let contact_points = match ContactPoints::from_str("127.0.0.1") {
Result::Ok(val) => val,
Result::Err(err) => panic!("My error! {}", err),
};
let mut cluster = Cluster::default();
cluster.set_contact_points(contact_points).unwrap();
cluster.set_load_balance_round_robin();
match cluster.connect() {
Ok(ref mut session) => {
let ks_statement = &stmt!("CREATE KEYSPACE IF NOT EXISTS examples WITH replication = \
{ \'class\': \'SimpleStrategy\', \'replication_factor\': \
\'1\' };");
let table_statement = &stmt!("CREATE TABLE IF NOT EXISTS examples.basic (key text, \
bln boolean, flt float, dbl double, i32 int, i64 \
bigint, PRIMARY KEY (flt));");
session.execute(ks_statement).wait().unwrap();
session.execute(table_statement).wait().unwrap();
insert_into_basic(session, "test", input);
let output = select_all(session);
show(&output);
println!("{:?}", input);
// println!("{:?}", output);
}
err => println!("{:?}", err),
}
}