Logo
~Sockets~
~Examples~
~Contact~

db::Race Class Reference

#include <libfuture.h>

Collaboration diagram for db::Race:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Race (Database *)
 Begin class 'Race'.
 Race (Database *, const std::string &)
 Race (Database *, Query *, int=0)
 Race (Database &, long num)
 Race (Database &, const std::string &name)
 ~Race ()
Database & GetDatabase ()
unsigned long long int insert ()
void update ()
void save ()
void erase ()
std::string xml ()
std::string xml (const std::string &, const std::string &)
size_t num_cols ()
 Race (Database *)
 Race (Database *, const std::string &)
 Race (Database *, Query *, int=0)
 Race (Database &, long num)
 Race (Database &, const std::string &name)
 ~Race ()
Database & GetDatabase ()
unsigned long long int insert ()
void update ()
void save ()
void erase ()
std::string xml ()
std::string xml (const std::string &, const std::string &)
size_t num_cols ()

Public Attributes

long num
std::string name
double sightrange
double hearing

Private Member Functions

void clear ()
void spawn (const std::string &)
void spawn (Query *, int=0)
void select (const std::string &)
void update (long num)
void clear ()
void spawn (const std::string &)
void spawn (Query *, int=0)
void select (const std::string &)
void update (long num)

Private Attributes

Database * database
short new_object
Database * database

Detailed Description

Definition at line 375 of file root/src/futuremud/libfuture/libfuture.h.


Constructor & Destructor Documentation

Race::Race ( Database *   ) 

Begin class 'Race'.

Definition at line 2072 of file libfuture.cpp.

02073 {
02074         database = db;
02075         new_object = 1;
02076         clear();
02077 }

Race::Race ( Database *  ,
const std::string &   
)

Definition at line 2080 of file libfuture.cpp.

02081 {
02082         database = db;
02083         new_object = 1;
02084         spawn(sql);
02085 }

Race::Race ( Database *  ,
Query *  ,
int  = 0 
)

Definition at line 2088 of file libfuture.cpp.

02089 {
02090         database = db;
02091         new_object = 0;
02092         spawn(qd, offset);
02093 }

Race::Race ( Database &  ,
long  num 
)

Definition at line 2096 of file libfuture.cpp.

References database, and spawn().

02096                                  :database(&db),new_object(1)
02097 {
02098         Query q(*database);
02099         std::string sql = "select * from race where ";
02100         {
02101                 char slask[100];
02102                 sprintf(slask,"num='%ld'",i_num);
02103                 sql += slask;
02104         }
02105         spawn(sql);
02106 }

Race::Race ( Database &  ,
const std::string &  name 
)

Definition at line 2109 of file libfuture.cpp.

References database, and spawn().

02109                                                :database(&db),new_object(1)
02110 {
02111         Query q(*database);
02112         std::string sql = "select * from race where ";
02113         sql += "name='" + q.GetDatabase().safestr(i_name) + "'";
02114         spawn(sql);
02115 }

Race::~Race (  ) 

Definition at line 2118 of file libfuture.cpp.

02119 {
02120 }

db::Race::Race ( Database *   ) 

db::Race::Race ( Database *  ,
const std::string &   
)

db::Race::Race ( Database *  ,
Query *  ,
int  = 0 
)

db::Race::Race ( Database &  ,
long  num 
)

db::Race::Race ( Database &  ,
const std::string &  name 
)

db::Race::~Race (  ) 


Member Function Documentation

Database& db::Race::GetDatabase (  )  [inline]

Definition at line 383 of file root/src/futuremud/libfuture/libfuture.h.

References database.

00383 { return *database; }

unsigned long long int Race::insert (  ) 

Definition at line 2129 of file libfuture.cpp.

02130 {
02131         Query q(*database);
02132         std::string sql;
02133 
02134         sql = "insert into race(name,sightrange,hearing)";
02135         sql += " values('" + q.GetDatabase().safestr(this -> name) + "'";
02136         {
02137                 char slask[100];
02138                 sprintf(slask,", %f",this -> sightrange);
02139                 sql += slask;
02140         }
02141         {
02142                 char slask[100];
02143                 sprintf(slask,", %f",this -> hearing);
02144                 sql += slask;
02145         }
02146         sql += ")";
02147         q.execute(sql);
02148         new_object = 0;
02149         unsigned long long int inserted_id = q.insert_id();
02150         num = inserted_id;
02151         return inserted_id;
02152 }

void Race::update (  ) 

Definition at line 2155 of file libfuture.cpp.

02156 {
02157         update(this -> num);
02158 }

void Race::save (  ) 

Definition at line 2185 of file libfuture.cpp.

02186 {
02187         if (new_object)
02188                 insert();
02189         else
02190                 update();
02191 }

void Race::erase (  ) 

Definition at line 2194 of file libfuture.cpp.

02195 {
02196         if (!new_object)
02197         {
02198                 std::string sql = "delete from race where";
02199                 Query q(*database);
02200                 {
02201                         char slask[200];
02202                         sprintf(slask," num='%ld'",this -> num);
02203                         sql += slask;
02204                 }
02205                 q.execute(sql);
02206         }
02207 }

std::string Race::xml (  ) 

Definition at line 2210 of file libfuture.cpp.

