Planeshift

psdatabase.h

Go to the documentation of this file.
00001 /*
00002  * psdatabase.h - Author: Keith Fulton
00003  *
00004  * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org) 
00005  *
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 (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef __PSDATABASE_H__
00021 #define __PSDATABASE_H__
00022 
00023 #include <stdio.h>
00024 #include <string.h>
00025 
00026 #include <idal.h>      // Database Abstraction Layer Interface
00027 
00028 struct iObjectRegistry;
00029 class psAdminResponseList;
00030 class stringList;
00031 class csVector3;
00032 class psString;
00033 class csRandomGen;
00034 
00039 // implementation of the plugin
00040 
00041 #define  PS_DBNAME  "planeshift"
00042 #define  PS_USER    "planeshift"
00043 #define  PS_PASS    "planeshift"
00044 
00045 class psDatabase
00046 {
00047 public:
00052     psDatabase(iObjectRegistry *objectreg);
00053 
00059     virtual ~psDatabase();
00060 
00074     virtual bool Initialize(const char* host, unsigned int port, const char* user,
00075                             const char* password, const char* database);
00076 
00078     void Close();
00079 
00081 
00087     const char* GetLastSQLError ();
00088 
00090     void SetLastError(const char *str) { lasterror = str; }
00091 
00100     const char* GetLastError ();
00108     const char* GetLastQuery ();
00109 
00110  protected:
00111     
00112     iObjectRegistry *object_reg;
00113     csRef<iDataConnection> mysql;
00114 
00116     csString lasterror;
00117 
00118     int InsertResponse ( psAdminResponseList& responses );
00119     int InsertResponse ( csString &response );
00120 
00121     int InsertResponseSet( stringList& responseSet );
00122     int InsertTrigger( const char* trigger, const char* area, 
00123                       int maxAttitude, int minAttitude, 
00124                       int responseID, int priorID );
00125 };
00126 
00127 
00132 struct Result
00133 {
00134     iResultSet *rs;
00135 
00136     Result() { rs = NULL; }
00137     Result(iResultSet* resset) : rs(resset) {}
00138     ~Result() { if (rs) rs->Release(); }
00139 
00140     bool IsValid() { return rs != NULL; }
00141 
00142     void operator = (iResultSet* resset)
00143     { 
00144         if (rs) rs->Release();
00145         rs = resset; 
00146     }
00147 
00148     iResultRow& operator[](unsigned long whichrow)
00149     {
00150         return (*rs)[whichrow];
00151     }
00152     
00153     unsigned long Count(void) { return rs->Count(); }
00154 };
00155 
00156 
00157 
00160 #endif