diff options
-rw-r--r-- | odb/mssql/auto-handle.cxx | 19 | ||||
-rw-r--r-- | odb/mssql/auto-handle.hxx | 78 | ||||
-rw-r--r-- | odb/mssql/makefile | 1 | ||||
-rw-r--r-- | odb/mssql/mssql-fwd.hxx | 9 |
4 files changed, 105 insertions, 2 deletions
diff --git a/odb/mssql/auto-handle.cxx b/odb/mssql/auto-handle.cxx new file mode 100644 index 0000000..733ec92 --- /dev/null +++ b/odb/mssql/auto-handle.cxx @@ -0,0 +1,19 @@ +// file : odb/mssql/auto-handle.cxx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#include <odb/mssql/odbc.hxx> +#include <odb/mssql/auto-handle.hxx> + +namespace odb +{ + namespace mssql + { + void + free_handle (SQLHANDLE h, SQLSMALLINT htype) + { + SQLFreeHandle (htype, h); + } + } +} diff --git a/odb/mssql/auto-handle.hxx b/odb/mssql/auto-handle.hxx new file mode 100644 index 0000000..d545629 --- /dev/null +++ b/odb/mssql/auto-handle.hxx @@ -0,0 +1,78 @@ +// file : odb/mssql/auto-handle.hxx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// 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/mssql/version.hxx> +#include <odb/mssql/mssql-fwd.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; + } + + 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 diff --git a/odb/mssql/makefile b/odb/mssql/makefile index 98749c1..00342f1 100644 --- a/odb/mssql/makefile +++ b/odb/mssql/makefile @@ -7,6 +7,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make cxx := \ +auto-handle.cxx \ exceptions.cxx diff --git a/odb/mssql/mssql-fwd.hxx b/odb/mssql/mssql-fwd.hxx index 434edb1..403e2a8 100644 --- a/odb/mssql/mssql-fwd.hxx +++ b/odb/mssql/mssql-fwd.hxx @@ -13,10 +13,15 @@ // in public headers. // #ifdef _WIN32 -typedef long SQLINTEGER; -typedef unsigned long SQLUINTEGER; +typedef long SQLINTEGER; +typedef unsigned long SQLUINTEGER; #endif +typedef short SQLSMALLINT; +typedef unsigned short SQLUSMALLINT; + +typedef void* SQLHANDLE; + #include <odb/post.hxx> #endif // ODB_MSSQL_MSSQL_FWD_HXX |