Planeshift
psdatabase.h
Go to the documentation of this file.
1 /*
2  * psdatabase.h - Author: Keith Fulton
3  *
4  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef __PSDATABASE_H__
21 #define __PSDATABASE_H__
22 
23 #include <stdio.h>
24 #include <string.h>
25 
26 #include <idal.h> // Database Abstraction Layer Interface
27 
28 struct iObjectRegistry;
29 class psAdminResponseList;
30 class stringList;
31 class csVector3;
32 class psString;
33 class csRandomGen;
34 
39 // implementation of the plugin
40 
41 #define PS_DBNAME "planeshift"
42 #define PS_USER "planeshift"
43 #define PS_PASS "planeshift"
44 
46 {
47 public:
52  psDatabase(iObjectRegistry *objectreg);
53 
59  virtual ~psDatabase();
60 
74  virtual bool Initialize(const char* host, unsigned int port, const char* user,
75  const char* password, const char* database);
76 
78  void Close();
79 
81 
87  const char* GetLastSQLError ();
88 
90  void SetLastError(const char *str) { lasterror = str; }
91 
100  const char* GetLastError ();
108  const char* GetLastQuery ();
109 
110  protected:
111 
112  iObjectRegistry *object_reg;
113  csRef<iDataConnection> mysql;
114 
116  csString lasterror;
117 
118  int InsertResponse ( psAdminResponseList& responses );
119  int InsertResponse ( csString &response );
120 
121  int InsertResponseSet( stringList& responseSet );
122  int InsertTrigger( const char* trigger, const char* area,
123  int maxAttitude, int minAttitude,
124  int responseID, int priorID );
125 };
126 
127 
132 struct Result
133 {
134  iResultSet *rs;
135 
136  Result() { rs = NULL; }
137  Result(iResultSet* resset) : rs(resset) {}
138  ~Result() { if (rs) rs->Release(); }
139 
140  bool IsValid() { return rs != NULL; }
141 
142  void operator = (iResultSet* resset)
143  {
144  if (rs) rs->Release();
145  rs = resset;
146  }
147 
148  iResultRow& operator[](unsigned long whichrow)
149  {
150  return (*rs)[whichrow];
151  }
152 
153  unsigned long Count(void) { return rs->Count(); }
154 };
155 
156 
157 
160 #endif
int InsertResponseSet(stringList &responseSet)
iResultSet * rs
Definition: psdatabase.h:134
~Result()
Definition: psdatabase.h:138
const char * GetLastQuery()
Returns the last query that was performed.
unsigned long Count(void)
Definition: psdatabase.h:153
Result(iResultSet *resset)
Definition: psdatabase.h:137
const char * GetLastSQLError()
Utility functions.
int InsertResponse(psAdminResponseList &responses)
Result()
Definition: psdatabase.h:136
void SetLastError(const char *str)
Sets the last error that occured.
Definition: psdatabase.h:90
int InsertTrigger(const char *trigger, const char *area, int maxAttitude, int minAttitude, int responseID, int priorID)
csString lasterror
Contains a string that describes the last error that happened.
Definition: psdatabase.h:116
iObjectRegistry * object_reg
Definition: psdatabase.h:112
virtual bool Initialize(const char *host, unsigned int port, const char *user, const char *password, const char *database)
Initialize the database manager.
const char * GetLastError()
Returns the last error that occured.
virtual ~psDatabase()
Destructor.
This is a wrapper class for result sets which makes syntax for getting at the data easier and also us...
Definition: psdatabase.h:132
bool IsValid()
Definition: psdatabase.h:140
void Close()
Closes sql database connection.
csRef< iDataConnection > mysql
Definition: psdatabase.h:113
iResultRow & operator[](unsigned long whichrow)
Definition: psdatabase.h:148
psDatabase(iObjectRegistry *objectreg)
Initializing Constructor.