summaryrefslogtreecommitdiff
path: root/libodb-mssql/odb/mssql/auto-handle.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2024-02-01 18:10:29 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2024-02-01 18:10:29 +0300
commit2895ad78dbdb43e57fc34558b4530b4e105fc72d (patch)
tree9a176c9a1a34cfa9df60fcf482bc6c360ae11214 /libodb-mssql/odb/mssql/auto-handle.hxx
parent8ac5c705c360b9ccde527eea24ddc90b2f6ed7ec (diff)
Turn libodb-mssql repository into package for muti-package repositorylibodb-mssql
Diffstat (limited to 'libodb-mssql/odb/mssql/auto-handle.hxx')
-rw-r--r--libodb-mssql/odb/mssql/auto-handle.hxx88
1 files changed, 88 insertions, 0 deletions
diff --git a/libodb-mssql/odb/mssql/auto-handle.hxx b/libodb-mssql/odb/mssql/auto-handle.hxx
new file mode 100644
index 0000000..f6934e4
--- /dev/null
+++ b/libodb-mssql/odb/mssql/auto-handle.hxx
@@ -0,0 +1,88 @@
+// file : odb/mssql/auto-handle.hxx
+// license : ODB NCUEL; see accompanying LICENSE file
+
+#ifndef ODB_MSSQL_AUTO_HANDLE_HXX
+#define ODB_MSSQL_AUTO_HANDLE_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/details/config.hxx> // ODB_CXX11
+
+#include <odb/mssql/mssql-fwd.hxx>
+#include <odb/mssql/version.hxx>
+
+#include <odb/mssql/details/export.hxx>
+
+namespace odb
+{
+ namespace mssql
+ {
+ LIBODB_MSSQL_EXPORT void
+ free_handle (SQLHANDLE, SQLSMALLINT htype);
+
+ template <SQLSMALLINT htype>
+ class auto_handle
+ {
+ public:
+ auto_handle (SQLHANDLE h = 0)
+ : h_ (h)
+ {
+ }
+
+ ~auto_handle ()
+ {
+ if (h_ != 0)
+ free_handle (h_, htype);
+ }
+
+ operator SQLHANDLE () const
+ {
+ return h_;
+ }
+
+ SQLHANDLE
+ get () const
+ {
+ return h_;
+ }
+
+ SQLHANDLE
+ release ()
+ {
+ SQLHANDLE h (h_);
+ h_ = 0;
+ return h;
+ }
+
+ void
+ reset (SQLHANDLE h = 0)
+ {
+ if (h_ != 0)
+ free_handle (h_, htype);
+
+ h_ = h;
+ }
+
+#ifdef ODB_CXX11
+ auto_handle (auto_handle&& ah) noexcept: h_ (ah.release ()) {}
+ auto_handle& operator= (auto_handle&& ah) noexcept
+ {
+ if (this != &ah)
+ reset (ah.release ());
+ return *this;
+ }
+#endif
+
+ private:
+ auto_handle (const auto_handle&);
+ auto_handle& operator= (const auto_handle&);
+
+ private:
+ SQLHANDLE h_;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_MSSQL_AUTO_HANDLE_HXX