Skip to content

"skip" method to generate a null value in prepared queries #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/cql/cql_execute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class CQL_EXPORT cql_execute_t :

void
push_back(const bool val);

void
skip();

void
pop_back();
Expand Down Expand Up @@ -111,6 +114,9 @@ class CQL_EXPORT cql_execute_t :

void
set_stream(const cql_stream_t& stream);

std::string
str() const;

private:
boost::shared_ptr<cql_message_execute_impl_t> _impl;
Expand Down
3 changes: 3 additions & 0 deletions include/cql/internal/cql_message_execute_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class cql_message_execute_impl_t :

void
push_back(const bool val);

void
skip();

void
pop_back();
Expand Down
6 changes: 6 additions & 0 deletions include/cql/internal/cql_serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ decode_string(cql::cql_byte_t* input,
std::ostream&
encode_bytes(std::ostream& output,
const std::vector<cql::cql_byte_t>& value);

std::ostream&
encode_null_byte(std::ostream& output);

void
encode_null_byte(std::vector<cql::cql_byte_t>& output);

std::istream&
decode_bytes(std::istream& input,
Expand Down
11 changes: 11 additions & 0 deletions src/cql/cql_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ cql::cql_execute_t::push_back(const bool val) {
_impl->push_back(val);
}

void
cql::cql_execute_t::skip() {
_impl->skip();
}

void
cql::cql_execute_t::pop_back() {
_impl->pop_back();
Expand Down Expand Up @@ -143,6 +148,12 @@ cql::cql_execute_t::stream()
return impl()->stream();
}

std::string
cql::cql_execute_t::str() const
{
return impl()->str();
}

void
cql::cql_execute_t::set_stream(const cql_stream_t& stream)
{
Expand Down
7 changes: 7 additions & 0 deletions src/cql/internal/cql_message_execute_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ cql::cql_message_execute_impl_t::push_back(const bool val) {
_params.push_back(p);
}

void
cql::cql_message_execute_impl_t::skip() {
cql::cql_message_execute_impl_t::param_t p;
cql::encode_null_byte(p);
_params.push_back(p);
}

void
cql::cql_message_execute_impl_t::pop_back() {
_params.pop_back();
Expand Down
17 changes: 17 additions & 0 deletions src/cql/internal/cql_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,23 @@ cql::encode_bytes(ostream& output,
return output;
}

ostream&
cql::encode_null_byte(ostream& output) {
// As per CQL bytes representation, if len is negative, no byte
// should follow and the represented value is 'null'
cql::cql_int_t len = -1;
output.write(reinterpret_cast<char*>(&len), sizeof(len));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without using the hton* function, this won't be portable, will it?

Also, how would this be different from encode_int(output, -1)? If you're trying to encode a NULL string, then encode_short(output, -1) might do what you want, if you're right about negative length values having special significance. If you're trying to encode a NULL integer (or floating point), then how do you distinguish NULL from any valid value? I don't know the binary spec, but based on this implementation, there is no room in the representation for NULL integer values.

return output;
}

void
cql::encode_null_byte(vector<cql::cql_byte_t>& output) {
cql::cql_byte_t l = -1;
output.resize(sizeof(l));
const cql::cql_byte_t* it = reinterpret_cast<cql::cql_byte_t*>(&l);
output.assign(it, it + sizeof(l));
}

istream&
cql::decode_bytes(istream& input,
vector<cql::cql_byte_t>& value) {
Expand Down