Database.h

Go to the documentation of this file.
00001 //**********************************************************************
00002 //
00003 //  REGCOM: Regimental Command
00004 //  Copyright (C) 2008 Randi J. Relander
00005 //    <rjrelander@users.sourceforge.net>
00006 //
00007 //  This program is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU General Public License
00009 //  as published by the Free Software Foundation; either version 3
00010 //  of the License, or (at your option) any later version.
00011 //  
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //  
00017 //  You should have received a copy of the GNU General Public
00018 //  License along with this program.  If not, see 
00019 //  <http://www.gnu.org/licenses/>.
00020 //  
00021 //**********************************************************************
00022 
00023 #ifndef REGCOM_SERVER_DATABASE_H
00024 #define REGCOM_SERVER_DATABASE_H
00025 
00026 // SYSTEM INCLUDES
00027 #include <string>
00028 
00029 // make mysql and windows play nice
00030 #ifdef _WIN32
00031 #define SOCKET int
00032 #endif
00033 
00034 // LIBRARY INCLUDES
00035 #include "mysql.h"
00036 #include "SDL.h"
00037 #include "SDL_thread.h"
00038 
00039 // PROJECT INCLUDES
00040 #include "regcom/common/ErrorCode.h"
00041 #include "regcom/common/Player.h"
00042 
00043 // NAMESPACES
00044 namespace regcom {
00045 namespace server {
00046 
00048 //  CLASS: Database
00054 class Database
00055 {
00056 public:
00057     
00058     // PUBLIC METHODS
00059 
00061     Database();
00062     
00064     virtual ~Database();
00065 
00067     common::ErrorCodeType Connect(const std::string& hostname,
00068         const std::string& username, const std::string& password);
00069 
00071     common::ErrorCodeType Close();
00072 
00074     common::ErrorCodeType GetPlayer(
00075         const std::string& rUsername, const std::string& rPassword,
00076         common::Player& rPlayer);       
00077 
00079     common::ErrorCodeType GetTimeStamp(std::string& rTimeStamp);
00080 
00081 private:
00082 
00083     // PRIVATE METHODS
00084 
00086     common::ErrorCodeType Query(
00087         const std::string& rQuery, std::string& rResult);
00088 
00090     std::string EscapeString(const std::string& rString);
00091 
00092     // MEMBER VARIABLES
00093 
00095     MYSQL* m_pDatabase;
00096 
00098     SDL_mutex* m_pQueryMutex;
00099 };
00100 
00101 } // namespace server
00102 } // namespace regcom
00103 
00104 #endif