GDBMS 1.0
|
00001 #include "maininclude.h" 00002 #include "listi.h" 00003 #include "settings.h" 00004 #include "hash_table.h" 00005 #include "tr_twin_ht.h" 00006 #include "file_semaphore.h" 00007 #include "some_functions.h" 00008 #include "initial_mode_commands.h" 00009 #include "session_mode_commands.h" 00010 #include "transaction_mode_commands.h" 00011 #include "transaction_mode_commands_types.h" 00012 #include "transaction_mode_commands_nodes.h" 00013 #include "transaction_mode_commands_edges.h" 00014 #include "transaction_mode_commands_find.h" 00015 00016 using namespace std; 00017 00018 hash_table::hash_table(char* table_name, char* folder_name, char* columns, char* columns_searchby, char* unique) 00019 { 00020 this->hash_table(table_name, folder_name, 0, columns, columns_searchby, unique); 00021 } 00022 00023 00024 hash_table::hash_table(char* table_name, char* folder_name, int columns_nr, char* columns, char* columns_searchby, char* unique) 00025 { 00026 char *fullfname=new char[1000]; 00027 fullfname[0]=0; 00028 strcat(fullfname, MAINFOLDER); 00029 strcat(fullfname, folder_name); 00030 00031 char *fullfname1=new char[1000]; 00032 fullfname1[0]=0; 00033 00034 strcat(fullfname1, fullfname); 00035 strcat(fullfname1, "/hash_main.xml"); 00036 this->tblname=table_name; 00037 this->table_folder=folder_name; 00038 transaction_id=0; 00039 00040 if(!FileExists1(fullfname1)){ 00041 //hash tablicata q nqma 00042 char **buf_col; 00043 char **buf_col_sb; 00044 int n1=0, n2=0; 00045 this->split(columns, &n1, &buf_col); 00046 this->split(columns_searchby, &n2, &buf_col_sb); 00047 this->colls_searchby=buf_col_sb; 00048 this->n_cols_sby=n2; 00049 00050 string fullfolder; 00051 fullfolder+=MAINFOLDER; 00052 fullfolder+=folder_name; 00053 mkfolder1(fullfolder); 00054 XMLNode xMainNode=XMLNode::createXMLTopNode("xml"); 00055 XMLNode xNode00=xMainNode.addChild("columns"); 00056 XMLNode xNode01=xMainNode.addChild("info"); 00057 XMLNode xNode010=xNode01.addChild("nrecords"); 00058 xNode010.addText("0"); 00059 XMLNode xNode011=xNode01.addChild("deletedids"); 00060 xNode011.addText(""); 00061 int i=0, j=0; 00062 for(i=0; i<n1; i++){ 00063 XMLNode xi=xNode00.addChild("c"); 00064 xi.addAttribute("seaby", "0"); 00065 xi.addAttribute("name", buf_col[i]); 00066 00067 for(j=0; j<n2; j++){ 00068 if(!strcmp(buf_col[i], buf_col_sb[j])){ 00069 xi.updateAttribute("1", "seaby", "seaby"); 00070 00071 00072 } 00073 00074 } 00075 xMainNode.writeToFile(fullfname1); 00076 00077 00078 00079 this->transaction_folder=""; 00080 00081 for(i=0; i<n1; i++) 00082 if(buf_col[i]) 00083 delete buf_col[i]; 00084 00085 00086 00087 00088 if(buf_col) 00089 delete buf_col; 00090 00091 00092 00093 } 00094 00095 00096 00097 00098 00099 }else{ 00100 //hash tablicata q ima 00101 00102 00103 int i, j; 00104 XMLNode xMainNode; 00105 XMLNode xNode; 00106 XMLNode xNode1, xNode0; 00107 string fullfn; 00108 fullfn=MAINFOLDER; 00109 fullfn+=this->table_folder; 00110 fullfn+="/hash_main.xml"; 00111 xMainNode=XMLNode::parseFile(fullfn.c_str()); 00112 xNode=xMainNode.getChildNode("info"); 00113 xNode0=xMainNode.getChildNode("columns"); 00114 xNode1=xNode.getChildNode("nrecords"); 00115 XMLNode xi; 00116 int nni=xNode0.nChildNode("c"); 00117 char *bbbuf; 00118 int nnn=0; 00119 for(i=0; i<nni; i++){ 00120 xi=xNode0.getChildNode("c"); 00121 bbbuf=xi.getAttribute("seaby"); 00122 if(!strcmp(bbbuf, "1")){ 00123 nnn++; 00124 } 00125 00126 } 00127 00128 char **c_sb=new char *[nnn]; 00129 int p_c_sb=0; 00130 xNode0=xMainNode.getChildNode("columns"); 00131 for(i=0; i<nni; i++){ 00132 xi=xNode0.getChildNode("c"); 00133 bbbuf=xi.getAttribute("seaby"); 00134 if(!strcmp(bbbuf, "1")){ 00135 c_sb[p_c_sb++]=xi.getAttribute("name"); 00136 00137 } 00138 00139 } 00140 this->n_cols_sby=nnn; 00141 this->colls_searchby=c_sb; 00142 00143 00144 00145 } 00146 00147 00148 delete fullfname1; 00149 00150 delete fullfname; 00151 } 00152 00153 hash_table::~hash_table() 00154 { 00155 int i; 00156 for(i=0; i<this->n_cols_sby; i++) 00157 if(colls_searchby[i]) 00158 delete colls_searchby[i]; 00159 00160 if(colls_searchby) 00161 delete colls_searchby; 00162 00163 } 00164 00165 00166 unsigned int hash_table::hash(const string& key) 00167 { 00168 unsigned hashVal = 0; 00169 int l = key.length(); 00170 00171 for (int x = 0; x < l; ++x) 00172 { 00173 hashVal ^= (hashVal << 5) + 00174 (hashVal >> 2) + 00175 key[x]; 00176 } 00177 00178 return hashVal % 300; 00179 } 00180 00181 00182 void hash_table::AddRecord(char* column_names, char* values) 00183 { 00184 int n1=0, n2=0; 00185 int i, j; 00186 char **cols=0; 00187 char **vals=0; 00188 this->split(column_names, &n1, &cols); 00189 this->split(values, &n2, &vals); 00190 XMLParserBase64Tool b64; 00191 00192 00193 00194 00195 if(!(strlen(transaction_folder.c_str())>2)) 00196 { 00197 //ne e v rejim transaction 00198 string ffname; 00199 ffname+=MAINFOLDER; 00200 ffname+=this->table_folder; 00201 ffname += "/hash_main.xml"; 00202 00203 XMLNode xN; 00204 XMLNode xN1; 00205 XMLNode xN2, xN3; 00206 int nid; 00207 xN=XMLNode::parseFile(ffname.c_str()); 00208 xN1=xN.getChildNode("info"); 00209 xN2=xN1.getChildNode("nrecords"); 00210 xN3=xN1.getChildNode("deletedids"); 00211 00212 nid=this->getMAXID(); 00213 00214 00215 XMLNode Newdata; 00216 XMLNode Newdata1; 00217 XMLNode Newdata11; 00218 00219 Newdata=XMLNode::createXMLTopNode("xml"); 00220 Newdata1=Newdata.addChild("records"); 00221 Newdata11=Newdata1.addChild("rec"); 00222 Newdata11.addAttribute("id", inttostr(nid)); 00223 XMLNode NewData111; 00224 00225 00226 00227 for(i=0; i<n1; i++){ 00228 00229 00230 00231 NewData111=Newdata11.addChild(cols[i]); 00232 NewData111.addText(vals[i]); 00233 00234 for(j=0; j<this->n_cols_sby; j++){ 00235 if(!strstr(colls_searchby[j], cols[i])){ 00236 //dobavyame index 00237 string indexfname; 00238 indexfname=MAINFOLDER; 00239 indexfname+=this->table_folder; 00240 indexfname+="/index_"; 00241 indexfname+=colls_searchby[j]; 00242 indexfname+="_"; 00243 indexfname+=inttostr(hash(string(vals[i]))); 00244 indexfname+=".xml"; 00245 if(!FileExists1(indexfname)){ 00246 //no collision 00247 XMLNode no, no1, no2; 00248 no=XMLNode::createXMLTopNode("xml"); 00249 no1=no.addChild("records"); 00250 no2=no1.addChild("rec"); 00251 no2.addAttribute("id", inttostr(nid)); 00252 no2.addText(vals[i]); 00253 no.writeToFile(indexfname.c_str()); 00254 00255 }else{ 00256 //with collision 00257 XMLNode x, x1, x2; 00258 x=XMLNode::parseFile(indexfname.c_str()); 00259 x1=x.getChildNode("records"); 00260 x2=x1.addChild("rec"); 00261 00262 x2.addAttribute("id", inttostr(nid)); 00263 x2.addText(vals[i]); 00264 x.writeToFile(indexfname.c_str()); 00265 00266 } 00267 00268 00269 } 00270 00271 } 00272 00273 00274 00275 00276 } 00277 string datafilename; 00278 datafilename=MAINFOLDER; 00279 datafilename+=this->table_folder; 00280 datafilename+="/data_"; 00281 datafilename+=inttostr(nid); 00282 datafilename+=".xml"; 00283 Newdata.writeToFile(datafilename.c_str()); 00284 00285 00286 00287 00288 00289 00290 00291 }else{ 00292 //v regim transaction 00293 string ffname; 00294 ffname+=MAINFOLDER; 00295 ffname+=this->transaction_folder; 00296 ffname += "/hash_main.xml"; 00297 00298 XMLNode xN; 00299 XMLNode xN1; 00300 XMLNode xN2; 00301 00302 xN=XMLNode::parseFile(ffname.c_str()); 00303 xN1=xN.getChildNode("info"); 00304 xN2=xN1.getChildNode("nrecords"); 00305 int nid=strtoint(xN2.getText())+1; 00306 00307 XMLNode Newdata; 00308 XMLNode Newdata1; 00309 XMLNode Newdata11; 00310 00311 Newdata=XMLNode::createXMLTopNode("xml"); 00312 Newdata1=Newdata.addChild("records"); 00313 Newdata11=Newdata1.addChild("rec"); 00314 Newdata11.addAttribute("id", inttostr(nid)); 00315 XMLNode NewData111; 00316 00317 00318 00319 for(i=0; i<n1; i++){ 00320 00321 00322 00323 NewData111=Newdata11.addChild(cols[i]); 00324 NewData111.addText(vals[i]); 00325 00326 for(j=0; j<this->n_cols_sby; j++){ 00327 if(!strstr(colls_searchby[j], cols[i])){ 00328 //dobavyame index 00329 string indexfname; 00330 indexfname=MAINFOLDER; 00331 indexfname+=this->transaction_folder; 00332 indexfname+="/index_"; 00333 indexfname+=colls_searchby[j]; 00334 indexfname+="_"; 00335 indexfname+=inttostr(hash(string(vals[i]))); 00336 indexfname+=".xml"; 00337 if(!FileExists1(indexfname)){ 00338 //no collision 00339 XMLNode no, no1, no2; 00340 no=XMLNode::createXMLTopNode("xml"); 00341 no1=no.addChild("records"); 00342 no2=no1.addChild("rec"); 00343 no2.addAttribute("id", inttostr(nid)); 00344 no2.addText(vals[i]); 00345 no.writeToFile(indexfname.c_str()); 00346 00347 }else{ 00348 //with collision 00349 XMLNode x, x1, x2; 00350 x=XMLNode::parseFile(indexfname.c_str()); 00351 x1=x.getChildNode("records"); 00352 x2=x1.addChild("rec"); 00353 00354 x2.addAttribute("id", inttostr(nid)); 00355 x2.addText(vals[i]); 00356 x.writeToFile(indexfname.c_str()); 00357 00358 } 00359 00360 00361 } 00362 00363 } 00364 00365 00366 00367 00368 } 00369 string datafilename; 00370 datafilename=MAINFOLDER; 00371 datafilename+=this->transaction_folder; 00372 datafilename+="/data_"; 00373 datafilename+=inttostr(nid); 00374 datafilename+=".xml"; 00375 Newdata.writeToFile(datafilename.c_str()); 00376 //update transaction file 00377 00378 XMLNode xx, xx1, xx2; 00379 string trfname; 00380 trfname+=MAINFOLDER; 00381 trfname+=this->transaction_folder; 00382 trfname+="/trans_changed_ids_"; 00383 trfname+=this->tblname; 00384 trfname+=".xml"; 00385 xx=XMLNode::parseFile(trfname.c_str()); 00386 xx1=xx.getChildNode("ids"); 00387 xx2=xx1.addChild("id"); 00388 xx2.addText(inttostr(nid)); 00389 00390 xx.writeToFile(trfname.c_str()); 00391 00392 00393 00394 00395 00396 } 00397 00398 for(i=0; i<n1; i++) 00399 if(cols[i]) 00400 delete cols[i]; 00401 00402 for(i=0; i<n1; i++) 00403 if(vals[i]) 00404 delete vals[i]; 00405 00406 00407 00408 if(cols) 00409 delete cols; 00410 if(vals) 00411 delete vals; 00412 00413 00414 00415 } 00416 00417 void hash_table::DeleteRecord(char* column_name, char* value) 00418 { 00419 int i, j; 00420 char buf[15]; 00421 for(i=0; i<15; i++) 00422 buf[i]=0; 00423 00424 buf = this->FindRecord(column_name, value, "id"); 00425 if(!buf) 00426 return; 00427 00428 00429 if(this->transaction_id){ 00430 //ima tranzakciya 00431 string trfname; 00432 trfname+=MAINFOLDER; 00433 trfname+=this->transaction_folder; 00434 trfname+="/trans_changed_ids_"; 00435 trfname+=this->tblname; 00436 trfname+=".xml"; 00437 00438 XMLNode x, x1, x2; 00439 x=XMLNode::parseFile(trfname.c_str()); 00440 x1=x.getChildNode("ids"); 00441 int br=x1.nChildNode(); 00442 bool is_in_my_trans=false; 00443 00444 for(i=0; i<br; i++){ 00445 x2=x1.getChildNode("id"); 00446 char *bbuf=0; 00447 bbuf=x2.getText(); 00448 if(!strcmp(buf, bbuf)){ 00449 is_in_my_trans=true; 00450 x2.deleteNodeContent(); 00451 00452 00453 } 00454 if(bbuf) 00455 delete bbuf; 00456 if(is_in_my_trans) 00457 break; 00458 00459 } 00460 if(is_in_my_trans){ 00461 //tova, koeto trqbva da se iztrie e v moqta tranzakciya 00462 00463 00464 }else{ 00465 //tova, koeto tryabva da se iztrie e izvyn moqta tranzakciya 00466 XMLNode x3; 00467 x3=x1.addChild("id"); 00468 x3.addAttribute("del", "1"); 00469 x3.addText(buf); 00470 00471 00472 00473 } 00474 x.writeToFile(trfname.c_str()); 00475 00476 00477 }else{ 00478 //nyama tranzakciya 00479 string ffolder; 00480 ffolder=+MAINFOLDER; 00481 ffolder+=this->table_folder; 00482 string fname=ffolder; 00483 fname+="/data_"; 00484 fname+=buf; 00485 fname+=".xml"; 00486 XMLNode a, a1, a2, a3; 00487 a=XMLNode::parseFile(fname.c_str()); 00488 a1=a.getChildNode("records"); 00489 a2=a1.getChildNode("rec"); 00490 int nr=a2.nChildNode(); 00491 for(i=0; i<nr; i++){ 00492 a3=a2.getChildNode(i); 00493 for(j=0; j<this->n_cols_sby; j++){ 00494 if(!strstr(a3.getName(), colls_searchby[j])){ 00495 //trqbva da iztriya syotvetniya index 00496 XMLNode b, b1, b2, b3; 00497 string ifname=ffolder; 00498 ifname+="/index_"; 00499 ifname+=colls_searchby[j]; 00500 ifname+="_"; 00501 char *bbb=a3.getText(); 00502 char *bbc=inttostr(hash(string(bbb))); 00503 00504 ifname+=bbc; 00505 ifname+=".xml"; 00506 b=XMLNode::parseFile(ifname.c_str()); 00507 b1=b.getChildNode("records"); 00508 if(b1.nChildNode()==1){ 00509 //ako vyv fila ima samo 1 zapis, iztrivame go 00510 string cmd; 00511 cmd+="rm -r "; 00512 cmd+=ifname; 00513 system(cmd.c_str()); 00514 00515 }else{ 00516 //vyv fila ima pove4e zapisi i tryabva da se iztrie samo zasegnatiq zapis 00517 int l; 00518 for(l=0; l<b1.nChildNode("rec"); l++){ 00519 b2=b1.getChildNode("rec"); 00520 char *bbd=0; 00521 bool fnd=false; 00522 bbd=b2.getAttribute("id"); 00523 if(!strcmp(bbd, buf)){ 00524 fnd=true; 00525 b2.deleteNodeContent(); 00526 b.writeToFile(ifname.c_str()); 00527 00528 } 00529 00530 if(bbd) 00531 delete bbd; 00532 if(fnd) 00533 break; 00534 } 00535 00536 } 00537 00538 00539 if(bbb) 00540 delete bbb; 00541 if(bbc) 00542 delete bbc; 00543 00544 00545 00546 00547 00548 } 00549 00550 } 00551 00552 00553 } 00554 00555 00556 00557 00558 00559 string cmd; 00560 cmd+="rm -r "; 00561 cmd+=fname; 00562 system(cmd.c_str()); 00563 00564 string mainfile; 00565 mainfile=ffolder; 00566 mainfile+="/hash_main.xml"; 00567 XMLNode cc, cc1, cc2; 00568 cc=XMLNode::parseFile(mainfile.c_str()); 00569 char * bbe=0; 00570 cc1=cc.getChildNode("info"); 00571 cc2=cc1.getChildNode("deletedids"); 00572 bbe=cc2.getText(); 00573 if(bbe){ 00574 if(strlen(bbe)>0){ 00575 string adddeleted; 00576 adddeleted=bbe; 00577 adddeleted+=";"; 00578 adddeleted+=buf; 00579 00580 cc2.updateText(adddeleted.c_str()); 00581 00582 00583 }else{ 00584 00585 cc2.updateText(buf); 00586 } 00587 00588 }else{ 00589 00590 cc2.updateText(buf); 00591 } 00592 00593 cc.writeToFile(mainfile.c_str()); 00594 00595 00596 00597 if(bbe) 00598 delete bbe; 00599 00600 00601 } 00602 00603 00604 } 00605 00606 char* hash_table::FindRecord(char* where_column_name, char* where_column_value, char* find_column) 00607 { 00608 if(this->transaction_id){ 00609 //transaction mode 00610 return 0; 00611 }else{ 00612 //regular mode 00613 char *retval=0; 00614 string buf; 00615 buf=where_column_value; 00616 int h=this->hash(buf); 00617 string folname; 00618 folname+=MAINFOLDER; 00619 folname+=this->table_folder; 00620 string indfname; 00621 indfname=folname; 00622 indfname+="/_index"; 00623 indfname+=where_column_name; 00624 indfname+="_"; 00625 char *buf1=0; 00626 00627 buf1=inttostr(h); 00628 indfname+=buf1; 00629 indfname+=".xml"; 00630 if(!FileExists1(indfname)) 00631 return 0; 00632 XMLNode x, x1, x2; 00633 x=XMLNode::parseFile(indfname.c_str()); 00634 x1=x.getChildNode("records"); 00635 int nnum=0; 00636 nnum=x1.nChildNode(); 00637 int i, j; 00638 for(i=0; i<nnum; i++) 00639 { 00640 x2=x1.getChildNode(i); 00641 char *buf2=0; 00642 buf2=x2.getText(); 00643 if(!strcmp(buf2, where_column_value)){ 00644 //namereno e syvpadenie 00645 char *buf_id=0; 00646 buf_id=x2.getAttribute("id"); 00647 string datafname; 00648 datafname=folname; 00649 datafname+="/data_"; 00650 datafname+=buf_id; 00651 datafname+=".xml"; 00652 if(!FileExists1(datafname)){ 00653 if(buf_id) 00654 delete buf_id; 00655 00656 return 0; 00657 00658 } 00659 00660 XMLNode y, y1, y2, y3; 00661 y=XMLNode::parseFile(datafname.c_str()); 00662 y1=y.getChildNode("records"); 00663 y2=y1.getChildNode("rec"); 00664 int nnn; 00665 nnn=y2.nChildNode(); 00666 int k; 00667 bool fnd1=0; 00668 for(k=0; k<nnn; k++){ 00669 y3=y2.getChildNode(i); 00670 char *buf5=0; 00671 char *buf6=0; 00672 buf5=y3.getName(); 00673 if(!strcmp(buf5, find_column)){ 00674 //nameren e zapisa 00675 retval=y3.getText(); 00676 fnd1=true; 00677 00678 } 00679 00680 if(buf5) 00681 delete buf5; 00682 if(buf6) 00683 delete buf6; 00684 if(fnd1) 00685 break; 00686 00687 00688 } 00689 if(!fnd1){ 00690 retval=new char[2]; 00691 retval[0]=0; 00692 retval[1]=0; 00693 00694 } 00695 00696 00697 if(buf_id) 00698 delete buf_id; 00699 00700 } 00701 00702 00703 00704 if(buf2) 00705 delete buf2; 00706 if(retval) 00707 break; 00708 } 00709 00710 00711 if(buf1) 00712 delete buf1; 00713 return retval; 00714 00715 00716 } 00717 } 00718 void hash_table::UpdateRecord(char* where_column, char* where_value, char* column_names, char* column_values) 00719 { 00720 /*char *buf=0; 00721 buf=this->FindRecord(where_column, where_value, "id"); 00722 string dfname; 00723 dfname+=MAINFOLDER; 00724 dfname+=this->table_folder; 00725 dfname+="/data_"; 00726 dfname+=buf; 00727 dfname+=".xml"; 00728 if(!FileExists1(dfname)) 00729 return; 00730 00731 XMLNode x, x1, x2, x3; 00732 int i, j; 00733 x=XMLNode::parseFile(dfname.c_str()); 00734 x1=x.getChildNode("records"); 00735 x2=x1.getChildNode("rec"); 00736 int nfilerecs=x2.nChildNode(); 00737 char **cn=0; 00738 char **cv=0; 00739 int nn=0; 00740 this->split(column_names, &nn, &cn); 00741 this->split(column_values, &nn, &cv); 00742 00743 for(i=0; i<nn; i++){ 00744 bool exists=0; 00745 x=XMLNode::parseFile(dfname.c_str()); 00746 x1=x.getChildNode("records"); 00747 x2=x1.getChildNode("rec"); 00748 for(j=0; j<nfilerecs; j++){ 00749 00750 x3=x2.getChildNode(j); 00751 if(!strcmp(x3.getName(), cn[i])){ 00752 x3.updateText(cv[i]); 00753 exists=true; 00754 break; 00755 } 00756 00757 00758 00759 00760 } 00761 if(!exists){ 00762 x2.addAttribute(cn[i], cv[i]); 00763 00764 } 00765 00766 00767 x.writeToFile(dfname.c_str()); 00768 00769 } 00770 00771 00772 for(i=0; i<nn; i++) 00773 if(cn[i]) 00774 delete cn[i]; 00775 00776 for(i=0; i<nn; i++) 00777 if(cv[i]) 00778 delete cv[i]; 00779 if(cn) 00780 delete cn; 00781 if(cv) 00782 delete cv; 00783 00784 00785 00786 00787 if(buf) 00788 delete buf; 00789 */ 00790 string wc; 00791 string wv; 00792 wc=where_column; 00793 wv=where_value; 00794 char *id=this->FindRecord(where_column, where_value, "id"); 00795 if(id){ 00796 this->FindByIdAndReturnColNamesAndValues(id, wc, wv, 0); 00797 this->DeleteRecord("id", id); 00798 int idm=this->getMAXID(); 00799 char *idmstr=inttostr(idm); 00800 if(idmstr){ 00801 //this->AddRecord(wc.c_str(), wv.c_str()); 00802 int nn=0; 00803 char **cn=0; 00804 char **cv=0; 00805 this->split(wc.c_str(), &nn, &cn); 00806 this->split(wv.c_str(), &nn, &cv); 00807 int i; 00808 for(i=0; i<nn; i++){ 00809 if(!strstr(cn[i], "id")){ 00810 delete cv[i]; 00811 cv[i] = new char[strlen(idm)+1]; 00812 cv[i][0]=0; 00813 strcat(cv[i], idmstr); 00814 00815 break; 00816 } 00817 00818 } 00819 string mergedvals; 00820 for(i=0; i<nn; i++){ 00821 mergedvals+=cv[i]; 00822 if(i<nn-1){ 00823 mergedvals+=";"; 00824 } 00825 } 00826 this->AddRecord(wc.c_str(), mergedvals.c_str()); 00827 delete idmstr; 00828 for(i=0; i<nn; i++){ 00829 if(cv[i]) 00830 delete cv[i]; 00831 if(cn[i]) 00832 delete cn[i]; 00833 } 00834 if(cv) 00835 delete cv; 00836 if(cn) 00837 delete cn; 00838 } 00839 00840 delete id; 00841 } 00842 00843 } 00844 00845 int hash_table::getMAXID() 00846 { 00847 int i, j; 00848 string fname; 00849 fname=MAINFOLDER; 00850 fname+=this->table_folder; 00851 fname+="/hash_main.xml"; 00852 int rtv=1; 00853 char** freeids=0; 00854 int nids=0; 00855 XMLNode x1, x2, x3, x4; 00856 x1=XMLNode::parseFile(fname.c_str()); 00857 x2=x1.getChildNode("info"); 00858 x3=x2.getChildNode("nrecords"); 00859 x4=x2.getChildNode("deletedids"); 00860 char *buf0=0; 00861 char *buf1=0; 00862 00863 buf0=x3.getText(); 00864 buf1=x4.getText(); 00865 if(buf1){ 00866 if(strlen(buf1)>0){ 00867 this->split(buf1, &nids, &freeids); 00868 rtv=strtoint(freeids[0]); 00869 00870 00871 00872 goto getmid_endl; 00873 }else{ 00874 00875 } 00876 00877 }else{ 00878 00879 00880 } 00881 rtv=strtoint(x3.getText())+1; 00882 00883 getmid_endl: 00884 00885 00886 if(buf0) 00887 delete buf0; 00888 if(buf1) 00889 delete buf1; 00890 00891 00892 return rtv; 00893 00894 00895 00896 } 00897 void hash_table::FindByIdAndReturnColNamesAndValues(char* id, string& cnames, string& cvalues, char* requested_id=0) 00898 { 00899 string dfile; 00900 dfile=MAINFOLDER; 00901 dfile+=this->table_folder; 00902 dfile+="/data_"; 00903 dfile+=id; 00904 dfile+=".xml"; 00905 XMLNode x, x1, x2, x3; 00906 x=XMLNode::parseFile(dfile.c_str()); 00907 x1=x.getChildNode("records"); 00908 x2=x1.getChildNode("rec"); 00909 int i, n=0; 00910 n=x2.nChildNode(); 00911 for(i=0; i<n; i++){ 00912 x3=x2.getChildNode(i); 00913 char *buf1=0; 00914 char *buf2=0; 00915 00916 buf1=x3.getName(); 00917 buf2=x3.getText(); 00918 if(requested_id&&!strcmp(buf1, "id")){ 00919 cnames+="id"; 00920 cvalues+=requested_id; 00921 }else{ 00922 00923 cnames+=buf1; 00924 cvalues+=buf2; 00925 } 00926 if(i<n-1){ 00927 cnames+=";"; 00928 cvalues+=";"; 00929 00930 } 00931 00932 if(buf1) 00933 delete buf1; 00934 if(buf2) 00935 delete buf2; 00936 00937 } 00938 } 00939 void hash_table::EndTransaction() 00940 { 00941 00942 }