From 5cc387e0a1ef801fc511911e6ebe2c54272e5b6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Uzarski?= Date: Wed, 16 Oct 2024 16:17:11 +0200 Subject: [PATCH 1/2] session: prepare empty statement on nullptr I explained the reasoning in the code: // Apparently nullptr denotes an empty statement string. // It seems to be intended (for some weird reason, why not save a round-trip???) // to receive a server error in such case (CASS_ERROR_SERVER_SYNTAX_ERROR). // There is a test for this: `NullStringApiArgsTest.Integration_Cassandra_PrepareNullQuery`. --- scylla-rust-wrapper/src/session.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scylla-rust-wrapper/src/session.rs b/scylla-rust-wrapper/src/session.rs index fe5f419f..ce51b3bc 100644 --- a/scylla-rust-wrapper/src/session.rs +++ b/scylla-rust-wrapper/src/session.rs @@ -555,10 +555,12 @@ pub unsafe extern "C" fn cass_session_prepare_n( query: *const c_char, query_length: size_t, ) -> *const CassFuture { - let query_str = match ptr_to_cstr_n(query, query_length) { - Some(v) => v, - None => return std::ptr::null(), - }; + let query_str = ptr_to_cstr_n(query, query_length) + // Apparently nullptr denotes an empty statement string. + // It seems to be intended (for some weird reason, why not save a round-trip???) + // to receive a server error in such case (CASS_ERROR_SERVER_SYNTAX_ERROR). + // There is a test for this: `NullStringApiArgsTest.Integration_Cassandra_PrepareNullQuery`. + .unwrap_or_default(); let query = Query::new(query_str.to_string()); let cass_session: &CassSession = ptr_to_ref(cass_session_raw); From ff120666b1b9287e3926c821cad407d3d8f74902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Uzarski?= Date: Wed, 16 Oct 2024 16:18:19 +0200 Subject: [PATCH 2/2] ci: enable NullStringApiArgsTest suite --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 381d2879..7c2d6b34 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ ifndef SCYLLA_TEST_FILTER SCYLLA_TEST_FILTER := $(subst ${SPACE},${EMPTY},ClusterTests.*\ :BasicsTests.*\ :ConfigTests.*\ +:NullStringApiArgsTest.*\ :ConsistencyTwoNodeClusterTests.*\ :ConsistencyThreeNodeClusterTests.*\ :SerialConsistencyTests.*\ @@ -31,6 +32,7 @@ ifndef CASSANDRA_TEST_FILTER CASSANDRA_TEST_FILTER := $(subst ${SPACE},${EMPTY},ClusterTests.*\ :BasicsTests.*\ :ConfigTests.*\ +:NullStringApiArgsTest.*\ :ConsistencyTwoNodeClusterTests.*\ :ConsistencyThreeNodeClusterTests.*\ :SerialConsistencyTests.*\