xc
Database.h
1 /*
2  ** Database.h
3  **
4  ** Published / author: 2005-08-12 / grymse@alhem.net
5  **/
6 
7 /*
8 Copyright (C) 2001-2006 Anders Hedstrom
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24 
25 #ifndef _DATABASE_H_SQLITE
26 #define _DATABASE_H_SQLITE
27 
28 #ifdef _WIN32
29 #include <windows.h>
30 #else
31 #include <pthread.h>
32 #endif
33 #include <string>
34 #include <list>
35 #ifdef WIN32
36 typedef unsigned __int64 uint64_t;
37 typedef __int64 int64_t;
38 #else
39 #include <stdint.h>
40 #endif
41 
42 #ifdef SQLITEW_NAMESPACE
43 namespace SQLITEW_NAMESPACE {
44 #endif
45 
46 
47 class IError;
48 class Query;
49 class Mutex;
50 
51 
52 // Connection information and pool.
53 class Database
54  {
55  public:
58  class Mutex
59  {
60  public:
61  Mutex();
62  ~Mutex();
63  void Lock();
64  void Unlock();
65  private:
66 #ifdef _WIN32
67  HANDLE m_mutex;
68 #else
69  pthread_mutex_t m_mutex;
70 #endif
71  };
72  private:
74  class Lock
75  {
76  public:
77  Lock(Mutex& mutex,bool use);
78  ~Lock();
79  private:
80  Mutex& m_mutex;
81  bool m_b_use;
82  };
83  public:
85  struct OPENDB
86  {
87  OPENDB() : busy(false) {}
88  sqlite3 *db;
89  bool busy;
90  };
91  typedef std::list<OPENDB *> opendb_v;
92  public:
94  Database(const std::string& database,IError * = NULL);
95 
97  Database(Mutex& ,const std::string& database,IError * = NULL);
98 
99  virtual ~Database();
100 
102  bool Connected(void);
103 
104  void RegErrHandler(IError *);
105  void error(Query&,const char *format, ...);
106  void error(Query&,const std::string& );
107 
123  OPENDB *grabdb();
124  void freedb(OPENDB *odb);
125 
127  std::string safestr(const std::string& );
129  std::string xmlsafestr(const std::string& );
130 
132  int64_t a2bigint(const std::string& );
134  uint64_t a2ubigint(const std::string& );
135 
136  inline const std::string &getName(void) const
137  { return database; }
138 
139  private:
140  Database(const Database &other) : m_mutex(other.m_mutex) {} //LCPT 6/9/2018
141  Database& operator=(const Database& ) { return *this; }
142  void error(const char *format, ...);
143  //
144  std::string database;
145  opendb_v m_opendbs;
146  IError *m_errhandler;
147  bool m_embedded;
148  Mutex& m_mutex;
149  bool m_b_use_mutex;
150  };
151 
152 
153 #ifdef SQLITEW_NAMESPACE
154 } // namespace SQLITEW_NAMESPACE {
155 #endif
156 
157 #endif // _DATABASE_H
Mutex container class, used by Lock.
Definition: Database.h:58
Definition: Database.h:53
Connection pool struct.
Definition: Database.h:85
SQL Statement execute / result.
Definition: Query.h:49
Log class interface.
Definition: IError.h:41