PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Database.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLDATABASE_DATABASE_H__ 00024 #define __PLDATABASE_DATABASE_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Base/Object.h> 00032 #include "PLDatabase/PLDatabase.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLDatabase { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Forward declarations ] 00043 //[-------------------------------------------------------] 00044 class DatabaseQuery; 00045 00046 00047 //[-------------------------------------------------------] 00048 //[ Classes ] 00049 //[-------------------------------------------------------] 00050 /** 00051 * @brief 00052 * Abstract SQL (Structured Query Language) database base class 00053 */ 00054 class Database : public PLCore::Object { 00055 00056 00057 //[-------------------------------------------------------] 00058 //[ RTTI interface ] 00059 //[-------------------------------------------------------] 00060 pl_class(PLDATABASE_RTTI_EXPORT, Database, "PLDatabase", PLCore::Object, "Abstract SQL (Structured Query Language) database base class") 00061 pl_class_end 00062 00063 00064 //[-------------------------------------------------------] 00065 //[ Public static functions ] 00066 //[-------------------------------------------------------] 00067 public: 00068 /** 00069 * @brief 00070 * Creates a database instance 00071 * 00072 * @param[in] sClass 00073 * Class name of the database implementation 00074 * 00075 * @return 00076 * The database instance, a null pointer on error 00077 */ 00078 static PLDATABASE_API Database *Create(const PLCore::String &sClass); 00079 00080 00081 //[-------------------------------------------------------] 00082 //[ Public virtual Database functions ] 00083 //[-------------------------------------------------------] 00084 public: 00085 /** 00086 * @brief 00087 * Destructor 00088 */ 00089 PLDATABASE_API virtual ~Database(); 00090 00091 /** 00092 * @brief 00093 * Returns the version of the database implementation 00094 * 00095 * @return 00096 * The version of the database implementation 00097 */ 00098 virtual PLCore::String GetVersion() const = 0; 00099 00100 /** 00101 * @brief 00102 * Connect to a database 00103 * 00104 * @param[in] sServer 00105 * Server name, can be a hostname (for instance 'localhost') or a IP-address 00106 * @param[in] sUserName 00107 * User name 00108 * @param[in] sUserPassword 00109 * User password 00110 * @param[in] sDatabase 00111 * Database 00112 * 00113 * @return 00114 * 'true' if all went fine, else 'false' 00115 */ 00116 virtual bool Connect(const PLCore::String &sServer, const PLCore::String &sUserName, const PLCore::String &sUserPassword, const PLCore::String &sDatabase) = 0; 00117 00118 /** 00119 * @brief 00120 * Returns whether there's an active database connection or not 00121 * 00122 * @return 00123 * 'true' if there's an active database connection, else 'false' 00124 */ 00125 virtual bool IsConnected() const = 0; 00126 00127 /** 00128 * @brief 00129 * Returns whether the connection to the database is still active or not 00130 * 00131 * @return 00132 * 'true' the connection to the database is still active, else 'false' 00133 * 00134 * @remarks 00135 * Checks whether the server connection is still active. If the connection has broken, normally 00136 * an automatic reconnection is attempted. If you as client idle for a long tíme, you can use this 00137 * function to check whether the server has closed the connection and reconnect if necessary. 00138 */ 00139 virtual bool IsConnectionActive() const = 0; 00140 00141 /** 00142 * @brief 00143 * Disconnect from the database 00144 * 00145 * @return 00146 * 'true' if all went fine, else 'false' (maybe there's no connection to disconnect?) 00147 */ 00148 virtual bool Disconnect() = 0; 00149 00150 /** 00151 * @brief 00152 * Creates a database query 00153 * 00154 * @return 00155 * The database query, a null pointer on error 00156 */ 00157 virtual DatabaseQuery *CreateQuery() = 0; 00158 00159 00160 //[-------------------------------------------------------] 00161 //[ Protected functions ] 00162 //[-------------------------------------------------------] 00163 protected: 00164 /** 00165 * @brief 00166 * Constructor 00167 */ 00168 PLDATABASE_API Database(); 00169 00170 00171 //[-------------------------------------------------------] 00172 //[ Private functions ] 00173 //[-------------------------------------------------------] 00174 private: 00175 /** 00176 * @brief 00177 * Copy constructor 00178 * 00179 * @param[in] cSource 00180 * Source to copy from 00181 */ 00182 Database(const Database &cSource); 00183 00184 /** 00185 * @brief 00186 * Copy operator 00187 * 00188 * @param[in] cSource 00189 * Source to copy from 00190 * 00191 * @return 00192 * Reference to this instance 00193 */ 00194 Database &operator =(const Database &cSource); 00195 00196 00197 }; 00198 00199 00200 //[-------------------------------------------------------] 00201 //[ Namespace ] 00202 //[-------------------------------------------------------] 00203 } // PLDatabase 00204 00205 00206 #endif // __PLDATABASE_DATABASE_H__
|