return checkLimits(user_context, CHECK_LEASE6_LIMITS);
}
+bool
+MySqlLeaseMgr::isJsonSupported() const {
+ // Get a context.
+ MySqlLeaseContextAlloc get_context(*this);
+ MySqlLeaseContextPtr ctx = get_context.ctx_;
+
+ // Create bindings.
+ MySqlBindingCollection in_bindings;
+ MySqlBindingCollection out_bindings({
+ MySqlBinding::createBool()
+ });
+
+ // Execute the select.
+ bool json_supported(false);
+ ctx->conn_.selectQuery(IS_JSON_SUPPORTED, in_bindings, out_bindings,
+ [&json_supported] (MySqlBindingCollection const& result) {
+ json_supported = result[0]->getBool();
+ });
+
+ return json_supported;
+}
+
LeaseStatsQueryPtr
MySqlLeaseMgr::startLeaseStatsQuery4() {
// Get a context
isc_throw(NotImplemented, "wipeLeases6 is not implemented for MySQL backend");
}
-bool
-MySqlLeaseMgr::isJsonSupported() const {
- // Get a context.
- MySqlLeaseContextAlloc get_context(*this);
- MySqlLeaseContextPtr ctx = get_context.ctx_;
-
- // Create bindings.
- MySqlBindingCollection in_bindings;
- MySqlBindingCollection out_bindings({
- MySqlBinding::createBool()
- });
-
- // Execute the select.
- bool json_supported(false);
- ctx->conn_.selectQuery(IS_JSON_SUPPORTED, in_bindings, out_bindings,
- [&json_supported] (MySqlBindingCollection const& result) {
- json_supported = result[0]->getBool();
- });
-
- return json_supported;
-}
-
// Miscellaneous database methods.
std::string
/// @return number of leases removed.
virtual size_t wipeLeases6(const SubnetID& subnet_id) override;
- /// @brief Checks if JSON support is enabled in the database.
- /// MySQL implementation.
- ///
- /// @return true if there is JSON support, false otherwise
- virtual bool isJsonSupported() const override;
-
/// @brief Return backend type
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
virtual std::string
checkLimits6(isc::data::ConstElementPtr const& user_context) const override;
+ /// @brief Checks if JSON support is enabled in the database.
+ /// MySQL implementation.
+ ///
+ /// @return true if there is JSON support, false otherwise
+ bool isJsonSupported() const override;
+
/// @brief Check Error and Throw Exception
///
/// This method invokes @ref MySqlConnection::checkError.
" WHERE subnet_id >= $1 and subnet_id <= $2 "
" ORDER BY subnet_id, lease_type, state" },
- // TODO: remove single quotes from the following two SELECTs when the functions are implemented
-
// CHECK_LEASE4_LIMITS
{ 1, { OID_TEXT },
"check_lease4_limits",
- "SELECT 'checkLease4Limits($1)'" },
+ "SELECT checkLease4Limits($1)" },
// CHECK_LEASE6_LIMITS
{ 1, { OID_TEXT },
"check_lease6_limits",
- "SELECT 'checkLease6Limits($1)'" },
+ "SELECT checkLease6Limits($1)" },
+
+ // IS_JSON_SUPPORTED
+ { 0, { OID_NONE },
+ "is_json_supported",
+ "SELECT isJsonSupported()" },
// End of list sentinel
{ 0, { 0 }, NULL, NULL}
string
PgSqlLeaseMgr::checkLimits(ConstElementPtr const& user_context, StatementIndex const stindex) const {
- // Bindings
- PsqlBindArray bind_array;
- std::string const user_context_str(user_context->str());
- bind_array.add(user_context_str);
+ // No user context means no limits means allocation allowed means empty string.
+ if (!user_context) {
+ return string();
+ }
// Get a context.
PgSqlLeaseContextAlloc get_context(*this);
PgSqlLeaseContextPtr ctx(get_context.ctx_);
+ // Create bindings.
+ PsqlBindArray bind_array;
+ std::string const user_context_str(user_context->str());
+ bind_array.add(user_context_str);
+
+ // Execute the select.
PgSqlResult r(PQexecPrepared(ctx->conn_,
tagged_statements[stindex].name,
tagged_statements[stindex].nbparams,
&bind_array.values_[0],
&bind_array.lengths_[0],
&bind_array.formats_[0], 0));
-
ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
- int rows = PQntuples(r);
- if (rows > 1) {
- isc_throw(MultipleRecords, "multiple records were found in the "
- "database where only one was expected for query "
- << tagged_statements[stindex].name);
- }
-
std::string const limits(PgSqlExchange::getRawColumnValue(r, 0, 0));
return limits;
}
return checkLimits(user_context, CHECK_LEASE6_LIMITS);
}
+bool
+PgSqlLeaseMgr::isJsonSupported() const {
+ // Get a context.
+ PgSqlLeaseContextAlloc get_context(*this);
+ PgSqlLeaseContextPtr ctx(get_context.ctx_);
+
+ // Execute the select.
+ StatementIndex const stindex(IS_JSON_SUPPORTED);
+ PgSqlResult r(PQexecPrepared(ctx->conn_, tagged_statements[stindex].name,
+ 0, 0, 0, 0, 0));
+ ctx->conn_.checkStatementError(r, tagged_statements[stindex]);
+
+ bool const json_supported(PgSqlExchange::getRawColumnValue(r, 0, 0));
+ return json_supported;
+}
+
LeaseStatsQueryPtr
PgSqlLeaseMgr::startLeaseStatsQuery4() {
// Get a context
isc_throw(NotImplemented, "wipeLeases6 is not implemented for PostgreSQL backend");
}
-bool
-PgSqlLeaseMgr::isJsonSupported() const {
- isc_throw(NotImplemented, "PgSqlLeaseMgr::isJsonSupported() not implemented");
-}
-
std::string
PgSqlLeaseMgr::getName() const {
// Get a context
/// @return number of leases removed.
virtual size_t wipeLeases6(const SubnetID& subnet_id) override;
- /// @brief Checks if JSON support is enabled in the database.
- /// PostgreSQL implementation.
- ///
- /// @return true if there is JSON support, false otherwise
- virtual bool isJsonSupported() const override;
-
/// @brief Return backend type
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
SUBNET_RANGE_LEASE6_STATS, // Fetched IPv6 lease stats for a subnet range.
CHECK_LEASE4_LIMITS, // Check if allocated IPv4 leases are inside the set limits.
CHECK_LEASE6_LIMITS, // Check if allocated IPv6 leases are inside the set limits.
+ IS_JSON_SUPPORTED, // Checks if JSON support is enabled in the database.
NUM_STATEMENTS // Number of statements
};
virtual std::string
checkLimits6(isc::data::ConstElementPtr const& user_context) const override;
+ /// @brief Checks if JSON support is enabled in the database.
+ /// PostgreSQL implementation.
+ ///
+ /// @return true if there is JSON support, false otherwise
+ bool isJsonSupported() const override;
+
/// @brief Context RAII Allocator.
class PgSqlLeaseContextAlloc {
public: