susumu.yata
null+****@clear*****
Thu Dec 25 15:15:18 JST 2014
susumu.yata 2014-12-25 15:15:18 +0900 (Thu, 25 Dec 2014) New Revision: bd8d2957ef17f2bcb7091e7f4b136f9d241a559f https://github.com/groonga/grnxx/commit/bd8d2957ef17f2bcb7091e7f4b136f9d241a559f Message: Fix a bug that N/A values are accepted as keys. (#138) Modified files: lib/grnxx/impl/column/scalar/int.cpp lib/grnxx/impl/column/scalar/text.cpp Modified: lib/grnxx/impl/column/scalar/int.cpp (+8 -1) =================================================================== --- lib/grnxx/impl/column/scalar/int.cpp 2014-12-25 15:13:11 +0900 (25cca09) +++ lib/grnxx/impl/column/scalar/int.cpp 2014-12-25 15:15:18 +0900 (4f077c7) @@ -122,6 +122,9 @@ void Column<Int>::set_key_attribute() { } if (!indexes_.is_empty()) { + if (contains(grnxx::Int::na())) { + throw "N/A exist"; // TODO + } // TODO: Choose the best index. if (!indexes_[0]->test_uniqueness()) { throw "Key duplicate"; // TODO @@ -132,7 +135,11 @@ void Column<Int>::set_key_attribute() { for (size_t i = 0; i < valid_size; ++i) try { // TODO: Improve this loop. Int value = _get(i); - if (!value.is_na()) { + if (value.is_na()) { + if (table_->test_row(grnxx::Int(i))) { + throw "N/A exist"; // TODO + } + } else { if (!set.insert(value.raw()).second) { throw "Key duplicate"; // TODO } Modified: lib/grnxx/impl/column/scalar/text.cpp (+8 -1) =================================================================== --- lib/grnxx/impl/column/scalar/text.cpp 2014-12-25 15:13:11 +0900 (f7036ae) +++ lib/grnxx/impl/column/scalar/text.cpp 2014-12-25 15:15:18 +0900 (e3894e5) @@ -196,6 +196,9 @@ void Column<Text>::set_key_attribute() { } if (!indexes_.is_empty()) { + if (contains(grnxx::Text::na())) { + throw "N/A exist"; // TODO + } // TODO: Choose the best index. if (!indexes_[0]->test_uniqueness()) { throw "Key duplicate"; // TODO @@ -205,7 +208,11 @@ void Column<Text>::set_key_attribute() { size_t valid_size = get_valid_size(); for (size_t i = 0; i < valid_size; ++i) try { Text value = get(Int(i)); - if (!value.is_na()) { + if (value.is_na()) { + if (table_->test_row(grnxx::Int(i))) { + throw "N/A exist"; // TODO + } + } else { if (!set.insert(String(value.raw_data(), value.raw_size())).second) { throw "Key duplicate"; // TODO } -------------- next part -------------- HTML����������������������������... 下载