Version: 1.0.0
dbconf.h
Go to the documentation of this file.
1 #ifndef _WX_MLBASE_DBLCONF_H_
2 #define _WX_MLBASE_DBLCONF_H_
3 
4 #include "wx/base/wxprec.h"
5 
6 #include <wx/fileconf.h>
7 #ifdef wxUSE_STREAMS
8 #include <wx/stream.h>
9 #endif
10 
11 // std::
12 #include <vector>
13 
14 class WXDLLIMPEXP_MLBASE wxDatabaseConfig : public wxConfigBase
15 {
16 public:
18  (
19  const wxString& appName = wxEmptyString,
20  const wxString& vendorName = wxEmptyString,
21  const wxString& viewName = wxEmptyString,
22  const wxString& settingsConf = wxEmptyString,
23  long style = 0,
24  const wxMBConv &conv = wxConvAuto()
25  );
26 #ifdef wxUSE_STREAMS
28  (
29  wxInputStream& inStream,
30  const wxString& viewName = wxEmptyString,
31  const wxMBConv &conv = wxConvAuto()
32  );
33 #endif
34 
35  virtual ~wxDatabaseConfig();
36 
37  virtual void SetPath(const wxString& strPath);
38  virtual const wxString& GetPath() const { return m_entry.path; }
39 
40  virtual bool GetFirstGroup(wxString& str, long& lIndex) const;
41  virtual bool GetNextGroup(wxString& str, long& lIndex) const;
42  virtual bool GetFirstEntry(wxString& str, long& lIndex) const;
43  virtual bool GetNextEntry(wxString& str, long& lIndex) const;
44 
45  virtual size_t GetNumberOfEntries(bool bRecursive = false) const;
46  virtual size_t GetNumberOfGroups(bool bRecursive = false) const;
47 
48  virtual bool HasGroup(const wxString& strName) const;
49  virtual bool HasEntry(const wxString& strName) const;
50 
51  virtual bool Flush(bool bCurrentOnly = false);
52 
53  virtual bool RenameEntry(const wxString& oldName, const wxString& newName);
54  virtual bool RenameGroup(const wxString& oldName, const wxString& newName);
55 
56  virtual bool DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso = true);
57  virtual bool DeleteGroup(const wxString& key);
58  virtual bool DeleteAll();
59 
60 protected:
61  virtual bool DoReadString(const wxString& key, wxString* pStr) const;
62  virtual bool DoReadLong(const wxString& key, long* pl) const;
63 
64  virtual bool DoWriteString(const wxString& key, const wxString& szValue);
65  virtual bool DoWriteLong(const wxString& key, long lValue);
66 #if wxCHECK_VERSION(2,9,0) && wxUSE_BASE64
67  virtual bool DoReadBinary(const wxString& key, wxMemoryBuffer* buf) const;
68  virtual bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf);
69 #endif
70 
71 private:
72  typedef struct
73  {
74  long id;
75  wxString name;
76  wxString value;
77  wxString path;
78  bool isgroup;
79  } dbentry;
80  typedef std::vector<dbentry> dbentries;
81 
83 
84  void CleanUp();
85 
86 #ifdef wxUSE_STREAMS
87  bool LoadStream(wxInputStream& inStream, wxString* err = NULL);
88 #endif
89 
95 
97 
98  wxPreparedStatement* PrepareStatement(const wxString& strQuery);
99  wxPreparedStatement* ExecuteStatement(wxPreparedStatement* pStatement, dbentries* pEntries = NULL);
100 
101  void DatabaseErrorCheck(wxDatabaseErrorReporter* reporter);
102  void ProcessException(wxDatabaseException& e, bool fail = true);
103 
104  void SetRootPath(dbentry& entry);
105 
106  bool FindEntries(const wxString& nameORpath, dbentries& entries);
107  bool AddEntry(dbentry& parent, const wxString& name, const wxString* value = NULL);
108  bool WriteEntry(dbentry& entry, const wxString& name, const wxString& value);
109 
111  wxString m_viewName;
112  wxString m_settingsConf;
113 
114  void GetChildren(dbentry& parent, dbentries* groups = NULL, dbentries* entries = NULL, bool recursive = false);
115 
116  // following used to optimise/cache calls to Get[First|Next][Entry|Group]
119 
120  wxDECLARE_NO_COPY_CLASS(wxDatabaseConfig);
121  wxDECLARE_ABSTRACT_CLASS(wxDatabaseConfig);
122 };
123 
124 #endif//_WX_MLBASE_DBLCONF_H_
wxPreparedStatement * m_pStatementSqlDelEntry
Definition: dbconf.h:92
dbentries m_groups
Definition: dbconf.h:117
wxPreparedStatement * m_pStatementSqlDropAll
Definition: dbconf.h:96
wxPreparedStatement * m_pStatementSqlEditEntry
Definition: dbconf.h:93
dbentries m_entries
Definition: dbconf.h:118
wxDatabase * m_pDatabase
Definition: dbconf.h:90
wxString m_viewName
Definition: dbconf.h:111
dbentry m_entry
Definition: dbconf.h:110
#define WXDLLIMPEXP_MLBASE
Definition: base/dlimpexp.h:21
wxPreparedStatement * m_pStatementSqlAddEntry
Definition: dbconf.h:91
std::vector< dbentry > dbentries
Definition: dbconf.h:80
wxDatabaseConfig * m_self
Definition: dbconf.h:82
virtual const wxString & GetPath() const
Definition: dbconf.h:38
wxString m_settingsConf
Definition: dbconf.h:112
wxPreparedStatement * m_pStatementSqlFindEntries
Definition: dbconf.h:94