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

db::Item Class Reference

#include <libfd.h>

List of all members.

Public Member Functions

 Item (Database *)
 Item (Database *, const std::string &)
 Item (Database *, Query *, int=0)
 Item (Database &, long num)
 Item (Database &, long sz, const std::string &sha1)
 ~Item ()
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
enum_t typ
long category
std::string name
std::vector< std::string > data
long sz
std::string sha1

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

std::map< std::string, uint64_t > mmap_typ
Database * database
short new_object


Constructor & Destructor Documentation

db::Item::Item Database *  db  ) 
 

Begin class 'Item'

Definition at line 237 of file libfd.cpp.

References clear(), database, and new_object.

00237 :typ(mmap_typ) 00238 { 00239 database = db; 00240 new_object = 1; 00241 clear(); 00242 }

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

Definition at line 245 of file libfd.cpp.

References database, new_object, and spawn().

00245 :typ(mmap_typ) 00246 { 00247 database = db; 00248 new_object = 1; 00249 spawn(sql); 00250 }

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

Definition at line 253 of file libfd.cpp.

References database, new_object, and spawn().

00253 :typ(mmap_typ) 00254 { 00255 database = db; 00256 new_object = 0; 00257 spawn(qd, offset); 00258 }

db::Item::Item Database &  ,
long  num
 

Definition at line 261 of file libfd.cpp.

References database, and spawn().

00261 :typ(mmap_typ),database(&db),new_object(1) 00262 { 00263 Query q(*database); 00264 std::string sql = "select * from item where "; 00265 { 00266 char slask[100]; 00267 sprintf(slask,"num='%ld'",i_num); 00268 sql += slask; 00269 } 00270 spawn(sql); 00271 }

db::Item::Item Database &  ,
long  sz,
const std::string &  sha1
 

Definition at line 274 of file libfd.cpp.

References database, and spawn().

00274 :typ(mmap_typ),database(&db),new_object(1) 00275 { 00276 Query q(*database); 00277 std::string sql = "select * from item where "; 00278 { 00279 char slask[100]; 00280 sprintf(slask,"sz='%ld'",i_sz); 00281 sql += slask; 00282 } 00283 sql += " and sha1='" + q.safestr(i_sha1) + "'"; 00284 spawn(sql); 00285 }

db::Item::~Item  ) 
 

Definition at line 288 of file libfd.cpp.

00289 { 00290 }


Member Function Documentation

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

Definition at line 462 of file libfd.cpp.

References category, mmap_typ, num, and sz.

Referenced by Item(), and spawn().

00463 { 00464 mmap_typ["File"] = 1; 00465 mmap_typ["URL"] = 2; 00466 num = 0; 00467 // 1 - typ enum('File','URL') 00468 category = 0; 00469 // 3 - name varchar(255) 00470 sz = 0; 00471 // 6 - sha1 varchar(40) 00472 }

void db::Item::erase  ) 
 

Definition at line 400 of file libfd.cpp.

References database, new_object, and num.

00401 { 00402 if (!new_object) 00403 { 00404 std::string sql = "delete from item where"; 00405 Query q(*database); 00406 { 00407 char slask[200]; 00408 sprintf(slask," num='%ld'",this -> num); 00409 sql += slask; 00410 } 00411 q.execute(sql); 00412 } 00413 }

my_ulonglong db::Item::insert  ) 
 

Definition at line 299 of file libfd.cpp.

References category, data, database, name, new_object, num, sha1, sz, and typ.

Referenced by save().

