- Use variable to hold mysql_insert_id in insertOption4/6 function.
- Use variable for timestamp binding in insertOption4/6 function
- Removed unused MYSQL_DELETE_OPTION_SERVER query
- Removed LAST_INSERT_ID from a query
- Unit test tries to insert shared network for non-existing server.
conn_.insertQuery(MySqlConfigBackendDHCPv4Impl::INSERT_OPTION4,
in_bindings);
+ // Fetch primary key value of the inserted option. We will use it in the
+ // next INSERT statement to associate this option with the server.
+ auto option_id = mysql_insert_id(conn_.mysql_);
+
+ // Timestamp is expected to be in this input binding.
+ auto timestamp_binding = in_bindings[11];
+
// Associate the option with the servers.
attachElementToServers(MySqlConfigBackendDHCPv4Impl::INSERT_OPTION4_SERVER,
server_selector,
- MySqlBinding::createInteger<uint64_t>(mysql_insert_id(conn_.mysql_)),
- in_bindings[11]);
+ MySqlBinding::createInteger<uint64_t>(option_id),
+ timestamp_binding);
}
/// @brief Sends query to insert or update global DHCP option.
conn_.insertQuery(MySqlConfigBackendDHCPv6Impl::INSERT_OPTION6,
in_bindings);
+ // Fetch primary key value of the inserted option. We will use it in the
+ // next INSERT statement to associate this option with the server.
+ auto option_id = mysql_insert_id(conn_.mysql_);
+
+ // Timestamp is expected to be in this input binding.
+ auto timestamp_binding = in_bindings[11];
+
// Associate the option with the servers.
attachElementToServers(MySqlConfigBackendDHCPv6Impl::INSERT_OPTION6_SERVER,
server_selector,
- MySqlBinding::createInteger<uint64_t>(mysql_insert_id(conn_.mysql_)),
- in_bindings[11]);
+ MySqlBinding::createInteger<uint64_t>(option_id),
+ timestamp_binding);
}
/// @brief Sends query to insert or update global DHCP option.
"INNER JOIN " #table_prefix "_server AS s" \
" ON a.server_id = s.id " \
"SET" \
- " o.option_id = LAST_INSERT_ID(o.option_id)," \
" o.code = ?," \
" o.value = ?," \
" o.formatted_value = ?," \
" WHERE prefix = ? AND prefix_length = ?)"
#endif
-#ifndef MYSQL_DELETE_OPTION_SERVER
-#define MYSQL_DELETE_OPTION_SERVER(table_prefix) \
- "DELETE os FROM " #table_prefix "_options_server AS os " \
- "WHERE os.option_id = " \
- " (SELECT o.option_id FROM " #table_prefix "_options AS o" \
- " INNER JOIN " #table_prefix "_options_server AS a" \
- " ON o.option_id = a.option_id " \
- " INNER JOIN " #table_prefix "_server AS s" \
- " ON a.server_id = s.id " \
- " WHERE s.tag = ? AND o.scope_id = ? AND o.code = ? AND o.space = ?)"
-#endif
-
#ifndef MYSQL_DELETE_SERVER
#define MYSQL_DELETE_SERVER(table_prefix) \
"DELETE FROM " #table_prefix "_server " \
// Test that shared network may be created and updated and the server tags
// are properly assigned to it.
TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateSharedNetwork4) {
+ auto shared_network = test_networks_[0];
+
+ // An attempto insert the shared network for non-existing server should fail.
+ EXPECT_THROW(cbptr_->createUpdateSharedNetwork4(ServerSelector::ONE("server1"),
+ shared_network),
+ DbOperationError);
+
// Insert the server1 into the database.
EXPECT_NO_THROW(cbptr_->createUpdateServer4(test_servers_[0]));
{
"server set");
}
- auto shared_network = test_networks_[0];
-
EXPECT_NO_THROW(cbptr_->createUpdateSharedNetwork4(ServerSelector::ALL(),
shared_network));
{
// Test that shared network may be created and updated and the server tags
// are properly assigned to it.
TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateSharedNetwork6) {
+ auto shared_network = test_networks_[0];
+
+ // An attempto insert the shared network for non-existing server should fail.
+ EXPECT_THROW(cbptr_->createUpdateSharedNetwork6(ServerSelector::ONE("server1"),
+ shared_network),
+ DbOperationError);
+
// Insert the server1 into the database.
EXPECT_NO_THROW(cbptr_->createUpdateServer6(test_servers_[0]));
{
"server set");
}
- auto shared_network = test_networks_[0];
-
EXPECT_NO_THROW(cbptr_->createUpdateSharedNetwork6(ServerSelector::ALL(),
shared_network));
{