02211 {
02212         Query q(*database);
02213         std::string dest;
02214         char slask[200];
02215         dest = "<RACE>";
02216         sprintf(slask,"<NUM>%ld</NUM>",this -> num);
02217         dest += slask;
02218         dest += "<NAME>" + q.GetDatabase().xmlsafestr(this -> name) + "</NAME>";
02219         sprintf(slask,"<SIGHTRANGE>%f</SIGHTRANGE>",this -> sightrange);
02220         dest += slask;
02221         sprintf(slask,"<HEARING>%f</HEARING>",this -> hearing);
02222         dest += slask;
02223         dest += "</RACE>";
02224         return dest;
02225 }

std::string Race::xml ( const std::string &  ,
const std::string &   
)

Definition at line 2228 of file libfuture.cpp.

02229 {
02230         Query q(*database);
02231         std::string dest;
02232         char slask[200];
02233         dest = "<RACE " + tag + "=\"" + xvalx + "\">";
02234         sprintf(slask,"<NUM>%ld</NUM>",this -> num);
02235         dest += slask;
02236         dest += "<NAME>" + q.GetDatabase().xmlsafestr(this -> name) + "</NAME>";
02237         sprintf(slask,"<SIGHTRANGE>%f</SIGHTRANGE>",this -> sightrange);
02238         dest += slask;
02239         sprintf(slask,"<HEARING>%f</HEARING>",this -> hearing);
02240         dest += slask;
02241         dest += "</RACE>";
02242         return dest;
02243 }

size_t Race::num_cols (  ) 

Definition at line 2246 of file libfuture.cpp.

02247 {
02248         return 4;
02249 }

void Race::clear (  )  [private]

Definition at line 2252 of file libfuture.cpp.

02253 {
02254         this -> num = 0;
02255         this -> name = "";
02256         this -> sightrange = 0;
02257         this -> hearing = 0;
02258 }

void Race::spawn ( const std::string &   )  [private]

Definition at line 2261 of file libfuture.cpp.

Referenced by Race().

02262 {
02263         Query q(*database);
02264         std::string temp;
02265 
02266         clear();
02267 
02268         if (!strncasecmp(sql.c_str(),"select * ",9))
02269         {
02270                 temp = "select num,name,sightrange,hearing " + sql.substr(9);
02271         } else
02272                 temp = sql;
02273         q.get_result(temp);
02274         if (q.fetch_row())
02275         {
02276                 this -> num = q.getval(0);                                                                                                                                                              // 0 - num integer
02277                 this -> name = q.getstr(1);                                                                                                                                                             // 1 - name varchar(255)
02278                 this -> sightrange = q.getnum(2);                                                                                                                                                               // 2 - sightrange float
02279                 this -> hearing = q.getnum(3);                                                                                                                                                          // 3 - hearing float
02280                 new_object = 0;
02281         } else
02282                 clear();
02283         q.free_result();
02284 }

void Race::spawn ( Query *  ,
int  = 0 
) [private]

Definition at line 2287 of file libfuture.cpp.

02288 {
02289         clear();
02290 
02291         this -> num = qd -> getval(0 + offset);                                                                                                                                                         // 0 - num integer
02292         this -> name = qd -> getstr(1 + offset);                                                                                                                                                                // 1 - name varchar(255)
02293         this -> sightrange = qd -> getnum(2 + offset);                                                                                                                                                          // 2 - sightrange float
02294         this -> hearing = qd -> getnum(3 + offset);                                                                                                                                                             // 3 - hearing float
02295 }

void Race::select ( const std::string &   )  [private]

Definition at line 2123 of file libfuture.cpp.

02124 {
02125         spawn(sql);
02126 }

void Race::update ( long  num  )  [private]

Definition at line 2161 of file libfuture.cpp.

02162 {
02163         Query q(*database);
02164         std::string sql;
02165         sql += "update race set name='" + q.GetDatabase().safestr(this -> name) + "'";
02166         {
02167                 char slask[200];
02168                 sprintf(slask,", sightrange='%f'",this -> sightrange);
02169                 sql += slask;
02170         }
02171         {
02172                 char slask[200];
02173                 sprintf(slask,", hearing='%f'",this -> hearing);
02174                 sql += slask;
02175         }
02176         {
02177                 char slask[200];
02178                 sprintf(slask," where num='%ld'",i_num);
02179                 sql += slask;
02180         }
02181         q.execute(sql);
02182 }

Database& db::Race::GetDatabase (  )  [inline]

Definition at line 383 of file usr/devel/include/libfuture.h.

References database.

00383 { return *database; }

unsigned long long int db::Race::insert (  ) 

void db::Race::update (  ) 

void db::Race::save (  ) 

void db::Race::erase (  ) 

std::string db::Race::xml (  ) 

std::string db::Race::xml ( const std::string &  ,
const std::string &   
)

size_t db::Race::num_cols (  ) 

void db::Race::clear (  )  [private]

void db::Race::spawn ( const std::string &   )  [private]

void db::Race::spawn ( Query *  ,
int  = 0 
) [private]

void db::Race::select ( const std::string &   )  [private]

void db::Race::update ( long  num  )  [private]


Member Data Documentation

long Race::num

Definition at line 394 of file root/src/futuremud/libfuture/libfuture.h.

std::string Race::name

Definition at line 395 of file root/src/futuremud/libfuture/libfuture.h.

double Race::hearing

Definition at line 397 of file root/src/futuremud/libfuture/libfuture.h.

Database* db::Race::database [private]

Definition at line 406 of file root/src/futuremud/libfuture/libfuture.h.

Referenced by GetDatabase(), and Race().

short Race::new_object [private]

Definition at line 407 of file root/src/futuremud/libfuture/libfuture.h.

Database* db::Race::database [private]

Definition at line 406 of file usr/devel/include/libfuture.h.


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4