soci-autostatement.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // Copyright (C) 2020 Vadim Zeitlin
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef SOCI_PRIVATE_SOCI_AUTOSTATEMENT_H_INCLUDED
  8. #define SOCI_PRIVATE_SOCI_AUTOSTATEMENT_H_INCLUDED
  9. namespace soci
  10. {
  11. namespace details
  12. {
  13. // This helper class can be used with any statement backend to initialize and
  14. // cleanup a statement backend object in a RAII way. Normally this is not
  15. // needed because it's done by statement_impl, but this can be handy when using
  16. // a concrete backend inside this backend own code, see e.g. ODBC session
  17. // implementation.
  18. template <typename Backend>
  19. struct auto_statement : Backend
  20. {
  21. template <typename Session>
  22. explicit auto_statement(Session& session)
  23. : Backend(session)
  24. {
  25. this->alloc();
  26. }
  27. ~auto_statement() override
  28. {
  29. this->clean_up();
  30. }
  31. };
  32. } // namespace details
  33. } // namespace soci
  34. #endif // SOCI_PRIVATE_SOCI_AUTOSTATEMENT_H_INCLUDED