Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

MysqlDb Class Reference

#include <MysqlDb.h>

List of all members.

Public Member Functions

 MysqlDb ()
virtual ~MysqlDb ()
virtual bool Connect (const char *aHost, const char *aUser, const char *aPasswd, const char *aDb, const int aPort=0)
virtual bool reConnect ()
virtual unsigned NbRows ()
virtual unsigned NbFields ()
virtual void Release ()
virtual char * printQuery ()
virtual bool InputStart (const char *aName, StDbBuffer *aBuff, const char *colList, int nRows, bool &hasBinary)
virtual bool InputRow (StDbBuffer *aBuff, int row)
virtual bool InputEnd ()
virtual bool Input (const char *aName, StDbBuffer *aBuff)
virtual bool Output (StDbBuffer *aBuff)
MysqlDboperator<< (const char *c)
MysqlDboperator<< (const string s)
MysqlDboperator<< (const MysqlBin *aBin)
MysqlDboperator<< (const short aq)
MysqlDboperator<< (const unsigned short aq)
MysqlDboperator<< (const int aq)
MysqlDboperator<< (const unsigned int aq)
MysqlDboperator<< (const long long aq)
MysqlDboperator<< (const float aq)
MysqlDboperator<< (const double aq)
char ** DecodeStrArray (char *strinput, int &aLen)
char * CodeStrArray (char **strarr, int aLen)
virtual int GetLastInsertID ()
virtual bool QueryStatus ()
virtual bool checkForTable (const char *tableName)
virtual void Close ()
virtual bool IsConnected ()
virtual bool setDefaultDb (const char *dbName)

Public Attributes

bool mlogTime
StDbLogger mqueryLog
StDbLogger msocketLog
StDbLogger mconnectLog
StDbManagerImplmy_manager

Protected Member Functions

virtual void RazQuery ()
virtual bool ExecQuery ()

Private Member Functions

std::vector< std::string
>::iterator 
RecommendedServer (std::vector< std::string > *ListToUse, char *socket, int port)

Private Attributes

MYSQL mData
char * mQuery
unsigned long int mQueryLen
char * mQueryLast
MysqlResultmRes
bool mqueryState
bool mhasConnected
bool mhasBinaryQuery
char * mdbhost
char * mdbName
char * mdbuser
char * mdbpw
int mdbPort
char * mdbServerVersion
unsigned int mtimeout
int jfields
char * cnames [200]
bool isBlob [200]
bool isBinary [200]
bool isSpecialType [200]


Constructor & Destructor Documentation

MysqlDb::MysqlDb  ) 
 

Definition at line 213 of file MysqlDb.cc.

00213 : mdbhost(0), mdbName(NULL), mdbuser(0), mdbpw(0), mdbPort(0),mdbServerVersion(0),mlogTime(false) { 00214 00215 mhasConnected=false; 00216 mhasBinaryQuery=false; 00217 mtimeout=1; 00218 mQuery=0; 00219 mQueryLast=0; 00220 mRes= new MysqlResult; 00221 for(int i=0;i<200;i++)cnames[i]=0; 00222 }

MysqlDb::~MysqlDb  )  [virtual]
 

Definition at line 225 of file MysqlDb.cc.

00225 { 00226 if(mQuery) delete [] mQuery; 00227 if(mQueryLast) delete [] mQueryLast; 00228 Release(); 00229 if(mRes) delete mRes; 00230 if(mhasConnected)mysql_close(&mData); 00231 if(mdbhost) delete [] mdbhost; 00232 if(mdbuser) delete [] mdbuser; 00233 if(mdbpw) delete [] mdbpw; 00234 if(mdbName) delete [] mdbName; 00235 if(mdbServerVersion) delete [] mdbServerVersion; 00236 00237 }


Member Function Documentation

bool MysqlDb::checkForTable const char *  tableName  )  [virtual]
 

Definition at line 429 of file MysqlDb.cc.

00429 { 00430 00431 mRes->Release(); 00432 mRes->mRes=mysql_list_tables(&mData,tableName); 00433 if(mRes->mRes==NULL) return false; 00434 mRes->Release(); 00435 00436 return true; 00437 };

void MysqlDb::Close  )  [inline, virtual]
 

Definition at line 286 of file MysqlDb.h.

00286 { 00287 if(mhasConnected)mysql_close(&mData); 00288 mhasConnected=false; 00289 }

char * MysqlDb::CodeStrArray char **  strarr,
int  aLen
 

