// most recently added host is different than the host id of the
// currently processed host.
if (hosts.empty() || row_host_id != hosts.back()->getHostId()) {
- HostPtr host = retrieveHost(r, row, row_host_id);
+ HostPtr host(retrieveHost(r, row, row_host_id));
hosts.push_back(host);
}
}
OptionPtr option_;
};
-} // end of anonymous namespace
+} // namespace
namespace isc {
namespace dhcp {
/// @param single A boolean value indicating if a single host is
/// expected to be returned, or multiple hosts.
void getHostCollection(StatementIndex stindex, PsqlBindArrayPtr bind,
- boost::shared_ptr<PgSqlHostExchange> exchange,
+ std::shared_ptr<PgSqlHostExchange> exchange,
ConstHostCollection& result, bool single) const;
/// @brief Retrieves a host by subnet and client's unique identifier.
const uint8_t* identifier_begin,
const size_t identifier_len,
StatementIndex stindex,
- boost::shared_ptr<PgSqlHostExchange> exchange) const;
+ std::shared_ptr<PgSqlHostExchange> exchange) const;
/// @brief Throws exception if database is read only.
///
/// has failed.
std::pair<uint32_t, uint32_t> getVersion() const;
- /// @brief Pointer to the object representing an exchange which
- /// can be used to retrieve hosts and DHCPv4 options.
- boost::shared_ptr<PgSqlHostWithOptionsExchange> host_exchange_;
-
- /// @brief Pointer to an object representing an exchange which can
- /// be used to retrieve hosts, DHCPv6 options and IPv6 reservations.
- boost::shared_ptr<PgSqlHostIPv6Exchange> host_ipv6_exchange_;
-
- /// @brief Pointer to an object representing an exchange which can
- /// be used to retrieve hosts, DHCPv4 and DHCPv6 options, and
- /// IPv6 reservations using a single query.
- boost::shared_ptr<PgSqlHostIPv6Exchange> host_ipv46_exchange_;
-
- /// @brief Pointer to an object representing an exchange which can
- /// be used to insert new IPv6 reservation.
- boost::shared_ptr<PgSqlIPv6ReservationExchange> host_ipv6_reservation_exchange_;
-
- /// @brief Pointer to an object representing an exchange which can
- /// be used to insert DHCPv4 or DHCPv6 option into dhcp4_options
- /// or dhcp6_options table.
- boost::shared_ptr<PgSqlOptionExchange> host_option_exchange_;
-
/// @brief PgSQL connection
PgSqlConnection conn_;
// Using fixed scope_id = 3, which associates an option with host.
{7,
{ OID_INT2, OID_BYTEA, OID_TEXT,
- OID_VARCHAR, OID_BOOL, OID_TEXT, OID_INT8},
+ OID_VARCHAR, OID_BOOL, OID_TEXT, OID_INT8 },
"insert_v4_host_option",
"INSERT INTO dhcp4_options(code, value, formatted_value, space, "
" persistent, user_context, host_id, scope_id) "
// Using fixed scope_id = 3, which associates an option with host.
{7,
{ OID_INT2, OID_BYTEA, OID_TEXT,
- OID_VARCHAR, OID_BOOL, OID_TEXT, OID_INT8},
+ OID_VARCHAR, OID_BOOL, OID_TEXT, OID_INT8 },
"insert_v6_host_option",
"INSERT INTO dhcp6_options(code, value, formatted_value, space, "
" persistent, user_context, host_id, scope_id) "
}
};
-}; // end anonymous namespace
+} // namespace
PgSqlHostDataSourceImpl::
-PgSqlHostDataSourceImpl(const PgSqlConnection::ParameterMap& parameters)
- : host_exchange_(new PgSqlHostWithOptionsExchange(PgSqlHostWithOptionsExchange::DHCP4_ONLY)),
- host_ipv6_exchange_(new PgSqlHostIPv6Exchange(PgSqlHostWithOptionsExchange::DHCP6_ONLY)),
- host_ipv46_exchange_(new PgSqlHostIPv6Exchange(PgSqlHostWithOptionsExchange::
- DHCP4_AND_DHCP6)),
- host_ipv6_reservation_exchange_(new PgSqlIPv6ReservationExchange()),
- host_option_exchange_(new PgSqlOptionExchange()),
- conn_(parameters),
+PgSqlHostDataSourceImpl(const PgSqlConnection::ParameterMap& parameters) :
+ conn_(parameters),
is_readonly_(false) {
// Open the database.
isc_throw(DbOpenError,
"PostgreSQL schema version mismatch: need version: "
<< code_version.first << "." << code_version.second
- << " found version: " << db_version.first << "."
+ << " found version: " << db_version.first << "."
<< db_version.second);
}
void
PgSqlHostDataSourceImpl::addResv(const IPv6Resrv& resv,
const HostID& id) {
+ thread_local std::shared_ptr<PgSqlIPv6ReservationExchange> host_ipv6_reservation_exchange(
+ std::make_shared<PgSqlIPv6ReservationExchange>());
+
PsqlBindArrayPtr bind_array;
- bind_array = host_ipv6_reservation_exchange_->createBindForSend(resv, id);
+ bind_array = host_ipv6_reservation_exchange->createBindForSend(resv, id);
+
addStatement(INSERT_V6_RESRV, bind_array);
}
const std::string& opt_space,
const Optional<SubnetID>&,
const HostID& id) {
+ thread_local std::shared_ptr<PgSqlOptionExchange> host_option_exchange(
+ std::make_shared<PgSqlOptionExchange>());
+
PsqlBindArrayPtr bind_array;
- bind_array = host_option_exchange_->createBindForSend(opt_desc, opt_space,
- id);
+ bind_array = host_option_exchange->createBindForSend(opt_desc, opt_space, id);
+
addStatement(stindex, bind_array);
}
void
PgSqlHostDataSourceImpl::
getHostCollection(StatementIndex stindex, PsqlBindArrayPtr bind_array,
- boost::shared_ptr<PgSqlHostExchange> exchange,
+ std::shared_ptr<PgSqlHostExchange> exchange,
ConstHostCollection& result, bool single) const {
exchange->clear();
const uint8_t* identifier_begin,
const size_t identifier_len,
StatementIndex stindex,
- boost::shared_ptr<PgSqlHostExchange> exchange) const {
+ std::shared_ptr<PgSqlHostExchange> exchange) const {
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
// Return single record if present, else clear the host.
ConstHostPtr result;
- if (!collection.empty())
+ if (!collection.empty()) {
result = *collection.begin();
+ }
return (result);
}
-std::pair<uint32_t, uint32_t> PgSqlHostDataSourceImpl::getVersion() const {
+pair<uint32_t, uint32_t>
+PgSqlHostDataSourceImpl::getVersion() const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_PGSQL_HOST_DB_GET_VERSION);
const char* version_sql = "SELECT version, minor FROM schema_version;";
<< version_sql << ">, reason: " << PQerrorMessage(conn_));
}
- uint32_t version;
- PgSqlExchange::getColumnValue(r, 0, 0, version);
+ uint32_t major;
+ PgSqlExchange::getColumnValue(r, 0, 0, major);
uint32_t minor;
PgSqlExchange::getColumnValue(r, 0, 1, minor);
- return (std::make_pair(version, minor));
+ return (make_pair(major, minor));
}
void
// If operating in read-only mode, throw exception.
impl_->checkReadOnly();
+ thread_local std::shared_ptr<PgSqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<PgSqlHostWithOptionsExchange>(PgSqlHostWithOptionsExchange::DHCP4_ONLY));
+
// Initiate PostgreSQL transaction as we will have to make multiple queries
// to insert host information into multiple tables. If that fails on
// any stage, the transaction will be rolled back by the destructor of
PgSqlTransaction transaction(impl_->conn_);
// Create the PgSQL Bind array for the host
- PsqlBindArrayPtr bind_array = impl_->host_exchange_->createBindForSend(host);
+ PsqlBindArrayPtr bind_array = host_ipv4_exchange->createBindForSend(host);
// ... and insert the host.
uint32_t host_id = impl_->addStatement(PgSqlHostDataSourceImpl::INSERT_HOST,
PgSqlHostDataSource::getAll(const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
const size_t identifier_len) const {
+ thread_local std::shared_ptr<PgSqlHostIPv6Exchange> host_ipv46_exchange(
+ std::make_shared<PgSqlHostIPv6Exchange>(PgSqlHostWithOptionsExchange::DHCP4_AND_DHCP6));
+
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection result;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_DHCPID,
- bind_array, impl_->host_ipv46_exchange_,
- result, false);
+ bind_array, host_ipv46_exchange, result, false);
return (result);
}
ConstHostCollection
PgSqlHostDataSource::getAll4(const SubnetID& subnet_id) const {
+ thread_local std::shared_ptr<PgSqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<PgSqlHostWithOptionsExchange>(PgSqlHostWithOptionsExchange::DHCP4_ONLY));
+
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection result;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_SUBID4,
- bind_array, impl_->host_exchange_,
- result, false);
+ bind_array, host_ipv4_exchange, result, false);
return (result);
}
ConstHostCollection
PgSqlHostDataSource::getAll6(const SubnetID& subnet_id) const {
+ thread_local std::shared_ptr<PgSqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<PgSqlHostIPv6Exchange>(PgSqlHostWithOptionsExchange::DHCP6_ONLY));
+
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection result;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_SUBID6,
- bind_array, impl_->host_ipv6_exchange_,
- result, false);
+ bind_array, host_ipv6_exchange, result, false);
return (result);
}
ConstHostCollection
PgSqlHostDataSource::getAllbyHostname(const std::string& hostname) const {
+ thread_local std::shared_ptr<PgSqlHostIPv6Exchange> host_ipv46_exchange(
+ std::make_shared<PgSqlHostIPv6Exchange>(PgSqlHostWithOptionsExchange::DHCP4_AND_DHCP6));
+
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection result;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_HOSTNAME,
- bind_array, impl_->host_ipv46_exchange_,
- result, false);
+ bind_array, host_ipv46_exchange, result, false);
+
return (result);
}
ConstHostCollection
PgSqlHostDataSource::getAllbyHostname4(const std::string& hostname,
const SubnetID& subnet_id) const {
+ thread_local std::shared_ptr<PgSqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<PgSqlHostWithOptionsExchange>(PgSqlHostWithOptionsExchange::DHCP4_ONLY));
+
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection result;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_HOSTNAME_SUBID4,
- bind_array, impl_->host_exchange_,
- result, false);
+ bind_array, host_ipv4_exchange, result, false);
return (result);
}
ConstHostCollection
PgSqlHostDataSource::getAllbyHostname6(const std::string& hostname,
const SubnetID& subnet_id) const {
+ thread_local std::shared_ptr<PgSqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<PgSqlHostIPv6Exchange>(PgSqlHostWithOptionsExchange::DHCP6_ONLY));
+
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection result;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_HOSTNAME_SUBID6,
- bind_array, impl_->host_ipv6_exchange_,
- result, false);
+ bind_array, host_ipv6_exchange, result, false);
return (result);
}
size_t& /*source_index*/,
uint64_t lower_host_id,
const HostPageSize& page_size) const {
+ thread_local std::shared_ptr<PgSqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<PgSqlHostWithOptionsExchange>(PgSqlHostWithOptionsExchange::DHCP4_ONLY));
+
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection result;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_SUBID4_PAGE,
- bind_array, impl_->host_exchange_,
- result, false);
+ bind_array, host_ipv4_exchange, result, false);
return (result);
}
size_t& /*source_index*/,
uint64_t lower_host_id,
const HostPageSize& page_size) const {
+ thread_local std::shared_ptr<PgSqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<PgSqlHostIPv6Exchange>(PgSqlHostWithOptionsExchange::DHCP6_ONLY));
+
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection result;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_SUBID6_PAGE,
- bind_array, impl_->host_ipv6_exchange_,
- result, false);
+ bind_array, host_ipv6_exchange, result, false);
return (result);
}
ConstHostCollection
PgSqlHostDataSource::getAll4(const asiolink::IOAddress& address) const {
+ thread_local std::shared_ptr<PgSqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<PgSqlHostWithOptionsExchange>(PgSqlHostWithOptionsExchange::DHCP4_ONLY));
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection result;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_ADDR, bind_array,
- impl_->host_exchange_, result, false);
+ host_ipv4_exchange, result, false);
return (result);
}
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
const size_t identifier_len) const {
+ thread_local std::shared_ptr<PgSqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<PgSqlHostWithOptionsExchange>(PgSqlHostWithOptionsExchange::DHCP4_ONLY));
return (impl_->getHost(subnet_id, identifier_type, identifier_begin,
identifier_len,
PgSqlHostDataSourceImpl::GET_HOST_SUBID4_DHCPID,
- impl_->host_exchange_));
+ host_ipv4_exchange));
}
ConstHostPtr
PgSqlHostDataSource::get4(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const {
if (!address.isV4()) {
- isc_throw(BadValue, "PgSqlHostDataSource::get4(id, address) - "
- " wrong address type, address supplied is an IPv6 address");
+ isc_throw(BadValue, "PgSqlHostDataSource::get4(id, address): "
+ "wrong address type, address supplied is an IPv6 address");
}
+ thread_local std::shared_ptr<PgSqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<PgSqlHostWithOptionsExchange>(PgSqlHostWithOptionsExchange::DHCP4_ONLY));
+
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection collection;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_SUBID_ADDR,
- bind_array, impl_->host_exchange_, collection,
- true);
+ bind_array, host_ipv4_exchange, collection, true);
// Return single record if present, else clear the host.
ConstHostPtr result;
- if (!collection.empty())
+ if (!collection.empty()) {
result = *collection.begin();
+ }
return (result);
}
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
const size_t identifier_len) const {
+ thread_local std::shared_ptr<PgSqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<PgSqlHostIPv6Exchange>(PgSqlHostWithOptionsExchange::DHCP6_ONLY));
return (impl_->getHost(subnet_id, identifier_type, identifier_begin,
identifier_len, PgSqlHostDataSourceImpl::GET_HOST_SUBID6_DHCPID,
- impl_->host_ipv6_exchange_));
+ host_ipv6_exchange));
}
ConstHostPtr
PgSqlHostDataSource::get6(const asiolink::IOAddress& prefix,
const uint8_t prefix_len) const {
- /// @todo: Check that prefix is v6 address, not v4.
+ if (!prefix.isV6()) {
+ isc_throw(BadValue, "PgSqlHostDataSource::get6(prefix, prefix_len): "
+ "wrong address type, address supplied is an IPv4 address");
+ }
+
+ thread_local std::shared_ptr<PgSqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<PgSqlHostIPv6Exchange>(PgSqlHostWithOptionsExchange::DHCP6_ONLY));
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection collection;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_PREFIX,
- bind_array, impl_->host_ipv6_exchange_,
- collection, true);
+ bind_array, host_ipv6_exchange, collection, true);
// Return single record if present, else clear the host.
ConstHostPtr result;
ConstHostPtr
PgSqlHostDataSource::get6(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const {
- /// @todo: Check that prefix is v6 address, not v4.
+ if (!address.isV6()) {
+ isc_throw(BadValue, "PgSqlHostDataSource::get6(id, address): "
+ "wrong address type, address supplied is an IPv4 address");
+ }
+
+ thread_local std::shared_ptr<PgSqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<PgSqlHostIPv6Exchange>(PgSqlHostWithOptionsExchange::DHCP6_ONLY));
// Set up the WHERE clause value
PsqlBindArrayPtr bind_array(new PsqlBindArray());
ConstHostCollection collection;
impl_->getHostCollection(PgSqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR,
- bind_array, impl_->host_ipv6_exchange_,
- collection, true);
+ bind_array, host_ipv6_exchange, collection, true);
// Return single record if present, else clear the host.
ConstHostPtr result;
// Miscellaneous database methods.
-std::string PgSqlHostDataSource::getName() const {
+std::string
+PgSqlHostDataSource::getName() const {
std::string name = "";
try {
name = impl_->conn_.getParameter("name");
return (name);
}
-std::string PgSqlHostDataSource::getDescription() const {
+std::string
+PgSqlHostDataSource::getDescription() const {
return (std::string("Host data source that stores host information"
"in PostgreSQL database"));
}
impl_->conn_.rollback();
}
-}; // end of isc::dhcp namespace
-}; // end of isc namespace
+} // namespace dhcp
+} // namespace isc
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, "
- "state, user_context "
+ "state, user_context "
"FROM lease4 "
"WHERE subnet_id = $1"},
"hwaddr = $13, hwtype = $14, hwaddr_source = $15, "
"state = $16, user_context = $17 "
"WHERE address = $18"},
+
// ALL_LEASE4_STATS
{ 0, { OID_NONE },
"all_lease4_stats",
{ 0, { OID_NONE },
"all_lease6_stats",
"SELECT subnet_id, lease_type, state, leases as state_count"
- " FROM lease6_stat ORDER BY subnet_id, lease_type, state" },
+ " FROM lease6_stat ORDER BY subnet_id, lease_type, state"},
// SUBNET_LEASE6_STATS
{ 1, { OID_INT8 },
"SELECT subnet_id, lease_type, state, leases as state_count"
" FROM lease6_stat "
" WHERE subnet_id = $1 "
- " ORDER BY lease_type, state" },
+ " ORDER BY lease_type, state"},
// SUBNET_RANGE_LEASE6_STATS
{ 2, { OID_INT8, OID_INT8 },
"SELECT subnet_id, lease_type, state, leases as state_count"
" FROM lease6_stat "
" WHERE subnet_id >= $1 and subnet_id <= $2 "
- " ORDER BY subnet_id, lease_type, state" },
+ " ORDER BY subnet_id, lease_type, state"},
+
// End of list sentinel
{ 0, { 0 }, NULL, NULL}
};
lease_ = lease;
try {
- addr_str_ = boost::lexical_cast<std::string>
- (lease->addr_.toUint32());
+ addr_str_ = boost::lexical_cast<std::string>(lease->addr_.toUint32());
bind_array.add(addr_str_);
if (lease->hwaddr_ && !lease->hwaddr_->hwaddr_.empty()) {
bool fetch_type_;
};
-PgSqlLeaseMgr::PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
- : LeaseMgr(), exchange4_(new PgSqlLease4Exchange()),
- exchange6_(new PgSqlLease6Exchange()), conn_(parameters) {
+PgSqlLeaseMgr::PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters) :
+ conn_(parameters) {
conn_.openDatabase();
// Validate schema version first.
// Now prepare the SQL statements.
int i = 0;
- for( ; tagged_statements[i].text != NULL ; ++i) {
+ for(; tagged_statements[i].text != NULL; ++i) {
conn_.prepareStatement(tagged_statements[i]);
}
bool
PgSqlLeaseMgr::addLease(const Lease4Ptr& lease) {
+ thread_local std::shared_ptr<PgSqlLease4Exchange> exchange4(
+ std::make_shared<PgSqlLease4Exchange>());
+
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_PGSQL_ADD_ADDR4).arg(lease->addr_.toText());
PsqlBindArray bind_array;
- exchange4_->createBindForSend(lease, bind_array);
+ exchange4->createBindForSend(lease, bind_array);
return (addLeaseCommon(INSERT_LEASE4, bind_array));
}
bool
PgSqlLeaseMgr::addLease(const Lease6Ptr& lease) {
+ thread_local std::shared_ptr<PgSqlLease6Exchange> exchange6(
+ std::make_shared<PgSqlLease6Exchange>());
+
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_PGSQL_ADD_ADDR6).arg(lease->addr_.toText());
PsqlBindArray bind_array;
- exchange6_->createBindForSend(lease, bind_array);
+ exchange6->createBindForSend(lease, bind_array);
return (addLeaseCommon(INSERT_LEASE6, bind_array));
}
}
}
+void
+PgSqlLeaseMgr::getLeaseCollection(StatementIndex stindex, db::PsqlBindArray& bind_array,
+ Lease4Collection& result) const {
+ thread_local std::shared_ptr<PgSqlLease4Exchange> exchange4(
+ std::make_shared<PgSqlLease4Exchange>());
+
+ getLeaseCollection(stindex, bind_array, exchange4, result);
+}
+
+void
+PgSqlLeaseMgr::getLeaseCollection(StatementIndex stindex, db::PsqlBindArray& bind_array,
+ Lease6Collection& result) const {
+ thread_local std::shared_ptr<PgSqlLease6Exchange> exchange6(
+ std::make_shared<PgSqlLease6Exchange>());
+
+ getLeaseCollection(stindex, bind_array, exchange6, result);
+}
+
void
PgSqlLeaseMgr::getLease(StatementIndex stindex, PsqlBindArray& bind_array,
- Lease4Ptr& result) const {
+ Lease4Ptr& result) const {
+ thread_local std::shared_ptr<PgSqlLease4Exchange> exchange4(
+ std::make_shared<PgSqlLease4Exchange>());
+
// Create appropriate collection object and get all leases matching
// the selection criteria. The "single" parameter is true to indicate
// that the called method should throw an exception if multiple
// matching records are found: this particular method is called when only
// one or zero matches is expected.
Lease4Collection collection;
- getLeaseCollection(stindex, bind_array, exchange4_, collection, true);
+ getLeaseCollection(stindex, bind_array, exchange4, collection, true);
// Return single record if present, else clear the lease.
if (collection.empty()) {
void
PgSqlLeaseMgr::getLease(StatementIndex stindex, PsqlBindArray& bind_array,
- Lease6Ptr& result) const {
+ Lease6Ptr& result) const {
+ thread_local std::shared_ptr<PgSqlLease6Exchange> exchange6(
+ std::make_shared<PgSqlLease6Exchange>());
+
// Create appropriate collection object and get all leases matching
// the selection criteria. The "single" parameter is true to indicate
// that the called method should throw an exception if multiple
// matching records are found: this particular method is called when only
// one or zero matches is expected.
Lease6Collection collection;
- getLeaseCollection(stindex, bind_array, exchange6_, collection, true);
+ getLeaseCollection(stindex, bind_array, exchange6, collection, true);
// Return single record if present, else clear the lease.
if (collection.empty()) {
PsqlBindArray bind_array;
// LEASE ADDRESS
- std::string addr_str = boost::lexical_cast<std::string>
- (addr.toUint32());
+ std::string addr_str = boost::lexical_cast<std::string>(addr.toUint32());
bind_array.add(addr_str);
// Get the data
void
PgSqlLeaseMgr::updateLease4(const Lease4Ptr& lease) {
+ thread_local std::shared_ptr<PgSqlLease4Exchange> exchange4(
+ std::make_shared<PgSqlLease4Exchange>());
+
const StatementIndex stindex = UPDATE_LEASE4;
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
// Create the BIND array for the data being updated
PsqlBindArray bind_array;
- exchange4_->createBindForSend(lease, bind_array);
+ exchange4->createBindForSend(lease, bind_array);
// Set up the WHERE clause and append it to the SQL_BIND array
- std::string addr4_ = boost::lexical_cast<std::string>
- (lease->addr_.toUint32());
- bind_array.add(addr4_);
+ std::string addr_str = boost::lexical_cast<std::string>(lease->addr_.toUint32());
+ bind_array.add(addr_str);
// Drop to common update code
updateLeaseCommon(stindex, bind_array, lease);
void
PgSqlLeaseMgr::updateLease6(const Lease6Ptr& lease) {
+ thread_local std::shared_ptr<PgSqlLease6Exchange> exchange6(
+ std::make_shared<PgSqlLease6Exchange>());
+
const StatementIndex stindex = UPDATE_LEASE6;
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
// Create the BIND array for the data being updated
PsqlBindArray bind_array;
- exchange6_->createBindForSend(lease, bind_array);
+ exchange6->createBindForSend(lease, bind_array);
// Set up the WHERE clause and append it to the BIND array
std::string addr_str = lease->addr_.toText();
<< version_sql << ", reason: " << PQerrorMessage(conn_));
}
- istringstream tmp;
- uint32_t version;
- tmp.str(PQgetvalue(r, 0, 0));
- tmp >> version;
- tmp.str("");
- tmp.clear();
+ uint32_t major;
+ PgSqlExchange::getColumnValue(r, 0, 0, major);
uint32_t minor;
- tmp.str(PQgetvalue(r, 0, 1));
- tmp >> minor;
+ PgSqlExchange::getColumnValue(r, 0, 1, minor);
- return (make_pair(version, minor));
+ return (make_pair(major, minor));
}
void
conn_.rollback();
}
-}; // end of isc::dhcp namespace
-}; // end of isc namespace
+} // namespace dhcp
+} // namespace isc