Logo
~Sockets~
~Examples~
~Contact~

db::Chunk Class Reference

#include <libfuture.h>

Collaboration diagram for db::Chunk:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Chunk (Database *)
 Begin class 'Chunk'.
 Chunk (Database *, const std::string &)
 Chunk (Database *, Query *, int=0)
 Chunk (Database &, long num)
 Chunk (Database &, long area, long x, long y, long z)
 ~Chunk ()
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 ()
 Chunk (Database *)
 Chunk (Database *, const std::string &)
 Chunk (Database *, Query *, int=0)
 Chunk (Database &, long num)
 Chunk (Database &, long area, long x, long y, long z)
 ~Chunk ()
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
long area
std::string terrain
long x
long y
long z
long created_by
std::string created_date

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 188 of file root/src/futuremud/libfuture/libfuture.h.


Constructor & Destructor Documentation

Chunk::Chunk ( Database *   ) 

Begin class 'Chunk'.

Definition at line 845 of file libfuture.cpp.

00846 {
00847         database = db;
00848         new_object = 1;
00849         clear();
00850 }

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

Definition at line 853 of file libfuture.cpp.

00854 {
00855         database = db;
00856         new_object = 1;
00857         spawn(sql);
00858 }

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

Definition at line 861 of file libfuture.cpp.

00862 {
00863         database = db;
00864         new_object = 0;
00865         spawn(qd, offset);
00866 }

Chunk::Chunk ( Database &  ,
long  num 
)

Definition at line 869 of file libfuture.cpp.

References database, and spawn().

00869                                    :database(&db),new_object(1)
00870 {
00871         Query q(*database);
00872         std::string sql = "select * from chunk where ";
00873         {
00874                 char slask[100];
00875                 sprintf(slask,"num='%ld'",i_num);
00876                 sql += slask;
00877         }
00878         spawn(sql);
00879 }

Chunk::Chunk ( Database &  ,
long  area,
long  x,
long  y,
long  z 
)

Definition at line 882 of file libfuture.cpp.

References database, and spawn().

00882                                                                :database(&db),new_object(1)
00883 {
00884         Query q(*database);
00885         std::string sql = "select * from chunk where ";
00886         {
00887                 char slask[100];
00888                 sprintf(slask,"area='%ld'",i_area);
00889                 sql += slask;
00890         }
00891         {
00892                 char slask[100];
00893                 sprintf(slask," and x='%ld'",i_x);
00894                 sql += slask;
00895         }
00896         {
00897                 char slask[100];
00898                 sprintf(slask," and y='%ld'",i_y);
00899                 sql += slask;
00900         }
00901         {
00902                 char slask[100];
00903                 sprintf(slask," and z='%ld'",i_z);
00904                 sql += slask;
00905         }
00906         spawn(sql);
00907 }

Chunk::~Chunk (  ) 

Definition at line 910 of file libfuture.cpp.

00911 {
00912 }

db::Chunk::Chunk ( Database *   ) 

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

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

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

db::Chunk::Chunk ( Database &  ,
long  area,
long  x,
long  y,
long  z 
)

db::Chunk::~Chunk (  ) 


Member Function Documentation

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

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

References database.

00196 { return *database; }

unsigned long long int Chunk::insert (  ) 

Definition at line 921 of file libfuture.cpp.

00922 {
00923         Query q(*database);
00924         std::string sql;
00925 
00926         sql = "insert into chunk(area,terrain,x,y,z,created_by,created_date)";
00927         {
00928                 char slask[100];
00929                 sprintf(slask," values(%ld",this -> area);
00930                 sql += slask;
00931         }
00932         sql += ", '" + q.GetDatabase().safestr(this -> terrain) + "'";
00933         {
00934                 char slask[100];
00935                 sprintf(slask,", %ld",this -> x);
00936                 sql += slask;
00937         }
00938         {
00939                 char slask[100];
00940                 sprintf(slask,", %ld",this -> y);
00941                 sql += slask;
00942         }
00943         {
00944                 char slask[100];
00945                 sprintf(slask,", %ld",this -> z);
00946                 sql += slask;
00947         }
00948         {
00949                 char slask[100];
00950                 sprintf(slask,", %ld",this -> created_by);
00951                 sql += slask;
00952         }
00953         sql += ", '" + q.GetDatabase().safestr(this -> created_date) + "'";
00954         sql += ")";
00955         q.execute(sql);
00956         new_object = 0;
00957         unsigned long long int inserted_id = q.insert_id();
00958         num = inserted_id;
00959         return inserted_id;
00960 }

