4 ** Published / author: 2005-08-12 / grymse@alhem.net
8 Copyright (C) 2001-2006 Anders Hedstrom
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.
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.
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.
25 #ifndef _DATABASE_H_SQLITE
26 #define _DATABASE_H_SQLITE
30 * This file contains the Database class.
41 #ifdef SQLITEW_NAMESPACE
42 namespace SQLITEW_NAMESPACE
{
46 /** Connection information and pool. */
50 /** Connection pool struct. */
53 OPENDB() : busy(false) {}
54 sqlite3
*db
; ///< The database connection
55 bool busy
; ///< Is the database connection used
57 typedef std::list
<OPENDB
*> opendb_v
; ///< The pool of open database connections
60 /** Construc a Database that uses the specified filename. */
61 Database(const std::string
& database
);
66 /** try to establish connection with given host */
69 /** Request a database connection.
70 The "grabdb" method is used by the Query class, so that each object instance of Query gets a unique
71 database connection. I will reimplement your connection check logic in the Query class, as that's where
72 the database connection is really used.
73 It should be used something like this.
78 q.execute("delete * from user"); // well maybe not
81 When the Query object is deleted, then "freedb" is called - the database connection stays open in the
82 m_opendbs vector. New Query objects can then reuse old connections.
86 /** Free the database connection. */
87 void freedb(OPENDB
*odb
);
89 /** Escape string - change all ' to ''. */
90 std::string
safestr(const std::string
& );
91 /** Make string xml safe. */
92 std::string
xmlsafestr(const std::string
& );
94 /** Convert string to 64-bit integer. */
95 int64_t a2bigint(const std::string
& );
96 /** Convert string to unsigned 64-bit integer. */
97 uint64_t a2ubigint(const std::string
& );
100 /** Hide the copy constructor. */
101 Database(const Database
& );
102 /** Hide the assignment operator. */
103 Database
& operator=(const Database
& );
106 void error(const char *format
, ...);
108 std::string database
; ///< The name of the database
109 opendb_v m_opendbs
; ///< The open database connection
113 #ifdef SQLITEW_NAMESPACE
114 } // namespace SQLITEW_NAMESPACE {
117 #endif // _DATABASE_H