Definition at line 829 of file MysqlDb.cc.

00829 { 00830 int tMaxLen=0; 00831 int i; 00832 for (i=0;i<aLen;i++) { 00833 if (strarr[i]) tMaxLen=tMaxLen+strlen(strarr[i])*2; 00834 tMaxLen++; 00835 }; 00836 char* tTempVal=new char[tMaxLen+1]; 00837 char* tRead; 00838 char* tWrite=tTempVal; 00839 for (i=0;i<aLen;i++) { 00840 if (strarr[i]){ 00841 int j; 00842 tRead=strarr[i]; 00843 for (j=0;j<(int)strlen(strarr[i]);j++) { 00844 if (*tRead=='\\'||*tRead==',') { 00845 *tWrite='\\'; 00846 tWrite++; 00847 }; 00848 *tWrite=*tRead; 00849 tWrite++; 00850 tRead++; 00851 }; 00852 }; 00853 *tWrite=','; 00854 tWrite++; 00855 }; 00856 tWrite--; 00857 *tWrite='\0'; 00858 char *tRetVal=new char[strlen(tTempVal)+1]; 00859 strcpy(tRetVal,tTempVal); 00860 if (tTempVal) delete [] tTempVal; 00861 return tRetVal; 00862 };

bool MysqlDb::Connect const char *  aHost,
const char *  aUser,
const char *  aPasswd,
const char *  aDb,
const int  aPort = 0
[virtual]
 

Definition at line 328 of file MysqlDb.cc.

