Skip to content
Merged
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
7 changes: 2 additions & 5 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,13 @@ Value::Value(const DataType::ConstPtr& data_type, Decoder decoder)
} else if (data_type->is_user_type()) {
const UserType& user_type = static_cast<const UserType&>(*data_type);
count_ = user_type.fields().size();
} else {
count_ = 0;
}
}

bool Value::update(const Decoder& decoder) {
decoder_ = decoder;
if (!decoder_.is_null()) {
is_null_ = decoder_.is_null();
if (!is_null_) {
if (data_type_->is_collection()) {
return decoder_.decode_int32(count_);
} else if (data_type_->is_tuple()) {
Expand All @@ -223,9 +222,7 @@ bool Value::update(const Decoder& decoder) {
}
} else {
count_ = 0;
is_null_ = true;
}

return true;
}

Expand Down
24 changes: 24 additions & 0 deletions tests/src/unit/tests/test_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ TEST(ValueUnitTest, BadDecimal) {
CASS_ERROR_LIB_NOT_ENOUGH_DATA);
}

TEST(ValueUnitTest, NullInNextRow) {
DataType::ConstPtr data_type(new DataType(CASS_VALUE_TYPE_INT));

// Size (int32_t) and contents of element
const signed char input[8] = { 0, 0, 0, 4, 0, 0, 0, 2 };
Decoder decoder((const char*)input, 12);

// init with a non null column in a row
Value value(data_type, 2, decoder);
EXPECT_FALSE(value.is_null());

const signed char null_input[4] = { -1, 1, 1, 1 };
Decoder null_decoder((const char*)null_input, 4);

// simulate next row null value in the column
null_decoder.update_value(value);
EXPECT_TRUE(value.is_null());

// next row non null value check is_null() returns correct value
Decoder decoder2((const char*)input, 12);
decoder2.update_value(value);
EXPECT_FALSE(value.is_null());
}

TEST(ValueUnitTest, NullElementInCollectionList) {
const signed char input[12] = {
-1, -1, -1, -1, // Element 1 is NULL
Expand Down