Logo
~Database~
~ C++ ~
~Contact~

Database.h

Go to the documentation of this file.
00001 /*
00002  ** Database.h
00003  **
00004  ** Published / author: 2001-01-04 / grymse@telia.com
00005  **/
00006 /*
00007 Copyright (C) 2001 Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022 */
00023 #ifndef _DATABASE_H
00024 #define _DATABASE_H
00025 
00026 #include <string>
00027 #include <list>
00028 
00029 #ifdef ODBCW_NAMESPACE
00030 namespace ODBCW_NAMESPACE {
00031 #endif
00032 
00033 
00034 class Query;
00035 class IError;
00036 class Session;
00037 
00038 class Database
00039 {
00042 public:
00043         class Mutex {
00044         public:
00045                 Mutex();
00046                 ~Mutex();
00047                 void Lock();
00048                 void Unlock();
00049         private:
00050 #ifdef _WIN32
00051                 HANDLE m_mutex;
00052 #else
00053                 pthread_mutex_t m_mutex;
00054 #endif
00055         };
00057 private:
00058         class Lock {
00059         public:
00060                 Lock(Mutex& mutex,bool use);
00061                 ~Lock();
00062         private:
00063                 Mutex& m_mutex;
00064                 bool m_b_use;
00065         };
00066 public:
00073         Database(const std::string& dsn,const std::string& u,const std::string& auth,IError *p = NULL);
00078         Database(const std::string& driverconnect,IError *p = NULL);
00086         Database(Mutex&,const std::string& dsn,const std::string& u,const std::string& auth,IError *p = NULL);
00092         Database(Mutex&,const std::string& driverconnect,IError *p = NULL);
00095         virtual ~Database();
00096 
00098         Session *grabdb();
00100         void freedb(Session *);
00102         Query *GetQuery();
00104         Query *GetQuery(const std::string& sql);
00105 
00106         short errcode();
00107         void GetErrorText(char *);
00108 
00109         void SetEscapeChar(char);
00110         char GetEscapeChar();
00111         void SetDecimalChar(char);
00112         char GetDecimalChar();
00113 
00114         IError *GetErrHandler() { return m_errhandler; }
00115         void error(const std::string& text);
00116 
00117         std::string safestr(const std::string&);
00118         std::string xmlsafestr(const std::string&);
00119 
00120 private:
00121         short m_driverconnect;
00122         std::string m_host; // odbc: DSN
00123         std::string m_user; // odbc: user
00124         std::string m_password; // odbc: auth
00125         std::list<Session *> m_sessions;
00126         short m_errc;
00127         char m_escape;
00128         char m_decimal;
00129         IError *m_errhandler;
00130         Mutex& m_mutex;
00131         bool m_b_use_mutex;
00132 };
00133 
00134 
00135 #ifdef ODBCW_NAMESPACE
00136 } // namespace ODBCW_NAMESPACE {
00137 #endif
00138 #endif // _DATABASE_H
Page, code, and content Copyright (C) 2006 by Anders Hedström