00328 { 00329 #define __METHOD__ "Connect(host,user,pw,database,port)" 00330 00331 if(mdbhost) delete [] mdbhost; 00332 mdbhost = new char[strlen(aHost)+1]; 00333 strcpy(mdbhost,aHost); 00334 00335 if(aUser){ 00336 if(mdbuser) delete [] mdbuser; 00337 mdbuser = new char[strlen(aUser)+1]; strcpy(mdbuser,aUser); 00338 } 00339 if(aPasswd){ 00340 if(mdbpw) delete [] mdbpw; 00341 mdbpw = new char[strlen(aPasswd)+1]; strcpy(mdbpw,aPasswd); 00342 } 00343 mdbPort = aPort; 00344 // cout << "aHost = "<<mdbhost<<endl; 00345 //cout << " Calling load balancer\n"; 00346 clock_t start,finish; 00347 double lbtime; 00348 start = clock(); 00349 00350 std::vector<std::string>::iterator myserver = RecommendedServer(&(my_manager->xmlServerList), NULL, mdbPort); 00351 strcpy(mdbhost,(*myserver).c_str()); 00352 00353 finish = clock(); 00354 lbtime = (double(finish)-double(start))/CLOCKS_PER_SEC*1000; 00355 cout << " Load balancer took "<<lbtime<<" ms, will use "<<mdbhost<<" \n"; 00356 00357 if(mdbName) { 00358 delete [] mdbName; 00359 mdbName=NULL; 00360 } 00361 if(aDb && (strcmp(aDb," ")!=0)){ 00362 mdbName = new char[strlen(aDb)+1]; 00363 strcpy(mdbName,aDb); 00364 } 00365 00366 bool tRetVal = false; 00367 double t0=mqueryLog.wallTime(); 00368 if(mlogTime)mconnectLog.start(); 00369 if (!mysql_init(&mData)) 00370 return (bool) StDbManager::Instance()->printInfo("Mysql Init Error=",mysql_error(&mData),dbMErr,__LINE__,__CLASS__,__METHOD__); 00371 00372 // char *connString; 00373 StString cs; 00374 if(reConnect()){ 00375 // if(mysql_real_connect(&mData,aHost,aUser,aPasswd,bDb,aPort,NULL,0)){ 00376 t0=mqueryLog.wallTime()-t0; 00377 cs<< "Server Connecting:"; if(mdbName)cs<<" DB=" << mdbName ; 00378 cs<< " Host=" << mdbhost <<":"<<aPort <<stendl; 00379 cs<< " --> Connection Time="<<t0<<" sec "; 00380 if(mdbServerVersion)cs<<" MysqlVersion="<<mdbServerVersion; 00381 00382 StDbManager::Instance()->printInfo((cs.str()).c_str(),dbMConnect,__LINE__,__CLASS__,__METHOD__); 00383 tRetVal=true; 00384 } else { 00385 cs << "Making Connection to DataBase = " << aDb; 00386 cs << " On Host = " << mdbhost <<":"<<aPort; 00387 cs << " MySQL returned error " << mysql_error(&mData); 00388 StDbManager::Instance()->printInfo((cs.str()).c_str(),dbMConnect,__LINE__,__CLASS__,__METHOD__); 00389 } 00390 00391 if(mlogTime)mconnectLog.end(); 00392 mhasConnected = tRetVal; 00393 return tRetVal; 00394 #undef __METHOD__ 00395 }

char ** MysqlDb::DecodeStrArray char *  strinput,
int &  aLen
 

Definition at line 767 of file MysqlDb.cc.

00767 { 00768 00769 if(!strinput){ // shouldn't happen - should have checked before here 00770 // cout<< "null input string from mysql " << endl; 00771 char** tmparr = new char*[1]; 00772 aLen = 1; 00773 *tmparr = new char[2]; 00774 strcpy(*tmparr,"0"); 00775 return tmparr; 00776 } 00777 00778 char* tPnt=strinput; 00779 aLen=0; 00780 while (tPnt&&aLen<100) { // 100 is a limit on # comma separated values 00781 tPnt=strpbrk( tPnt,"\\,"); 00782 if (tPnt!=0){ 00783 if (*tPnt==',') { 00784 aLen++;tPnt++; 00785 } else { //(*tPnt=='\\') 00786 tPnt++;tPnt++;}; 00787 }; 00788 }; 00789 aLen++; 00790 char** strarr=new char*[aLen]; 00791 tPnt=strinput; 00792 char* tPntNew=tPnt; 00793 char *tBuff=new char[strlen(strinput)+1]; 00794 char *tBuffInd=tBuff; 00795 int tCount=0; 00796 while (tPntNew) { 00797 tPntNew=strpbrk( tPnt,"\\,"); 00798 if ((tPntNew==0)||*tPntNew==',') { 00799 if (tPntNew==0) { 00800 strcpy(tBuffInd,tPnt); 00801 00802 } else { 00803 strncpy(tBuffInd,tPnt,tPntNew-tPnt); 00804 *(tBuffInd+(tPntNew-tPnt))='\0'; 00805 } 00806 strarr[tCount]=new char[strlen(tBuff)+1]; 00807 strcpy(strarr[tCount],tBuff); 00808 tBuffInd=tBuff; 00809 tPnt=tPntNew+1; 00810 tCount++; 00811 } else { //(*tPntNew=='\\') 00812 strncpy(tBuffInd,tPnt,tPntNew-tPnt); 00813 tBuffInd=tBuffInd+(tPntNew-tPnt); 00814 tPntNew++; 00815 if(*tPntNew=='\\'||*tPntNew==',') { 00816 *tBuffInd=*tPntNew; 00817 tBuffInd++; 00818 }; 00819 *(tBuffInd)='\0'; 00820 tPnt=tPntNew+1; 00821 }; 00822 }; 00823 delete [] tBuff; 00824 return strarr; 00825 }

bool MysqlDb::ExecQuery  )  [protected, virtual]
 

Definition at line 441 of file MysqlDb.cc.

00441 { 00442 #define __METHOD__ "ExecQuery()" 00443 00444 mqueryState=false; 00445 00446 // cout<<"MysqlDb::ExecQuery() "; 00447 // cout<<mQuery<<endl; 00448 00449 if(mlogTime)mqueryLog.start(); 00450 00451 int status=mysql_real_query(&mData,mQuery,mQueryLen); 00452 00453 if( (status!=0) && ( mysql_errno(&mData)==CR_SERVER_GONE_ERROR || mysql_errno(&mData)==CR_SERVER_LOST ) ){ 00454 StDbManager::Instance()->printInfo(mysql_error(&mData)," Lost server, will try to reconnect",dbMDebug,__LINE__,__CLASS__,__METHOD__); 00455 if(reConnect())status=mysql_real_query(&mData,mQuery,mQueryLen); 00456 } 00457 00458 if(status!=0) 00459 return StDbManager::Instance()->printInfo(" Query Failed ",mysql_error(&mData),dbMErr,__LINE__,__CLASS__,__METHOD__); 00460 00461 if(mlogTime)mqueryLog.end(); 00462 mRes->Release(); 00463 00464 if(mlogTime)msocketLog.start(); 00465 mRes->mRes=mysql_store_result(&mData); 00466 if(mlogTime)msocketLog.end(); 00467 00468 return mqueryState=true; 00469 }

virtual int MysqlDb::GetLastInsertID  )  [inline, virtual]
 

Definition at line 264 of file MysqlDb.h.

00264 { return (int)mysql_insert_id(&mData);}

bool MysqlDb::Input const char *  aName,
StDbBuffer aBuff
[virtual]
 

Definition at line 627 of file MysqlDb.cc.

00627 { 00628 bool tRetVal=false; 00629 bool change=aBuff->IsClientMode(); 00630 if (change) aBuff->SetStorageMode(); 00631 aBuff->SetStorageMode(); 00632 if (aBuff) { 00633 *this << "select * from " << table << " where null"<< endsql; 00634 *this << "insert into " << table << " set "; 00635 bool tFirst=true; 00636 char* tVal;tVal=0; 00637 int len; 00638 unsigned i; 00639 00640 for (i=0;i<NbFields();i++) { 00641 if ((IS_BLOB(mRes->mRes->fields[i].flags) ) || 00642 mRes->mRes->fields[i].type ==254) { 00643 if (mRes->mRes->fields[i].flags&BINARY_FLAG) { // Binary 00644 if (aBuff->ReadArray(tVal,len,mRes->mRes->fields[i].name)){ 00645 if (tFirst) { 00646 tFirst=false; 00647 } else { 00648 *this << ","; 00649 }; 00650 *this << mRes->mRes->fields[i].name << "='" << Binary(len,(float*)tVal)<<"'"; 00651 }; 00652 }else{ // text types 00653 if(mRes->mRes->fields[i].type==254){ 00654 if (aBuff->ReadScalar(tVal,mRes->mRes->fields[i].name)) { 00655 if (tFirst) { 00656 tFirst=false; 00657 } else { 00658 *this << ","; 00659 }; 00660 *this << mRes->mRes->fields[i].name << "='" << tVal << "'"; 00661 }; 00662 } else { 00663 char** tVal2=0; 00664 if (aBuff->ReadArray(tVal2,len,mRes->mRes->fields[i].name)){ 00665 tVal=CodeStrArray(tVal2,len); 00666 int j;for (j=0;j<len;j++) {if (tVal2[j]) delete [] tVal2[j];}; 00667 delete [] tVal2; 00668 if (tFirst) { 00669 tFirst=false; 00670 } else { 00671 *this << ","; 00672 }; 00673 *this << mRes->mRes->fields[i].name << "='" << tVal<<"'"; 00674 } 00675 }; 00676 }; 00677 } else { // not binary nor text 00678 if (aBuff->ReadScalar(tVal,mRes->mRes->fields[i].name)) { 00679 if (tFirst) { 00680 tFirst=false; 00681 } else { 00682 *this << ","; 00683 }; 00684 *this << mRes->mRes->fields[i].name << "='" << tVal << "'"; 00685 }; 00686 }; 00687 if (tVal) delete [] tVal;tVal=0; 00688 }; 00689 if (tFirst) { 00690 RazQuery(); 00691 } else { 00692 *this << endsql; 00693 if(mqueryState)tRetVal=true; 00694 }; 00695 }; 00696 // if (!tRetVal) cout << "insert Failed"<< endl; 00697 if (change) aBuff->SetClientMode(); 00698 aBuff->SetClientMode(); 00699 return tRetVal; 00700 };

bool MysqlDb::InputEnd  )  [virtual]
 

Definition at line 617 of file MysqlDb.cc.

00617 { 00618 00619 bool tRetVal=false; 00620 *this<<")"<<endsql; 00621 if(mqueryState)tRetVal=true; 00622 return tRetVal; 00623 00624 };

bool MysqlDb::InputRow StDbBuffer aBuff,
int  row
[virtual]
 

Definition at line 578 of file MysqlDb.cc.

00578 { 00579 00580 char* tVal;tVal=0; 00581 int len; 00582 aBuff->SetStorageMode(); 00583 if(row>0)*this<<"),("; 00584 int k; 00585 for(k=0;k<jfields;k++){ 00586 if(k!=0)*this<<","; 00587 if(isBlob[k]){ 00588 if(isBinary[k]){ 00589 if(!aBuff->ReadArray(tVal,len,cnames[k]))break; 00590 *this<<"'"<<Binary(len,(float*)tVal)<<"'"; 00591 } else if(isSpecialType[k]) { 00592 if(!aBuff->ReadScalar(tVal,cnames[k]))break; 00593 *this<<"'"<<tVal<<"'"; 00594 } else { 00595 char** tVal2=0; 00596 if(!aBuff->ReadArray(tVal2,len,cnames[k]))break; 00597 tVal=CodeStrArray(tVal2,len); 00598 for(int jj=0;jj<len;jj++)if(tVal2[jj])delete []tVal2[jj]; 00599 *this<<"'"<<tVal<<"'"; 00600 } 00601 } else { 00602 if(!aBuff->ReadScalar(tVal,cnames[k])) break; 00603 *this<<"'"<<tVal<<"'"; 00604 } 00605 } 00606 00607 aBuff->SetClientMode(); 00608 00609 if(k!=jfields){ 00610 RazQuery(); 00611 return false; 00612 } 00613 00614 return true; 00615 }

bool MysqlDb::InputStart const char *  aName,
StDbBuffer aBuff,
const char *  colList,
int  nRows,
bool &  hasBinary
[virtual]
 

Definition at line 519 of file MysqlDb.cc.

00519 { 00520 00521 bool tRetVal=false; 00522 if(!table || !aBuff || !colList) return tRetVal; 00523 00524 bool change=aBuff->IsClientMode(); 00525 if(change) aBuff->SetStorageMode(); 00526 00527 *this << "select * from " << table << " where null"<< endsql; 00528 *this << "insert delayed into " << table << " ("<<colList<<") VALUES("; 00529 int i; 00530 00531 char* tmpString=new char[strlen(colList)+1]; 00532 strcpy(tmpString,colList); 00533 char *ptr1,*ptr2; 00534 jfields=0; 00535 bool done = false; 00536 ptr1=tmpString; 00537 00538 while(!done){ 00539 if((ptr2=strstr(ptr1,","))){ 00540 *ptr2='\0'; 00541 } else { 00542 done=true; 00543 } 00544 if(*ptr1==' ')ptr1++; 00545 if(cnames[jfields]) delete [] cnames[jfields]; 00546 cnames[jfields]=new char[strlen(ptr1)+1]; 00547 strcpy(cnames[jfields],ptr1); 00548 if(!done){ 00549 ptr1=ptr2+1; 00550 *ptr2=','; 00551 } 00552 jfields++; 00553 } 00554 delete [] tmpString; 00555 int nfields=NbFields(); 00556 int fcount=0; 00557 hasBinary=false; 00558 00559 for(int k=0;k<jfields;k++){ 00560 for(i=0;i<nfields;i++) 00561 if(strcmp(mRes->mRes->fields[i].name,cnames[k])==0)break; 00562 00563 if(i==nfields)continue; 00564 fcount++; 00565 isBlob[k]=( (IS_BLOB(mRes->mRes->fields[i].flags)) || 00566 (mRes->mRes->fields[i].type ==254) ); 00567 isBinary[k]= (mRes->mRes->fields[i].flags&BINARY_FLAG); 00568 isSpecialType[k]=(mRes->mRes->fields[i].type ==254); 00569 00570 if(isBinary[k])hasBinary=true; 00571 } 00572 if(fcount!=jfields) done=false; 00573 00574 return done; 00575 00576 };

virtual bool MysqlDb::IsConnected  )  [inline, virtual]
 

Definition at line 268 of file MysqlDb.h.

00268 { return mhasConnected; }

virtual unsigned MysqlDb::NbFields  )  [inline, virtual]
 

Definition at line 235 of file MysqlDb.h.

00235 {if(mqueryState)return mRes->NbFields(); return 0;};

virtual unsigned MysqlDb::NbRows  )  [inline, virtual]
 

Definition at line 234 of file MysqlDb.h.

00234 {if(mqueryState)return mRes->NbRows(); return 0;};

MysqlDb & MysqlDb::operator<< const double  aq  )  [inline]
 

Definition at line 325 of file MysqlDb.h.

00325 { 00326 StString ts; ts<<aq; 00327 return *this<<ts.str(); 00328 }

MysqlDb & MysqlDb::operator<< const float  aq  )  [inline]
 

Definition at line 320 of file MysqlDb.h.

00320 { 00321 StString ts; ts<<aq; 00322 return *this<<ts.str(); 00323 }

MysqlDb & MysqlDb::operator<< const long long  aq  )  [inline]
 

