Version: 1.0.0
tds_database.h
Go to the documentation of this file.
1 #ifndef _WX_DATABASE_TDS_DATABASE_H_
2 #define _WX_DATABASE_TDS_DATABASE_H_
3 
4 #include "wx/database/wxprec.h"
5 
7 class wxTdsDatabase;
8 
9 WX_DECLARE_HASH_MAP(TDSCONTEXT*, wxTdsDatabase*, wxPointerHash, wxPointerEqual, TdsContextToDatabaseLayerMap);
10 
12 {
13 public:
14  // ctor()
15  wxTdsDatabase();
16  wxTdsDatabase(const wxString& strFreeTDS, const wxString& strServer, const wxString& strDatabase, const wxString& strUser, const wxString& strPassword, int nTdsVersion = TDS_80);
17 
18  // dtor()
19  virtual ~wxTdsDatabase();
20 
21  // open database
22  virtual bool Open(const wxString& strDatabase);
23 
24  bool Connect();
25 
26  // close database
27  virtual bool Close();
28 
29  // Is the connection to the database open?
30  virtual bool IsOpen();
31 
32  // transaction support
33  virtual void BeginTransaction();
34  virtual void Commit();
35  virtual void RollBack();
36 
37  // query database
38  virtual int RunQuery(const wxString& strQuery, bool bParseQuery);
39  virtual wxDatabaseResultSet* RunQueryWithResults(const wxString& strQuery);
40 
41  // wxPreparedStatement support
42  virtual wxPreparedStatement* PrepareStatement(const wxString& strQuery);
43 
44  void SetFreeTDS(const wxString& strFreeTDS) { m_strFreeTDS = strFreeTDS; }
45  void SetServer(const wxString& strServer) { m_strServer = strServer; }
46  void SetDatabase(const wxString& strDatabase) { m_strDatabase = strDatabase; }
47  void SetLogin(const wxString& strLogin) { m_strLogin = strLogin; }
48  void SetPassword(const wxString& strPassword) { m_strPassword = strPassword; }
49  void SetTdsVersion(int nTdsVersion) { m_nTdsVersion = nTdsVersion; }
50 
51  enum
52  {
53  TDS_42 = 0,
57  //AML start
62  //AML end
63  TDS_80
64  };
65 
66  // Database schema API contributed by M. Szeftel (author of wxActiveRecordGenerator)
67  virtual bool TableExists(const wxString& table);
68  virtual bool ViewExists(const wxString& view);
69  virtual wxArrayString GetTables();
70  virtual wxArrayString GetViews();
71  virtual wxArrayString GetColumns(const wxString& table);
72  virtual wxArrayString GetPKColumns(const wxString& table);
73 
74  static wxTdsDatabase* LookupTdsLayer(const TDSCONTEXT* pContext);
75  void SetError(int nCode, const wxString& strMessage);
76 
77  //AML start
78  typedef struct
79  {
80  TDS_TINYINT has;
81  TDS_INT ret;
82  } status_t;
83  //AML end
84 private:
85  static int TranslateErrorCode(int nCode);
86  void FreeAllocatedResultSets(/*AML start*/status_t* status = NULL/*AML end*/);
87  static void AddTdsLayer(TDSCONTEXT* pContext, wxTdsDatabase* pLayer);
88  static void RemoveTdsLayer(TDSCONTEXT* pContext);
89 
90  TDSPARAMINFO* GetParameters(const wxString& strQuery);
91 
92  // Map of TDSCONTEXT* to wxTdsDatabase* to be used by the error handler
93  static TdsContextToDatabaseLayerMap m_ContextLookupMap;
94 
95  wxString m_strFreeTDS;
96  wxString m_strServer;
97  wxString m_strDatabase;
98  wxString m_strLogin;
99  wxString m_strPassword;
101 
102  TDSSOCKET* m_pDatabase;
103  TDSLOGIN* m_pLogin;
104  TDSCONTEXT* m_pContext;
105 };
106 
107 #endif//_WX_DATABASE_TDS_DATABASE_H_
108 
virtual wxArrayString GetPKColumns(const wxString &table)=0
get Primary keys column names
virtual wxArrayString GetViews()=0
Retrieve all view names.
WX_DECLARE_HASH_MAP(TDSCONTEXT *, wxTdsDatabase *, wxPointerHash, wxPointerEqual, TdsContextToDatabaseLayerMap)
wxString m_strFreeTDS
Definition: tds_database.h:95
wxString m_strDatabase
Definition: tds_database.h:97
void SetServer(const wxString &strServer)
Definition: tds_database.h:45
TDSLOGIN * m_pLogin
Definition: tds_database.h:103
TDSSOCKET * m_pDatabase
Definition: tds_database.h:102
virtual wxPreparedStatement * PrepareStatement(const wxString &strQuery)=0
Prepare a SQL statement which can be reused with different parameters.
void SetFreeTDS(const wxString &strFreeTDS)
Definition: tds_database.h:44
virtual void RollBack()=0
Rollback the current transaction.
void SetDatabase(const wxString &strDatabase)
Definition: tds_database.h:46
virtual bool IsOpen()=0
Is the connection to the database open?
wxString m_strPassword
Definition: tds_database.h:99
wxString m_strLogin
Definition: tds_database.h:98
void SetTdsVersion(int nTdsVersion)
Definition: tds_database.h:49
virtual int RunQuery(const wxString &strQuery)
Run an insert, update, or delete query on the database.
Definition: database.cpp:19
virtual void BeginTransaction()=0
Begin a transaction.
virtual bool Open(const wxString &strDatabase)=0
virtual bool ViewExists(const wxString &view)=0
Check for the existence of a view by name.
static TdsContextToDatabaseLayerMap m_ContextLookupMap
Definition: tds_database.h:93
virtual void Commit()=0
Commit the current transaction.
wxString m_strServer
Definition: tds_database.h:96
virtual wxArrayString GetColumns(const wxString &table)=0
Retrieve all column names for a table.
void SetLogin(const wxString &strLogin)
Definition: tds_database.h:47
TDSCONTEXT * m_pContext
Definition: tds_database.h:104
virtual bool Close()=0
close database
virtual bool TableExists(const wxString &table)=0
Check for the existence of a table by name.
#define WXDLLIMPEXP_DATABASE
void SetPassword(const wxString &strPassword)
Definition: tds_database.h:48
virtual wxArrayString GetTables()=0
Retrieve all table names.
virtual wxDatabaseResultSet * RunQueryWithResults(const wxString &strQuery)=0
Run a select query on the database.