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.
27 #pragma warning(disable:4786)
45 #ifdef SQLITEW_NAMESPACE
46 namespace SQLITEW_NAMESPACE
{
50 Database::Database(const std::string
& d
)
57 for (opendb_v::iterator it
= m_opendbs
.begin(); it
!= m_opendbs
.end(); it
++)
60 sqlite3_close(p
-> db
);
62 while (m_opendbs
.size())
64 opendb_v::iterator it
= m_opendbs
.begin();
66 /* If we're busy, it's YOUR fault you didn't delete the
67 * query object. Therefore, you take the consequences too. */
74 Database::OPENDB
*Database::grabdb()
78 for (opendb_v::iterator it
= m_opendbs
.begin(); it
!= m_opendbs
.end(); it
++)
94 throw std::runtime_error("grabdb: OPENDB struct "
95 "couldn't be created");
97 int rc
= sqlite3_open(database
.c_str(), &odb
-> db
);
99 std::string
msg(sqlite3_errmsg(odb
->db
));
100 sqlite3_close(odb
-> db
);
102 throw std::runtime_error("Can't open database: " + msg
);
105 m_opendbs
.push_back(odb
);
115 void Database::freedb(Database::OPENDB
*odb
)
123 bool Database::Connected()
125 OPENDB
*odb
= grabdb();
134 std::string
Database::safestr(const std::string
& str
)
137 for (size_t i
= 0; i
< str
.size(); i
++)
153 std::string
Database::xmlsafestr(const std::string
& str
)
156 for (size_t i
= 0; i
< str
.size(); i
++)
183 int64_t Database::a2bigint(const std::string
& str
)
193 for (; i
< str
.size(); i
++)
195 val
= val
* 10 + (str
[i
] - 48);
197 return sign
? -val
: val
;
201 uint64_t Database::a2ubigint(const std::string
& str
)
204 for (size_t i
= 0; i
< str
.size(); i
++)
206 val
= val
* 10 + (str
[i
] - 48);
212 #ifdef SQLITEW_NAMESPACE
213 } // namespace SQLITEW_NAMESPACE {