// No data returned but the SQL query succeeded. Only possibility
// is that there is no entry in the differences table for the given
// zone and version.
- isc_throw(NoSuchSerial, "No entry in differences table for " <<
+ isc_throw(NoSuchSerial, "No entry in differences table for" <<
" zone ID " << zone_id << ", serial number " << serial);
}
executer.exec();
}
-vector<vector<string> >
-SQLite3Accessor::getRecordDiff(int zone_id) {
- sqlite3_stmt* const stmt = dbparameters_->getStatement(GET_RECORD_DIFF);
- sqlite3_bind_int(stmt, 1, zone_id);
-
- vector<vector<string> > result;
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- vector<string> row_result;
- for (int i = 0; i < 6; ++i) {
- row_result.push_back(convertToPlainChar(sqlite3_column_text(stmt,
- i),
- dbparameters_->db_));
- }
- result.push_back(row_result);
- }
- sqlite3_reset(stmt);
-
- return (result);
-}
-
std::string
SQLite3Accessor::findPreviousName(int zone_id, const std::string& rname)
const
int zone_id, uint32_t serial, DiffOperation operation,
const std::string (¶ms)[DIFF_PARAM_COUNT]);
- // A short term method for tests until we implement more complete
- // API to retrieve diffs (#1330). It returns all records of the diffs
- // table whose zone_id column is identical to the given value.
- // Since this is a short term workaround, it ignores some corner cases
- // (such as an SQLite3 execution failure) and is not very efficient,
- // in favor of brevity. Once #1330 is completed, this method must be
- // removed, and the tests using this method must be rewritten using the
- // official API.
- std::vector<std::vector<std::string> > getRecordDiff(int zone_id);
-
/// The SQLite3 implementation of this method returns a string starting
/// with a fixed prefix of "sqlite3_" followed by the DB file name
/// removing any path name. For example, for the DB file
"1300", DIFF_ADD_TEXT
};
const char* const diff_add_a_data[] = {
- "dns01.example.com.", "A", "3600", "192.0.2.10", "1234", DIFF_ADD_TEXT
+ "dns01.example.com.", "A", "3600", "192.0.2.10", "1300", DIFF_ADD_TEXT
};
// The following two are helper functions to convert textual test data
// diffs.
void
checkDiffs(const vector<const char* const*>& expected,
- const vector<vector<string> >& actual)
+ DatabaseAccessor::IteratorContextPtr rr_iterator)
{
+ vector<vector<string> > actual;
+ string columns_holder[DatabaseAccessor::COLUMN_COUNT];
+ while (rr_iterator->getNext(columns_holder)) {
+ // Reorder the 'actual' vector to be compatible with the expected one.
+ vector<string> columns;
+ columns.push_back(columns_holder[DatabaseAccessor::NAME_COLUMN]);
+ columns.push_back(columns_holder[DatabaseAccessor::TYPE_COLUMN]);
+ columns.push_back(columns_holder[DatabaseAccessor::TTL_COLUMN]);
+ columns.push_back(columns_holder[DatabaseAccessor::RDATA_COLUMN]);
+ actual.push_back(columns);
+ }
EXPECT_EQ(expected.size(), actual.size());
const size_t n_diffs = std::min(expected.size(), actual.size());
for (size_t i = 0; i < n_diffs; ++i) {
getOperation(diff_end_data), diff_params);
// Until the diffs are committed, they are not visible to other accessors.
- EXPECT_TRUE(another_accessor->getRecordDiff(zone_id).empty());
+ EXPECT_THROW(another_accessor->getDiffs(zone_id, 1234, 1300),
+ NoSuchSerial);
accessor->commit();
expected_stored.clear();
expected_stored.push_back(diff_begin_data);
expected_stored.push_back(diff_end_data);
- checkDiffs(expected_stored, accessor->getRecordDiff(zone_id));
+ checkDiffs(expected_stored, accessor->getDiffs(zone_id, 1234, 1300));
// Now it should be visible to others, too.
- checkDiffs(expected_stored, another_accessor->getRecordDiff(zone_id));
+ checkDiffs(expected_stored, another_accessor->getDiffs(zone_id, 1234,
+ 1300));
}
TEST_F(SQLite3Update, addRecordOfLargeSerial) {
expected_stored.clear();
expected_stored.push_back(begin_data);
expected_stored.push_back(diff_end_data);
- checkDiffs(expected_stored, accessor->getRecordDiff(zone_id));
+ checkDiffs(expected_stored, accessor->getDiffs(zone_id, 4294967295, 1300));
}
TEST_F(SQLite3Update, addDiffWithoutUpdate) {
getOperation(diff_begin_data), diff_params);
accessor->rollback();
- EXPECT_TRUE(accessor->getRecordDiff(zone_id).empty());
+ EXPECT_THROW(accessor->getDiffs(zone_id, 1234, 1234), NoSuchSerial);
}
TEST_F(SQLite3Update, addDiffInBadOrder) {
copy(diff_end_data, diff_end_data + DatabaseAccessor::DIFF_PARAM_COUNT,
diff_params);
accessor->addRecordDiff(zone_id, getVersion(diff_end_data),
- getOperation(diff_end_data), diff_params);
+ static_cast<DatabaseAccessor::DiffOperation>(
+ lexical_cast<int>(DIFF_DELETE_TEXT)),
+ diff_params);
copy(diff_begin_data, diff_begin_data + DatabaseAccessor::DIFF_PARAM_COUNT,
diff_params);
accessor->addRecordDiff(zone_id, getVersion(diff_begin_data),
- getOperation(diff_begin_data), diff_params);
+ static_cast<DatabaseAccessor::DiffOperation>(
+ lexical_cast<int>(DIFF_ADD_TEXT)),
+ diff_params);
accessor->commit();
expected_stored.clear();
expected_stored.push_back(diff_end_data);
expected_stored.push_back(diff_begin_data);
- checkDiffs(expected_stored, accessor->getRecordDiff(zone_id));
+ checkDiffs(expected_stored, accessor->getDiffs(zone_id, 1300, 1234));
}
TEST_F(SQLite3Update, addDiffWithUpdate) {
expected_stored.push_back(diff_end_data);
expected_stored.push_back(diff_add_a_data);
- checkDiffs(expected_stored, accessor->getRecordDiff(zone_id));
+ checkDiffs(expected_stored, accessor->getDiffs(zone_id, 1234, 1300));
}
TEST_F(SQLite3Update, addDiffWithNoTable) {