Definition at line 315 of file MysqlDb.h.

00315 { 00316 StString ts; ts<<aq; 00317 return *this<<ts.str(); 00318 }

MysqlDb & MysqlDb::operator<< const unsigned int  aq  )  [inline]
 

Definition at line 310 of file MysqlDb.h.

00310 { 00311 StString ts; ts<<aq; 00312 return *this<<ts.str(); 00313 }

MysqlDb & MysqlDb::operator<< const int  aq  )  [inline]
 

Definition at line 305 of file MysqlDb.h.

00305 { 00306 StString ts; ts<<aq; 00307 return *this<<ts.str(); 00308 }

MysqlDb & MysqlDb::operator<< const unsigned short  aq  )  [inline]
 

Definition at line 300 of file MysqlDb.h.

00300 { 00301 StString ts; ts<<aq; 00302 return *this<<ts.str(); 00303 }

MysqlDb & MysqlDb::operator<< const short  aq  )  [inline]
 

Definition at line 295 of file MysqlDb.h.

00295 { 00296 StString ts; ts<<aq; 00297 return *this<<ts.str(); 00298 }

MysqlDb & MysqlDb::operator<< const MysqlBin aBin  ) 
 

Definition at line 502 of file MysqlDb.cc.

00502 { 00503 00504 mhasBinaryQuery=true; 00505 00506 char *tQuery = new char[mQueryLen+aBin->mLen+1]; 00507 memcpy(tQuery,mQuery,mQueryLen); 00508 memcpy(&tQuery[mQueryLen],aBin->mBinData,aBin->mLen+1); // mBinData included null terminator 00509 // tQuery[mQueryLen+aBin->mLen]='\0'; 00510 if(mQuery)delete [] mQuery; 00511 mQuery=tQuery; 00512 mQueryLen=mQueryLen+aBin->mLen; // always not include null terminator 00513 00514 return *this; 00515 };

MysqlDb & MysqlDb::operator<< const string  s  )  [inline]
 