void Chunk::update (  ) 

Definition at line 963 of file libfuture.cpp.

00964 {
00965         update(this -> num);
00966 }

void Chunk::save (  ) 

Definition at line 1009 of file libfuture.cpp.

Referenced by Chunk::Init().

01010 {
01011         if (new_object)
01012                 insert();
01013         else
01014                 update();
01015 }

void Chunk::erase (  ) 

Definition at line 1018 of file libfuture.cpp.

01019 {
01020         if (!new_object)
01021         {
01022                 std::string sql = "delete from chunk where";
01023                 Query q(*database);
01024                 {
01025                         char slask[200];
01026                         sprintf(slask," num='%ld'",this -> num);
01027                         sql += slask;
01028                 }
01029                 q.execute(sql);
01030         }
01031 }

std::string Chunk::xml (  ) 

Definition at line 1034 of file libfuture.cpp.

01035 {
01036         Query q(*database);
01037         std::string dest;
01038         char slask[200];
01039         dest = "<CHUNK>";
01040         sprintf(slask,"<NUM>%ld</NUM>",this -> num);
01041         dest += slask;
01042         sprintf(slask,"<AREA>%ld</AREA>",this -> area);
01043         dest += slask;
01044         dest += "<TERRAIN>" + q.GetDatabase().xmlsafestr(this -> terrain) + "</TERRAIN>";
01045         sprintf(slask,"<X>%ld</X>",this -> x);
01046         dest += slask;
01047         sprintf(slask,"<Y>%ld</Y>",this -> y);
01048         dest += slask;
01049         sprintf(slask,"<Z>%ld</Z>",this -> z);
01050         dest += slask;
01051         sprintf(slask,"<CREATED_BY>%ld</CREATED_BY>",this -> created_by);
01052         dest += slask;
01053         dest += "<CREATED_DATE>" + q.GetDatabase().xmlsafestr(this -> created_date) + "</CREATED_DATE>";
01054         dest += "</CHUNK>";
01055         return dest;
01056 }

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

Definition at line 1059 of file libfuture.cpp.

01060 {
01061         Query q(*database);
01062         std::string dest;
01063         char slask[200];
01064         dest = "<CHUNK " + tag + "=\"" + xvalx + "\">";
01065         sprintf(slask,"<NUM>%ld</NUM>",this -> num);
01066         dest += slask;
01067         sprintf(slask,"<AREA>%ld</AREA>",this -> area);
01068         dest += slask;
01069         dest += "<TERRAIN>" + q.GetDatabase().xmlsafestr(this -> terrain) + "</TERRAIN>";
01070         sprintf(slask,"<X>%ld</X>",this -> x);
01071         dest += slask;
01072         sprintf(slask,"<Y>%ld</Y>",this -> y);
01073         dest += slask;
01074         sprintf(slask,"<Z>%ld</Z>",this -> z);
01075         dest += slask;
01076         sprintf(slask,"<CREATED_BY>%ld</CREATED_BY>",this -> created_by);
01077         dest += slask;
01078         dest += "<CREATED_DATE>" + q.GetDatabase().xmlsafestr(this -> created_date) + "</CREATED_DATE>";
01079         dest += "</CHUNK>";
01080         return dest;
01081 }

size_t Chunk::num_cols (  ) 

Definition at line 1084 of file libfuture.cpp.

01085 {
01086         return 8;
01087 }

void Chunk::clear (  )  [private]

Definition at line 1090 of file libfuture.cpp.

01091 {
01092         this -> num = 0;
01093         this -> area = 0;
01094         this -> terrain = "";
01095         this -> x = 0;
01096         this -> y = 0;
01097         this -> z = 0;
01098         this -> created_by = 0;
01099         this -> created_date = "";
01100 }

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

Definition at line 1103 of file libfuture.cpp.

Referenced by Chunk().

