00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _DATABASE_H_SQLITE
00034 #define _DATABASE_H_SQLITE
00035
00036 #ifdef _WIN32
00037 #include <windows.h>
00038 #else
00039 #include <pthread.h>
00040 #endif
00041 #include <string>
00042 #include <list>
00043 #ifdef WIN32
00044 typedef unsigned __int64 uint64_t;
00045 typedef __int64 int64_t;
00046 #else
00047 #include <stdint.h>
00048 #endif
00049
00050 #ifdef SQLITEW_NAMESPACE
00051 namespace SQLITEW_NAMESPACE {
00052 #endif
00053
00054
00055 class IError;
00056 class Query;
00057 class Mutex;
00058
00059
00061 class Database
00062 {
00063 public:
00066 class Mutex {
00067 public:
00068 Mutex();
00069 ~Mutex();
00070 void Lock();
00071 void Unlock();
00072 private:
00073 #ifdef _WIN32
00074 HANDLE m_mutex;
00075 #else
00076 pthread_mutex_t m_mutex;
00077 #endif
00078 };
00079 private:
00081 class Lock {
00082 public:
00083 Lock(Mutex& mutex,bool use);
00084 ~Lock();
00085 private:
00086 Mutex& m_mutex;
00087 bool m_b_use;
00088 };
00089 public:
00091 struct OPENDB {
00092 OPENDB() : busy(false) {}
00093 sqlite3 *db;
00094 bool busy;
00095 };
00096 typedef std::list<OPENDB *> opendb_v;
00097
00098 public:
00100 Database(const std::string& database,
00101 IError * = NULL);
00102
00104 Database(Mutex& ,const std::string& database,
00105 IError * = NULL);
00106
00107 virtual ~Database();
00108
00110 bool Connected();
00111
00112 void RegErrHandler(IError *);
00113 void error(Query&,const char *format, ...);
00114 void error(Query&,const std::string& );
00115
00131 OPENDB *grabdb();
00132 void freedb(OPENDB *odb);
00133
00135 std::string safestr(const std::string& );
00137 std::string xmlsafestr(const std::string& );
00138
00140 int64_t a2bigint(const std::string& );
00142 uint64_t a2ubigint(const std::string& );
00143
00144 private:
00145 Database(const Database& ) : m_mutex(m_mutex) {}
00146 Database& operator=(const Database& ) { return *this; }
00147 void error(const char *format, ...);
00148
00149 std::string database;
00150 opendb_v m_opendbs;
00151 IError *m_errhandler;
00152 bool m_embedded;
00153 Mutex& m_mutex;
00154 bool m_b_use_mutex;
00155 };
00156
00157
00158 #ifdef SQLITEW_NAMESPACE
00159 }
00160 #endif
00161
00162 #endif // _DATABASE_H