00300 { 00301 Query q(*database); 00302 std::string sql; 00303 00304 sql = "insert into item(num,typ,category,name,data,sz,sha1)"; 00305 { 00306 char slask[100]; 00307 sprintf(slask," values(%ld",this -> num); 00308 sql += slask; 00309 } 00310 sql += ", '" + q.safestr(this -> typ.String()) + "'"; 00311 { 00312 char slask[100]; 00313 sprintf(slask,", %ld",this -> category); 00314 sql += slask; 00315 } 00316 sql += ", '" + q.safestr(this -> name) + "'"; 00317 { 00318 size_t i = 1; 00319 sql += ", '"; 00320 for (std::vector<std::string>::iterator it = this -> data.begin(); it != this -> data.end(); it++,i++) 00321 { 00322 sql += q.safestr(*it); 00323 if (i < this -> data.size()) 00324 sql += "\n"; 00325 } 00326 sql += "'"; 00327 } 00328 { 00329 char slask[100]; 00330 sprintf(slask,", %ld",this -> sz); 00331 sql += slask; 00332 } 00333 sql += ", '" + q.safestr(this -> sha1) + "'"; 00334 sql += ")"; 00335 q.execute(sql); 00336 new_object = 0; 00337 my_ulonglong inserted_id = q.insert_id(); 00338 num = inserted_id; 00339 return inserted_id; 00340 }

size_t db::Item::num_cols  ) 
 

Definition at line 456 of file libfd.cpp.

00457 { 00458 return 7; 00459 }

void db::Item::save  ) 
 

Definition at line 391 of file libfd.cpp.

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

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

00392 { 00393 if (new_object) 00394 insert(); 00395 else 00396 update(); 00397 }

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

Definition at line 293 of file libfd.cpp.

References spawn().

00294 { 00295 spawn(sql); 00296 }

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

Definition at line 521 of file libfd.cpp.

References category, clear(), data, name, num, sha1, sz, and typ.

