• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/data/MySqlConnection.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _mysqlconnection_h
00018 #define _mysqlconnection_h
00019 
00020 #include <spl/types.h>
00021 #include <spl/Debug.h>
00022 
00023 #ifdef _WINDOWS
00024 #include <spl/configwin32.h>
00025 #else
00026 #include <spl/autoconf/config.h>
00027 #endif
00028 
00029 #ifdef HAVE_TIME_H
00030 #include <time.h>
00031 #endif
00032 #ifdef HAVE_SYS_TYPE_H
00033 #include <sys/time.h>
00034 #endif
00035 
00042 #if defined(HAVE_MYSQL_H) || defined(HAVE_MYSQL_MYSQL_H)
00043 
00044 #include <spl/data/Connection.h>
00045 #include <spl/WeakReference.h>
00046 
00047 typedef struct _mysqlerror
00048 {
00049         int code;
00050         char errstr[512];
00051 } mysqlerror;
00052 
00053 class MySqlConnection;
00054 typedef RefCountPtrCast<MySqlConnection, Connection, ConnectionPtr> MySqlConnectionPtr;
00055 typedef WeakReference<MySqlConnection, MySqlConnectionPtr> MySqlConnectionRef;
00056 
00057 REGISTER_TYPEOF( 420, MySqlConnectionPtr );
00058 REGISTER_TYPEOF( 421, MySqlConnectionRef );
00059 
00067 class MySqlConnection : public Connection
00068 {
00069 protected:
00070         // type void (instead of MYSQL) so that mysql.h doesn't need to be included by lib users
00071         void *m_mysql;  
00072         mysqlerror m_lasterror;
00073         bool m_isopen;
00074 
00075 public:
00076         MySqlConnection(const String& serverOrIP, const String& database, const String& uid, const String& pw);
00077         virtual ~MySqlConnection();
00078 
00080         virtual void Open();
00081 
00083         virtual void Close();
00084 
00086         virtual void ChangeDatabase(const String& db);
00087 
00088         virtual TransactionPtr BeginTransaction();
00089         virtual CommandPtr CreateCommand();
00090         virtual CommandPtr CreateCommand(const String& cmdText);
00091 
00092         virtual int ExecuteNonQuery(const String& sql);
00093         virtual RecordSetPtr ExecuteQuery(const String& sql);
00094 
00096         virtual void RegisterThread();
00097 
00099         virtual void RegisterThreadExit();
00100 
00102         virtual void AllowOutOfOrderCommandParameters(bool allow);
00103 
00104 #if defined(DEBUG)
00105         virtual void CheckMem() const;
00106         virtual void ValidateMem() const;
00107 #endif
00108 
00109 private:
00110         void FillErrorInfo();
00111 };
00112 
00113 REGISTER_TYPEOF( 418, MySqlConnection );
00114 
00115 #endif
00116 
00119 #endif