Definition at line 291 of file MysqlDb.h.

00291 { 00292 return *this<<s.c_str(); 00293 }

MysqlDb & MysqlDb::operator<< const char *  c  ) 
 

Definition at line 473 of file MysqlDb.cc.

00473 { 00474 00475 if (strcmp(aQuery,";")==0){ 00476 ExecQuery(); 00477 RazQuery(); 00478 } else { 00479 00480 if(!mQuery){ 00481 mQueryLen=strlen(aQuery); 00482 mQuery = new char[mQueryLen+1]; 00483 strcpy(mQuery,aQuery); 00484 } else { 00485 char* tQuery = new char[strlen(mQuery)+1]; 00486 strcpy(tQuery,mQuery); 00487 delete [] mQuery; 00488 mQuery = new char[mQueryLen+strlen(aQuery)+1]; 00489 memcpy(mQuery,tQuery,mQueryLen); 00490 strcpy(&mQuery[mQueryLen],aQuery); 00491 delete [] tQuery; 00492 mQueryLen=mQueryLen+strlen(aQuery); 00493 } 00494 00495 } 00496 00497 return *this; 00498 }

bool MysqlDb::Output StDbBuffer aBuff  )  [virtual]
 

Definition at line 704 of file MysqlDb.cc.

00704 { 00705 00706 if(mlogTime)msocketLog.start(); 00707 MYSQL_ROW tRow=mysql_fetch_row(mRes->mRes); 00708 if(!tRow) return false; 00709 unsigned long * lengths=mysql_fetch_lengths(mRes->mRes); 00710 unsigned tNbFields=NbFields(); 00711 if(mlogTime)msocketLog.end(); 00712 int i; 00713 bool tRetVal=false; 00714 bool change=aBuff->IsClientMode(); 00715 if (change) aBuff->SetStorageMode(); 00716 aBuff->SetStorageMode(); 00717 00718 for (i=0;i<(int)tNbFields;i++){ 00719 if(tRow[i]){ 00720 00721 // cout <<mRes->mRes->fields[i].name<<" = "<< tRow[i] << endl; 00722 if (IS_BLOB(mRes->mRes->fields[i].flags)) { 00723 if (mRes->mRes->fields[i].flags&BINARY_FLAG) { 00724 aBuff->WriteArray((char*)tRow[i],lengths[i],mRes->mRes->fields[i].name); 00725 }else { 00726 char** tStrPtr; 00727 int len; 00728 tStrPtr=DecodeStrArray((char*)tRow[i],len); 00729 aBuff->WriteArray(tStrPtr,len,mRes->mRes->fields[i].name); 00730 for(int k=0;k<len;k++)delete [] tStrPtr[k]; 00731 delete [] tStrPtr; 00732 00733 // something of a cludge: "," are used in "Decode.." 00734 // as array delimeters. But we also want to have 00735 // char arrays for comment structures - so write'em both 00736 // to the buffer. 00737 00738 //char commentName[1024]; 00739 StString cn; 00740 cn<<mRes->mRes->fields[i].name<<".text"; 00741 aBuff->WriteScalar((char*)tRow[i],(cn.str()).c_str()); 00742 }; 00743 } else { 00744 aBuff->WriteScalar((char*)tRow[i],mRes->mRes->fields[i].name); 00745 }; 00746 } 00747 00748 /* 00749 else { 00750 00751 StString nd; 00752 nd<<"null data returned from table = "; 00753 nd<<mRes->mRes->fields[i].table<<" column="<<mRes->mRes->fields[i].name; 00754 StDbManager::Instance()->printInfo((nd.str()).c_str(),dbMWarn,__LINE__,"MysqlDb","Output(StDbBuffer* b)"); 00755 } 00756 */ 00757 00758 tRetVal=true; 00759 }; 00760 if (change) aBuff->SetClientMode(); 00761 aBuff->SetClientMode(); 00762 return tRetVal; 00763 }

char * MysqlDb::printQuery  )  [virtual]
 

Definition at line 401 of file MysqlDb.cc.

00401 { return mQueryLast; };

virtual bool MysqlDb::QueryStatus  )  [inline, virtual]
 

Definition at line 265 of file MysqlDb.h.

00265 { return mqueryState; }

void MysqlDb::RazQuery  )  [protected, virtual]
 

