MySqlBindingCollection in_server_bindings = { first_binding, in_bindings };
for (auto tag : server_selector.getTags()) {
in_server_bindings.push_back(MySqlBinding::createString(tag.get()));
- conn_.insertQuery(index, in_server_bindings);
+ // Handles the case where the server does not exists.
+ try {
+ conn_.insertQuery(index, in_server_bindings);
+ } catch (const NullKeyError&) {
+ // The message should give the tag value.
+ isc_throw(NullKeyError,
+ "server '" << tag.get() << "' does not exist");
+ }
in_server_bindings.pop_back();
}
}
// This should fail because the server must be inserted first.
EXPECT_THROW(cbptr_->createUpdateGlobalParameter4(ServerSelector::ONE("server1"),
global_parameter1),
- DbOperationError);
+ NullKeyError);
// Create two servers.
EXPECT_NO_THROW(cbptr_->createUpdateServer4(test_servers_[1]));
// An attempt to add a subnet to a non-existing server (server1) should fail.
EXPECT_THROW(cbptr_->createUpdateSubnet4(ServerSelector::MULTIPLE({ "server1", "server2" }),
subnet2),
- DbOperationError);
+ NullKeyError);
// The subnet shouldn't have been added, even though one of the servers exists.
Subnet4Ptr returned_subnet;
// An attempto insert the shared network for non-existing server should fail.
EXPECT_THROW(cbptr_->createUpdateSharedNetwork4(ServerSelector::ONE("server1"),
shared_network),
- DbOperationError);
+ NullKeyError);
// Insert the server1 into the database.
EXPECT_NO_THROW(cbptr_->createUpdateServer4(test_servers_[0]));
// fail.
EXPECT_THROW(cbptr_->createUpdateOptionDef4(ServerSelector::ONE("server1"),
option1),
- DbOperationError);
+ NullKeyError);
// Create two servers.
EXPECT_NO_THROW(cbptr_->createUpdateServer4(test_servers_[1]));
EXPECT_THROW(cbptr_->createUpdateOption4(ServerSelector::ONE("server1"),
opt_boot_file_name1),
- DbOperationError);
+ NullKeyError);
// Create two servers.
EXPECT_NO_THROW(cbptr_->createUpdateServer4(test_servers_[1]));
StampedValuePtr global_parameter2 = StampedValue::create("global", "value2");
StampedValuePtr global_parameter3 = StampedValue::create("global", "value3");
+ // Try to insert one of them and associate with non-existing server.
+ // This should fail because the server must be inserted first.
+ EXPECT_THROW(cbptr_->createUpdateGlobalParameter6(ServerSelector::ONE("server1"),
+ global_parameter1),
+ NullKeyError);
+
// Create two servers.
EXPECT_NO_THROW(cbptr_->createUpdateServer6(test_servers_[1]));
{
// An attempt to add a subnet to a non-existing server (server1) should fail.
EXPECT_THROW(cbptr_->createUpdateSubnet6(ServerSelector::MULTIPLE({ "server1", "server2" }),
subnet2),
- DbOperationError);
+ NullKeyError);
// The subnet shouldn't have been added, even though one of the servers exists.
Subnet6Ptr returned_subnet;
// An attempto insert the shared network for non-existing server should fail.
EXPECT_THROW(cbptr_->createUpdateSharedNetwork6(ServerSelector::ONE("server1"),
shared_network),
- DbOperationError);
+ NullKeyError);
// Insert the server1 into the database.
EXPECT_NO_THROW(cbptr_->createUpdateServer6(test_servers_[0]));
// fail.
EXPECT_THROW(cbptr_->createUpdateOptionDef6(ServerSelector::ONE("server1"),
option1),
- DbOperationError);
+ NullKeyError);
// Create two servers.
EXPECT_NO_THROW(cbptr_->createUpdateServer6(test_servers_[1]));
EXPECT_THROW(cbptr_->createUpdateOption6(ServerSelector::ONE("server1"),
opt_timezone1),
- DbOperationError);
+ NullKeyError);
// Create two servers.
EXPECT_NO_THROW(cbptr_->createUpdateServer6(test_servers_[1]));
-// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2019 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
isc::Exception(file, line, what) {}
};
+/// @brief Key is NULL but was specified NOT NULL
+class NullKeyError : public Exception {
+public:
+ NullKeyError(const char* file, size_t line, const char* what) :
+ isc::Exception(file, line, what) {}
+};
+
/// @brief Attempt to modify data in read-only database.
class ReadOnlyDb : public Exception {
public:
if (mysql_errno(mysql_) == ER_DUP_ENTRY) {
isc_throw(DuplicateEntry, "Database duplicate entry error");
}
+ // Failure: check for the special case of WHERE returning NULL.
+ if (mysql_errno(mysql_) == ER_BAD_NULL_ERROR) {
+ isc_throw(NullKeyError, "Database bad NULL error");
+ }
checkError(status, index, "unable to execute");
}
}