Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

db::Category Class Reference

#include <libfd.h>

List of all members.

Public Member Functions

 Category (Database *)
 Category (Database *, const std::string &)
 Category (Database *, Query *, int=0)
 Category (Database &, long num)
 ~Category ()
my_ulonglong 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

Private Member Functions

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


Constructor & Destructor Documentation

db::Category::Category Database *  db  ) 
 

Begin class 'Category'

Definition at line 35 of file libfd.cpp.

References clear(), database, and new_object.

00036 { 00037 database = db; 00038 new_object = 1; 00039 clear(); 00040 }

db::Category::Category Database *  ,
const std::string & 
 

Definition at line 43 of file libfd.cpp.

References database, new_object, and spawn().

00044 { 00045 database = db; 00046 new_object = 1; 00047 spawn(sql); 00048 }

db::Category::Category Database *  ,
Query *  ,
int  = 0
 

Definition at line 51 of file libfd.cpp.

References database, new_object, and spawn().

00052 { 00053 database = db; 00054 new_object = 0; 00055 spawn(qd, offset); 00056 }

db::Category::Category Database &  ,
long  num
 

Definition at line 59 of file libfd.cpp.

References database, and spawn().

00059 :database(&db),new_object(1) 00060 { 00061 Query q(*database); 00062 std::string sql = "select * from category where "; 00063 { 00064 char slask[100]; 00065 sprintf(slask,"num='%ld'",i_num); 00066 sql += slask; 00067 } 00068 spawn(sql); 00069 }

db::Category::~Category  ) 
 

Definition at line 72 of file libfd.cpp.

00073 { 00074 }


Member Function Documentation

void db::Category::clear  )  [private]
 

Definition at line 188 of file libfd.cpp.

References num.

Referenced by Category(), and spawn().

00189 { 00190 num = 0; 00191 // 1 - name varchar(255) 00192 }

void db::Category::erase  ) 
 

Definition at line 138 of file libfd.cpp.

References database, new_object, and num.

00139 { 00140 if (!new_object) 00141 { 00142 std::string sql = "delete from category where"; 00143 Query q(*database); 00144 { 00145 char slask[200]; 00146 sprintf(slask," num='%ld'",this -> num); 00147 sql += slask; 00148 } 00149 q.execute(sql); 00150 } 00151 }

my_ulonglong db::Category::insert  ) 
 

Definition at line 83 of file libfd.cpp.

References database, name, new_object, and num.

Referenced by save().

00084 { 00085 Query q(*database); 00086 std::string sql; 00087 00088 sql = "insert into category(num,name)"; 00089 { 00090 char slask[100]; 00091 sprintf(slask," values(%ld",this -> num); 00092 sql += slask; 00093 } 00094 sql += ", '" + q.safestr(this -> name) + "'"; 00095 sql += ")"; 00096 q.execute(sql); 00097 new_object = 0; 00098 my_ulonglong inserted_id = q.insert_id(); 00099 num = inserted_id; 00100 return inserted_id; 00101 }

size_t db::Category::num_cols  ) 
 

Definition at line 182 of file libfd.cpp.

00183 { 00184 return 2; 00185 }

void db::Category::save  ) 
 

Definition at line 129 of file libfd.cpp.

References insert(), new_object, and update().

Referenced by form_input(), and MyMinionSocket::OnVerifiedLine().

00130 { 00131 if (new_object) 00132 insert(); 00133 else 00134 update(); 00135 }

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

Definition at line 77 of file libfd.cpp.

References spawn().

00078 { 00079 spawn(sql); 00080 }

void db::Category::spawn Query *  ,
int  = 0
[private]
 

Definition at line 219 of file libfd.cpp.

References clear(), name, and num.

00220 { 00221 clear(); 00222 00223 num = qd -> getval(0 + offset); // 0 - num int(11) 00224 name = qd -> getstr(1 + offset); // 1 - name varchar(255) 00225 }

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

Definition at line 195 of file libfd.cpp.

References clear(), database, name, new_object, and num.

Referenced by Category(), and select().

00196 { 00197 Query q(*database); 00198 std::string temp; 00199 00200 clear(); 00201 00202 if (!strncasecmp(sql.c_str(),"select * ",9)) 00203 { 00204 temp = "select num,name " + sql.substr(9); 00205 } else 00206 temp = sql; 00207 q.get_result(temp); 00208 if (q.fetch_row()) 00209 { 00210 num = q.getval(0); // 0 - num int(11) 00211 name = q.getstr(1); // 1 - name varchar(255) 00212 new_object = 0; 00213 } else 00214 clear(); 00215 q.free_result(); 00216 }

void db::Category::update long  num  )  [private]
 

Definition at line 110 of file libfd.cpp.

References database, name, and num.

00111 { 00112 Query q(*database); 00113 std::string sql; 00114 { 00115 char slask[200]; 00116 sprintf(slask,"update category set num=%ld",this -> num); 00117 sql += slask; 00118 } 00119 sql += ", name='" + q.safestr(this -> name) + "'"; 00120 { 00121 char slask[200]; 00122 sprintf(slask," where num='%ld'",i_num); 00123 sql += slask; 00124 } 00125 q.execute(sql); 00126 }

void db::Category::update  ) 
 

Definition at line 104 of file libfd.cpp.

References num.

Referenced by save().

00105 { 00106 update(this -> num); 00107 }

std::string db::Category::xml const std::string &  ,
const std::string & 
 

Definition at line 168 of file libfd.cpp.

References database, name, and num.

00169 { 00170 Query q(*database); 00171 std::string dest; 00172 char slask[200]; 00173 dest = "<CATEGORY " + tag + "=\"" + xvalx + "\">"; 00174 sprintf(slask,"<NUM>%ld</NUM>",this -> num); 00175 dest += slask; 00176 dest += "<NAME>" + q.xmlsafestr(this -> name) + "</NAME>"; 00177 dest += "</CATEGORY>"; 00178 return dest; 00179 }

std::string db::Category::xml  ) 
 

Definition at line 154 of file libfd.cpp.

References database, name, and num.

00155 { 00156 Query q(*database); 00157 std::string dest; 00158 char slask[200]; 00159 dest = "<CATEGORY>"; 00160 sprintf(slask,"<NUM>%ld</NUM>",this -> num); 00161 dest += slask; 00162 dest += "<NAME>" + q.xmlsafestr(this -> name) + "</NAME>"; 00163 dest += "</CATEGORY>"; 00164 return dest; 00165 }


Member Data Documentation

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

Definition at line 78 of file libfd.h.

Referenced by Category(), erase(), insert(), spawn(), update(), and xml().

std::string db::Category::name
 

Definition at line 69 of file libfd.h.

Referenced by form_input(), insert(), MyMinionSocket::OnVerifiedLine(), post_form(), search(), spawn(), update(), and xml().

short db::Category::new_object [private]
 

Definition at line 79 of file libfd.h.

Referenced by Category(), erase(), insert(), save(), and spawn().

long db::Category::num
 

Definition at line 68 of file libfd.h.

Referenced by clear(), erase(), form_input(), insert(), MyMinionSocket::OnVerifiedLine(), post_form(), search(), spawn(), update(), and xml().


The documentation for this class was generated from the following files:
Generated on Thu Feb 10 22:42:41 2005 for Distributed URL Classification Tool by doxygen 1.3.7