Definition at line 404 of file MysqlDb.cc.

00404 { 00405 00406 if (mQueryLast){ 00407 delete [] mQueryLast; 00408 mQueryLast=0; 00409 } 00410 if(mhasBinaryQuery){ 00411 mQueryLast = new char[strlen(binaryMessage)+1]; 00412 strcpy(mQueryLast,binaryMessage); 00413 if(mQuery)delete [] mQuery; 00414 } else { 00415 if(mQuery){ 00416 mQueryLast=new char[strlen(mQuery)+1]; 00417 strcpy(mQueryLast,mQuery); 00418 delete [] mQuery; 00419 } 00420 } 00421 00422 mQuery = 0;//new char[1]; 00423 mQueryLen=0; 00424 // strcpy(mQuery,""); 00425 00426 mhasBinaryQuery=false; 00427 }

std::vector<std::string>::iterator MysqlDb::RecommendedServer std::vector< std::string > *  ListToUse,
char *  socket,
int  port
[private]
 

bool MysqlDb::reConnect  )  [virtual]
 

Definition at line 287 of file MysqlDb.cc.

00287 { 00288 #define __METHOD__ "reConnect()" 00289 00290 bool connected=false; 00291 unsigned int timeOutConnect=mtimeout; 00292 while(!connected && timeOutConnect<600){ 00293 mysql_options(&mData,MYSQL_OPT_CONNECT_TIMEOUT,(const char*)&timeOutConnect); 00294 if(mysql_real_connect(&mData,mdbhost,mdbuser,mdbpw,mdbName,mdbPort,NULL,0)) 00295 connected=true; 00296 if(!connected){ 00297 timeOutConnect*=2; 00298 StString wm; 00299 wm<<" Connection Failed with MySQL on "<<mdbhost<<":"<<mdbPort<<stendl; 00300 wm<<" Returned error ="; 00301 wm<<mysql_error(&mData)<<". Will re-try with timeout set at \n==> "; 00302 wm<<timeOutConnect<<" seconds <=="; 00303 StDbManager::Instance()->printInfo((wm.str()).c_str(),dbMConnect,__LINE__,__CLASS__,__METHOD__); 00304 } 00305 } 00306 00307 if(connected){ 00308 if(mdbServerVersion) delete [] mdbServerVersion; 00309 //MPD added 4/28/04 check for valid (not Null) mData.server_version 00310 if(!mData.server_version){ 00311 StString smm; 00312 smm<<" No Server version - most likely incompatable libraries \n CONTACT ADMIN"; 00313 StDbManager::Instance()->printInfo((smm.str()).c_str(),dbMConnect,__LINE__,__CLASS__,__METHOD__); 00314 assert(mData.server_version); 00315 } 00316 //MPD end addition 00317 00318 mdbServerVersion=new char[strlen(mData.server_version)+1]; 00319 strcpy(mdbServerVersion,mData.server_version); 00320 } 00321 00322 return connected; 00323 00324 #undef __METHOD__ 00325 }

virtual void MysqlDb::Release  )  [inline, virtual]
 