01104 {
01105         Query q(*database);
01106         std::string temp;
01107 
01108         clear();
01109 
01110         if (!strncasecmp(sql.c_str(),"select * ",9))
01111         {
01112                 temp = "select num,area,terrain,x,y,z,created_by,created_date " + sql.substr(9);
01113         } else
01114                 temp = sql;
01115         q.get_result(temp);
01116         if (q.fetch_row())
01117         {
01118                 this -> num = q.getval(0);                                                                                                                                                              // 0 - num integer
01119                 this -> area = q.getval(1);                                                                                                                                                             // 1 - area integer
01120                 this -> terrain = q.getstr(2);                                                                                                                                                          // 2 - terrain text
01121                 this -> x = q.getval(3);                                                                                                                                                                // 3 - x integer
01122                 this -> y = q.getval(4);                                                                                                                                                                // 4 - y integer
01123                 this -> z = q.getval(5);                                                                                                                                                                // 5 - z integer
01124                 this -> created_by = q.getval(6);                                                                                                                                                               // 6 - created_by integer
01125                 this -> created_date = q.getstr(7);                                                                                                                                                             // 7 - created_date datetime
01126                 new_object = 0;
01127         } else
01128                 clear();
01129         q.free_result();
01130 }

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

Definition at line 1133 of file libfuture.cpp.

01134 {
01135         clear();
01136 
01137         this -> num = qd -> getval(0 + offset);                                                                                                                                                         // 0 - num integer
01138         this -> area = qd -> getval(1 + offset);                                                                                                                                                                // 1 - area integer
01139         this -> terrain = qd -> getstr(2 + offset);                                                                                                                                                             // 2 - terrain text
01140         this -> x = qd -> getval(3 + offset);                                                                                                                                                           // 3 - x integer
01141         this -> y = qd -> getval(4 + offset);                                                                                                                                                           // 4 - y integer
01142         this -> z = qd -> getval(5 + offset);                                                                                                                                                           // 5 - z integer
01143         this -> created_by = qd -> getval(6 + offset);                                                                                                                                                          // 6 - created_by integer
01144         this -> created_date = qd -> getstr(7 + offset);                                                                                                                                                                // 7 - created_date datetime
01145 }

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

Definition at line 915 of file libfuture.cpp.

00916 {
00917         spawn(sql);
00918 }

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

Definition at line 969 of file libfuture.cpp.

00970 {
00971         Query q(*database);
00972         std::string sql;
00973         {
00974                 char slask[200];
00975                 sprintf(slask,"update chunk set area=%ld",this -> area);
00976                 sql += slask;
00977         }
00978         sql += ", terrain='" + q.GetDatabase().safestr(this -> terrain) + "'";
00979         {
00980                 char slask[200];
00981                 sprintf(slask,", x=%ld",this -> x);
00982                 sql += slask;
00983         }
00984         {
00985                 char slask[200];
00986                 sprintf(slask,", y=%ld",this -> y);
00987                 sql += slask;
00988         }
00989         {
00990                 char slask[200];
00991                 sprintf(slask,", z=%ld",this -> z);
00992                 sql += slask;
00993         }
00994         {
00995                 char slask[200];
00996                 sprintf(slask,", created_by=%ld",this -> created_by);
00997                 sql += slask;
00998         }
00999         sql += ", created_date='" + q.GetDatabase().safestr(this -> created_date) + "'";
01000         {
01001                 char slask[200];
01002                 sprintf(slask," where num='%ld'",i_num);
01003                 sql += slask;
01004         }
01005         q.execute(sql);
01006 }

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

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

References database.

00196 { return *database; }

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

void db::Chunk::update (  ) 

void db::Chunk::save (  ) 

void db::Chunk::erase (  ) 

std::string db::Chunk::xml (  ) 

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

size_t db::Chunk::num_cols (  ) 

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

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

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

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

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


Member Data Documentation

long Chunk::num

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

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

Referenced by Chunk::Init().

std::string Chunk::terrain

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

Referenced by Chunk::Init().

long Chunk::x

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

Referenced by Chunk::Init().

long Chunk::y

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

Referenced by Chunk::Init().

long Chunk::z

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

Referenced by Chunk::Init().

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

Referenced by Chunk::Init().

std::string Chunk::created_date

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

Referenced by Chunk::Init().

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

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

Referenced by Chunk(), and GetDatabase().

short Chunk::new_object [private]

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

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

Definition at line 223 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