Connection.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace AppSecInc
4 {
5  namespace Databases
6  {
7  namespace ODBC
8  {
10  {
14  ODBC_CONNECTION_RPC, // multi-protocol
15  ODBC_CONNECTION_LPC, // shared memory
16  ODBC_CONNECTION_SPX, // nwlink ipx/spx
17  ODBC_CONNECTION_VINES, // Banyan VINES
18  ODBC_CONNECTION_ADSP // Apple Talk
19  };
20 
21  // Bit flags controlling behaviour of Get-methods:
23  const WORD ODBC_SQL_FLAG_NO_ROWS_RETURN_EMPTY = 0x0001;
24 
25 
28  {
29  protected:
31  SQLHDBC _hconnection;
33  SQLHENV _henvironment;
35  BOOL _connected;
36  public:
38  virtual ~ODBCConnection();
40  void Initialize();
42  void Terminate();
44  void Connect(const ODBCConnectionInfo& connection_info);
46  void Disconnect();
48  std::wstring GetError() const { return ODBCHandle::GetError(_hconnection, SQL_HANDLE_DBC); }
50  std::vector<ODBCError> GetErrors() const { return ODBCHandle::GetErrors(_hconnection, SQL_HANDLE_DBC); }
52  operator SQLHDBC() const { return _hconnection; }
54  BOOL IsConnected() const { return _connected; }
56  SQLHENV GetEnvironmentHandle() const { return _henvironment; }
58  long GetScalar(const std::wstring& query) const;
59  long GetScalar(const std::wstring& query, ODBCHandle& stmt) const;
61  std::wstring GetXml(const std::wstring& query) const;
63  MSXML2::IXMLDOMNodePtr GetXml(const std::wstring& query, AppSecInc::Xml::XmlDocument& xmldoc, MSXML2::IXMLDOMNodePtr parent_node = NULL) const;
65  void InsertXml(const AppSecInc::Xml::XmlDocument& xmldatadoc);
67  void InsertXml(const AppSecInc::Xml::XmlDocument& xmldatadoc, AppSecInc::Xml::XmlDocument& xmldoc, MSXML2::IXMLDOMNodePtr parent_node);
69  void InsertXml(const AppSecInc::Xml::XmlDocument& xmldatadoc, MSXML2::IXMLDOMNodePtr result_node, AppSecInc::Xml::XmlDocument& xmldoc, MSXML2::IXMLDOMNodePtr parent_node);
71  std::string GetString(const std::wstring& query, WORD flags = 0) const;
73  std::string GetString(const std::wstring& query, ODBCHandle& stmt, WORD flags = 0) const;
75  std::wstring GetWString(const std::wstring& query, WORD flags = 0) const;
77  std::wstring GetWString(const std::wstring& query, ODBCHandle& stmt, WORD flags = 0) const;
79  void Execute(const std::wstring& query) const;
80  void Execute(const std::wstring& query, ODBCHandle&) const;
82  void Execute(const std::wstring& query, ODBCRowSet&) const;
84  void Execute(const std::wstring& query, ODBCParameters&) const;
86  void Execute(const std::wstring& query, ODBCParameters&, ODBCRowSet&) const;
87  };
88  }
89  }
90 }
91 
92 
93 
94 
95 
96 
97 
98 
void Terminate()
terminate the ODBC environment, succeeds if Initialize has not been called
Definition: Connection.cpp:47
SQLHDBC _hconnection
ODBC connection handle.
Definition: Connection.h:31
ODBCConnection()
Definition: Connection.cpp:8
long GetScalar(const std::wstring &query) const
Return a scalar result from a query (eg. a count)
Definition: Connection.cpp:106
void Initialize()
initialize the ODBC environment at ODBC version 3.0, fails if previously initialized ...
Definition: Connection.cpp:29
BOOL IsConnected() const
returns true if connected
Definition: Connection.h:54
std::string GetString(const std::wstring &query, WORD flags=0) const
Return a string result from a query.
Definition: Connection.cpp:130
std::vector< ODBCError > GetErrors() const
get an array of errors on the current ODBC handle
Definition: Handle.h:65
std::wstring GetError() const
get the text representation of the errors on an ODBC handle
Definition: Handle.h:63
std::wstring GetXml(const std::wstring &query) const
Return the data set from a query in xml format.
Definition: Connection.cpp:301
An ODBC rowset.
Definition: RowSet.h:10
std::vector< ODBCError > GetErrors() const
get an array of errors on the current ODBC connection
Definition: Connection.h:50
A generic connection info.
Definition: ConnectionInfo.h:10
An ODBC handle (smart pointer), bound to a connection.
Definition: Handle.h:31
An MSXML document.
Definition: XmlDocument.h:8
virtual ~ODBCConnection()
Definition: Connection.cpp:16
void InsertXml(const AppSecInc::Xml::XmlDocument &xmldatadoc)
Insert data from xml.
Definition: Connection.cpp:352
void Execute(const std::wstring &query) const
Execute a statement.
Definition: Connection.cpp:227
BOOL _connected
successful initialization and connection flag
Definition: Connection.h:35
SQLHENV _henvironment
ODBC environment.
Definition: Connection.h:33
SQLHENV GetEnvironmentHandle() const
returns the environment handle
Definition: Connection.h:56
An ODBC parameters.
Definition: Parameters.h:10
const WORD ODBC_SQL_FLAG_NO_ROWS_RETURN_EMPTY
In GetString don&#39;t consider empty rowset as error, return empty string instead.
Definition: Connection.h:23
An ODBC connection.
Definition: Connection.h:27
void Connect(const ODBCConnectionInfo &connection_info)
connect to a host, fails if already connected
Definition: Connection.cpp:62
std::wstring GetWString(const std::wstring &query, WORD flags=0) const
Return a string result from a query.
Definition: Connection.cpp:174
ODBCConnectionProtocol
Definition: Connection.h:9
void Disconnect()
disconnect from a host, fails if not connected
Definition: Connection.cpp:96
std::wstring GetError() const
get the text representation of the errors on an ODBC connection handle
Definition: Connection.h:48


© Application Security Inc. - All Rights Reserved http://msiext.codeplex.com