Definition at line 236 of file MysqlDb.h.

00236 {mRes->Release();};

bool MysqlDb::setDefaultDb const char *  dbName  )  [virtual]
 

Definition at line 867 of file MysqlDb.cc.

00867 { 00868 00869 if(!dbName || strlen(dbName)==0)return false; 00870 if(mdbName) delete [] mdbName; 00871 mdbName=new char[strlen(dbName)+1]; 00872 strcpy(mdbName,dbName); 00873 if(strcmp(dbName," ")==0)return true; 00874 00875 bool tOk=false; 00876 unsigned int mysqlError; 00877 00878 if(mysql_select_db(&mData,dbName)){ 00879 00880 mysqlError = mysql_errno(&mData); 00881 if(mysqlError==CR_SERVER_GONE_ERROR || mysqlError==CR_SERVER_LOST){ 00882 reConnect(); 00883 if(mysql_select_db(&mData,dbName)){ 00884 cerr<< "Error selecting database=" << dbName << endl; 00885 tOk=false; 00886 } else { 00887 tOk=true; 00888 } 00889 } else { 00890 cerr<< "Error selecting database=" << dbName << endl; 00891 tOk=false; 00892 } 00893 } else { 00894 tOk=true; 00895 } 00896 00897 return tOk; 00898 }