00522 { 00523 clear(); 00524 00525 num = qd -> getval(0 + offset); // 0 - num int(11) 00526 typ = qd -> getstr(1 + offset); // 1 - typ enum('File','URL') 00527 category = qd -> getval(2 + offset); // 2 - category int(11) 00528 name = qd -> getstr(3 + offset); // 3 - name varchar(255) 00529 { 00530 std::string s = qd -> getstr(4 + offset); 00531 std::string tmp; 00532 for (size_t i = 0; i < s.size(); i++) 00533 { 00534 if (s[i] == '\n') 00535 { 00536 data.push_back(tmp); 00537 tmp = ""; 00538 } 00539 else 00540 { 00541 tmp += s[i]; 00542 } 00543 } 00544 if (tmp.size()) 00545 data.push_back(tmp); 00546 } 00547 sz = qd -> getval(5 + offset); // 5 - sz int(11) 00548 sha1 = qd -> getstr(6 + offset); // 6 - sha1 varchar(40) 00549 }

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

Definition at line 475 of file libfd.cpp.

References category, clear(), data, database, name, new_object, num, sha1, sz, and typ.

Referenced by Item(), and select().

00476 { 00477 Query q(*database); 00478 std::string temp; 00479 00480 clear(); 00481 00482 if (!strncasecmp(sql.c_str(),"select * ",9)) 00483 { 00484 temp = "select num,typ,category,name,data,sz,sha1 " + sql.substr(9); 00485 } else 00486 temp = sql; 00487 q.get_result(temp); 00488 if (q.fetch_row()) 00489 { 00490 num = q.getval(0); // 0 - num int(11) 00491 typ = q.getstr(1); // 1 - typ enum('File','URL') 00492 category = q.getval(2); // 2 - category int(11) 00493 name = q.getstr(3); // 3 - name varchar(255) 00494 { 00495 std::string s = q.getstr(4); 00496 std::string tmp; 00497 for (size_t i = 0; i < s.size(); i++) 00498 { 00499 if (s[i] == '\n') 00500 { 00501 data.push_back(tmp); 00502 tmp = ""; 00503 } 00504 else 00505 { 00506 tmp += s[i]; 00507 } 00508 } 00509 if (tmp.size()) 00510 data.push_back(tmp); 00511 } 00512 sz = q.getval(5); // 5 - sz int(11) 00513 sha1 = q.getstr(6); // 6 - sha1 varchar(40) 00514 new_object = 0; 00515 } else 00516 clear(); 00517 q.free_result(); 00518 }

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

Definition at line 349 of file libfd.cpp.

References category, data, database, name, num, sha1, sz, and typ.

00350 { 00351 Query q(*database); 00352 std::string sql; 00353 { 00354 char slask[200]; 00355 sprintf(slask,"update item set num=%ld",this -> num); 00356 sql += slask; 00357 } 00358 sql += ", typ='" + q.safestr(this -> typ.String()) + "'"; 00359 { 00360 char slask[200]; 00361 sprintf(slask,", category=%ld",this -> category); 00362 sql += slask; 00363 } 00364 sql += ", name='" + q.safestr(this -> name) + "'"; 00365 { 00366 size_t i = 1; 00367 sql += ", data='"; 00368 for (std::vector<std::string>::iterator it = this -> data.begin(); it != this -> data.end(); it++,i++) 00369 { 00370 sql += q.safestr(*it); 00371 if (i < this -> data.size()) 00372 sql += "\n"; 00373 } 00374 sql += "'"; 00375 } 00376 { 00377 char slask[200]; 00378 sprintf(slask,", sz=%ld",this -> sz); 00379 sql += slask; 00380 } 00381 sql += ", sha1='" + q.safestr(this -> sha1) + "'"; 00382 { 00383 char slask[200]; 00384 sprintf(slask," where num='%ld'",i_num); 00385 sql += slask; 00386 } 00387 q.execute(sql); 00388 }

void db::Item::update  ) 
 

Definition at line 343 of file libfd.cpp.

References num.

Referenced by save().

00344 { 00345 update(this -> num); 00346 }

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

Definition at line 436 of file libfd.cpp.

References category, database, name, num, sha1, sz, and typ.

00437 { 00438 Query q(*database); 00439 std::string dest; 00440 char slask[200]; 00441 dest = "<ITEM " + tag + "=\"" + xvalx + "\">"; 00442 sprintf(slask,"<NUM>%ld</NUM>",this -> num); 00443 dest += slask; 00444 dest += "<TYP>" + q.xmlsafestr(this -> typ.String()) + "</TYP>"; 00445 sprintf(slask,"<CATEGORY>%ld</CATEGORY>",this -> category); 00446 dest += slask; 00447 dest += "<NAME>" + q.xmlsafestr(this -> name) + "</NAME>"; 00448 sprintf(slask,"<SZ>%ld</SZ>",this -> sz); 00449 dest += slask; 00450 dest += "<SHA1>" + q.xmlsafestr(this -> sha1) + "</SHA1>"; 00451 dest += "</ITEM>"; 00452 return dest; 00453 }

std::string db::Item::xml  ) 
 

Definition at line 416 of file libfd.cpp.

References category, database, name, num, sha1, sz, and typ.

00417 { 00418 Query q(*database); 00419 std::string dest; 00420 char slask[200]; 00421 dest = "<ITEM>"; 00422 sprintf(slask,"<NUM>%ld</NUM>",this -> num); 00423 dest += slask; 00424 dest += "<TYP>" + q.xmlsafestr(this -> typ.String()) + "</TYP>"; 00425 sprintf(slask,"<CATEGORY>%ld</CATEGORY>",this -> category); 00426 dest += slask; 00427 dest += "<NAME>" + q.xmlsafestr(this -> name) + "</NAME>"; 00428 sprintf(slask,"<SZ>%ld</SZ>",this -> sz); 00429 dest += slask; 00430 dest += "<SHA1>" + q.xmlsafestr(this -> sha1) + "</SHA1>"; 00431 dest += "</ITEM>"; 00432 return dest; 00433 }


Member Data Documentation

long db::Item::category
 

Definition at line 112 of file libfd.h.

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

std::vector<std::string> db::Item::data
 

Definition at line 114 of file libfd.h.

Referenced by form_input(), insert(), MyMinionSocket::OnVerifiedLine(), run(), spawn(), and update().

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

Definition at line 125 of file libfd.h.

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

std::map<std::string, uint64_t> db::Item::mmap_typ [private]
 

Definition at line 92 of file libfd.h.

Referenced by clear().

std::string db::Item::name
 

Definition at line 113 of file libfd.h.

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

short db::Item::new_object [private]
 

Definition at line 126 of file libfd.h.

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

long db::Item::num
 

Definition at line 110 of file libfd.h.

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

std::string db::Item::sha1
 

Definition at line 116 of file libfd.h.

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

long db::Item::sz
 

Definition at line 115 of file libfd.h.

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

enum_t db::Item::typ
 

Definition at line 111 of file libfd.h.

Referenced by 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