diff --git a/include/ParameterSet.hpp b/include/ParameterSet.hpp index d6baec8..007cf50 100644 --- a/include/ParameterSet.hpp +++ b/include/ParameterSet.hpp @@ -208,6 +208,20 @@ class ParameterSet { return *this; } + /** + * Add a bool value for the current parameter + * @throws ParamMismatchException Supplied parameter is the wrong type for this position or too many have been set + * @return Reference to this parameter set to allow invocation chaining. + */ + ParameterSet& addBool(const bool &val) throw (voltdb::ParamMismatchException) { + validateType(WIRE_TYPE_BOOL, false); + m_buffer.ensureRemaining(2); + m_buffer.putInt8(WIRE_TYPE_BOOL); + m_buffer.putInt8(val ? 1 : 0); + m_currentParam++; + return *this; + } + /** * Add an array of date values for the current parameter * @throws ParamMismatchException Supplied parameter is the wrong type for this position or too many have been set diff --git a/include/Row.hpp b/include/Row.hpp index b7d649b..312db8d 100644 --- a/include/Row.hpp +++ b/include/Row.hpp @@ -115,6 +115,22 @@ class Row { return decodeDate(encodedDate); } + /* + * Retrieve the value at the specified column index as a bool. The type of the column + * must be bool. + * @throws InvalidColumnException The index of the column was invalid or the type of the column does + * not match the type of the get method. + * @return bool te value at the specified column + */ + bool getBool(int32_t column) throw(voltdb::InvalidColumnException) { + validateType(WIRE_TYPE_BOOL, column); + int8_t retval = m_data.getInt8(getOffset(column)); + if (retval == INT8_MIN) { + m_wasNull = true; + } + return retval == 1; + } + /* * Retrieve the value at the specified column index as an int64_t/BIGINT. The type of the column * must be BIGINT, INTEGER, SMALLINT, or TINYINT. @@ -289,6 +305,8 @@ class Row { getTimestamp(column); break; case WIRE_TYPE_DATE: getDate(column); break; + case WIRE_TYPE_BOOL: + getBool(column); break; case WIRE_TYPE_BIGINT: getInt64(column); break; case WIRE_TYPE_INTEGER: @@ -505,6 +523,8 @@ class Row { ostream << getTimestamp(ii); break; case WIRE_TYPE_DATE: ostream << getDate(ii); break; + case WIRE_TYPE_BOOL: + ostream << getBool(ii); break; case WIRE_TYPE_DECIMAL: ostream << getDecimal(ii).toString(); break; case WIRE_TYPE_VARBINARY: @@ -558,6 +578,7 @@ class Row { break; case WIRE_TYPE_TIMESTAMP: case WIRE_TYPE_DATE: + case WIRE_TYPE_BOOL: case WIRE_TYPE_BIGINT: case WIRE_TYPE_FLOAT: case WIRE_TYPE_STRING: @@ -631,6 +652,9 @@ class Row { case WIRE_TYPE_DATE: length = 4; break; + case WIRE_TYPE_BOOL: + length = 1; + break; case WIRE_TYPE_SMALLINT: length = 2; break; diff --git a/include/RowBuilder.h b/include/RowBuilder.h index e606861..1662c75 100644 --- a/include/RowBuilder.h +++ b/include/RowBuilder.h @@ -118,6 +118,9 @@ friend class TableTest; case WIRE_TYPE_TINYINT: addInt8(INT8_MIN); break; + case WIRE_TYPE_BOOL: + addInt8(INT8_MIN); + break; case WIRE_TYPE_SMALLINT: addInt16(INT16_MIN); break; @@ -208,6 +211,14 @@ friend class TableTest; return *this; } + RowBuilder& addBool(const bool &value) throw (InvalidColumnException, RowCreationException) { + validateType(WIRE_TYPE_BOOL); + m_buffer.ensureRemaining(1); + m_buffer.putInt8(value ? 1 : 0); + m_currentColumnIndex++; + return *this; + } + RowBuilder& addDecimal(const Decimal& value) { validateType(WIRE_TYPE_DECIMAL); m_buffer.ensureRemaining(2 * sizeof (int64_t)); diff --git a/include/WireType.h b/include/WireType.h index 2b723e4..a1d8f21 100644 --- a/include/WireType.h +++ b/include/WireType.h @@ -46,6 +46,7 @@ enum WireType { WIRE_TYPE_DATE = 12, WIRE_TYPE_VOLTTABLE = 21, WIRE_TYPE_DECIMAL = 22, + WIRE_TYPE_BOOL = 23, WIRE_TYPE_VARBINARY = 25, WIRE_TYPE_GEOGRAPHY_POINT = 26, WIRE_TYPE_GEOGRAPHY = 27, diff --git a/makefile b/makefile index e58ac8a..8dfa5b4 100644 --- a/makefile +++ b/makefile @@ -35,7 +35,7 @@ ifeq ($(PLATFORM),Linux) $(THIRD_PARTY_DIR)/libssl.a \ $(THIRD_PARTY_DIR)/libcrypto.a \ -ldl - SYSTEM_LIBS := -L $(BOOST_LIBS) -lc -lpthread -lrt -lboost_system -lboost_thread -lboost_date_time + SYSTEM_LIBS := -L $(BOOST_LIBS) -lc -lpthread -lrt -lboost_system-mt -lboost_thread-mt -lboost_date_time-mt endif .PHONEY: all clean test kit diff --git a/src/WireType.cpp b/src/WireType.cpp index fba995a..f233000 100644 --- a/src/WireType.cpp +++ b/src/WireType.cpp @@ -46,6 +46,8 @@ std::string wireTypeToString(WireType type) { return std::string("TIMESTAMP"); case WIRE_TYPE_DATE: return std::string("DATE"); + case WIRE_TYPE_BOOL: + return std::string("BOOL"); case WIRE_TYPE_DECIMAL: return std::string("DECIMAL"); case WIRE_TYPE_VARBINARY: diff --git a/test_src/SerializationTest.cpp b/test_src/SerializationTest.cpp index 24a8427..8ed8921 100644 --- a/test_src/SerializationTest.cpp +++ b/test_src/SerializationTest.cpp @@ -211,6 +211,7 @@ static bool compareParameter(ByteBuffer &original, std::string originalName, } break; case WIRE_TYPE_TINYINT: + case WIRE_TYPE_BOOL: { int8_t g = generated.getInt8(); int8_t o = original.getInt8(); diff --git a/test_src/TableTest.cpp b/test_src/TableTest.cpp index 0618a72..dbf77f6 100644 --- a/test_src/TableTest.cpp +++ b/test_src/TableTest.cpp @@ -32,7 +32,7 @@ namespace voltdb { -voltdb::WireType allTypes[12] = { +voltdb::WireType allTypes[13] = { WIRE_TYPE_TINYINT, WIRE_TYPE_SMALLINT, WIRE_TYPE_INTEGER, @@ -42,6 +42,7 @@ voltdb::WireType allTypes[12] = { WIRE_TYPE_TIMESTAMP, WIRE_TYPE_DATE, WIRE_TYPE_DECIMAL, + WIRE_TYPE_BOOL, WIRE_TYPE_VARBINARY, WIRE_TYPE_GEOGRAPHY_POINT, WIRE_TYPE_GEOGRAPHY, @@ -84,7 +85,8 @@ class TableTest : public CppUnit::TestFixture { << GeographyPoint(15.3333, 0) << GeographyPoint(15.999, 15.666) << GeographyPoint(0, 14.1) - << GeographyPoint(0, 0);; + << GeographyPoint(0, 0); + m_bool = true; } void someMaxValues() { @@ -127,6 +129,7 @@ class TableTest : public CppUnit::TestFixture { uint8_t m_binData[1024]; GeographyPoint m_ptValue; Geography m_polyValue; + bool m_bool; int32_t populateRow(RowBuilder &row, bool nullValue) { int32_t rowSize = 0; @@ -142,6 +145,9 @@ class TableTest : public CppUnit::TestFixture { case WIRE_TYPE_TINYINT: length = 1; break; + case WIRE_TYPE_BOOL: + length = 1; + break; case WIRE_TYPE_SMALLINT: length = 2; break; @@ -210,6 +216,9 @@ class TableTest : public CppUnit::TestFixture { case WIRE_TYPE_DATE: row.addDate(m_dateValue); return 4; + case WIRE_TYPE_BOOL: + row.addBool(m_bool); + return 1; case WIRE_TYPE_DECIMAL: { row.addDecimal(m_decValue); return 2*sizeof(int64_t); @@ -279,6 +288,11 @@ class TableTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(value == m_dateValue); break; } + case WIRE_TYPE_BOOL: { + bool value = row.getBool(i); + CPPUNIT_ASSERT(value == m_bool); + break; + } case WIRE_TYPE_DECIMAL: { Decimal value = row.getDecimal(i); CPPUNIT_ASSERT(value == m_decValue); @@ -358,6 +372,11 @@ class TableTest : public CppUnit::TestFixture { break; } + case WIRE_TYPE_BOOL: { + row.getBool(i); + break; + } + case WIRE_TYPE_DECIMAL: { row.getDecimal(i); break;