Member Data Documentation

char* MysqlDb::cnames[200] [private]
 

Definition at line 213 of file MysqlDb.h.

bool MysqlDb::isBinary[200] [private]
 

Definition at line 215 of file MysqlDb.h.

bool MysqlDb::isBlob[200] [private]
 

Definition at line 214 of file MysqlDb.h.

bool MysqlDb::isSpecialType[200] [private]
 

Definition at line 216 of file MysqlDb.h.

int MysqlDb::jfields [private]
 

Definition at line 212 of file MysqlDb.h.

StDbLogger MysqlDb::mconnectLog
 

Definition at line 226 of file MysqlDb.h.

MYSQL MysqlDb::mData [private]
 

Definition at line 192 of file MysqlDb.h.

char* MysqlDb::mdbhost [private]
 

Definition at line 201 of file MysqlDb.h.

char* MysqlDb::mdbName [private]
 

Definition at line 202 of file MysqlDb.h.

int MysqlDb::mdbPort [private]
 

Definition at line 205 of file MysqlDb.h.

char* MysqlDb::mdbpw [private]
 

Definition at line 204 of file MysqlDb.h.

char* MysqlDb::mdbServerVersion [private]
 

Definition at line 206 of file MysqlDb.h.

char* MysqlDb::mdbuser [private]
 

Definition at line 203 of file MysqlDb.h.

bool MysqlDb::mhasBinaryQuery [private]
 

Definition at line 199 of file MysqlDb.h.

bool MysqlDb::mhasConnected [private]
 

Definition at line 198 of file MysqlDb.h.

bool MysqlDb::mlogTime
 

Definition at line 223 of file MysqlDb.h.

char* MysqlDb::mQuery [private]
 

Definition at line 193 of file MysqlDb.h.

char* MysqlDb::mQueryLast [private]
 

Definition at line 195 of file MysqlDb.h.

unsigned long int MysqlDb::mQueryLen [private]
 

Definition at line 194 of file MysqlDb.h.

StDbLogger MysqlDb::mqueryLog
 

Definition at line 224 of file MysqlDb.h.

bool MysqlDb::mqueryState [private]
 

Definition at line 197 of file MysqlDb.h.

MysqlResult* MysqlDb::mRes [private]
 

Definition at line 196 of file MysqlDb.h.

StDbLogger MysqlDb::msocketLog
 

Definition at line 225 of file MysqlDb.h.

unsigned int MysqlDb::mtimeout [private]
 

Definition at line 208 of file MysqlDb.h.

StDbManagerImpl* MysqlDb::my_manager
 

Definition at line 271 of file MysqlDb.h.


The documentation for this class was generated from the following files:
Generated on Thu Aug 24 14:45:47 2006 for Doxygen by doxygen 1.3.7