diff --git a/database/database.cpp b/database/database.cpp index f0148e594..725af6a2f 100644 --- a/database/database.cpp +++ b/database/database.cpp @@ -5,9 +5,9 @@ Database::Database(const char* host,const char* user,const char* pass) : mNumCol(0) { - mDBPass=pass; - mHost=host; - mUser=user; + mDBPass = pass; + mHost = host; + mUser = user; } Database::~Database() @@ -17,68 +17,80 @@ Database::~Database() bool Database::getNull(const char* colName) { int index; - if(getColNumber(colName,&index)) + + if (getColNumber(colName,&index)) { - return(getNull(index)); + return getNull(index); } + return true; } char* Database::getStr(const char* colName,std::string& retStr) { int index; - if(getColNumber(colName,&index)) + + if (getColNumber(colName,&index)) { - return(getStr(index,retStr)); + return getStr(index,retStr); } - return(NULL); + + return NULL; } int32 Database::getInt(const char* colName) { int index; - if(getColNumber(colName,&index)) + + if (getColNumber(colName,&index)) { - return(getInt(index)); + return getInt(index); } - return(0); + + return 0; } float Database::getFloat(const char* colName) { int index; - if(getColNumber(colName,&index)) + + if (getColNumber(colName,&index)) { - return(getFloat(index)); + return getFloat(index); } - return(0); + + return 0; } bool Database::getBool(const char* colName) { int index; - if(getColNumber(colName,&index)) + + if (getColNumber(colName,&index)) { - return(getBool(index)); + return getBool(index); } - return(0); + + return 0; } int Database::getBinary(const char* colName,unsigned char* buf,int maxSize) { int index; - if(getColNumber(colName,&index)) + + if (getColNumber(colName,&index)) { return(getBinary(index,buf,maxSize)); } + return(0); } -std::vector Database::getBinary(const char* colName) +std::vector Database::getBinary(const std::string& strColName) { int index; - if (getColNumber(colName,&index)) + if (getColNumber(strColName.c_str(), &index)) { return getBinary(index); } @@ -86,37 +98,44 @@ std::vector Database::getBinary(const char* colName) return std::vector(); } +std::string Database::getStrBinary(const std::string& strColName) +{ + // YYY Could eliminate a copy if getStrBinary was a template. + return strCopy(getBinary(strColName.c_str())); +} + uint64 Database::getBigInt(const char* colName) { int index; - if(getColNumber(colName,&index)) + + if (getColNumber(colName,&index)) { - return(getBigInt(index)); + return getBigInt(index); } - return(0); + + return 0; } - - // returns false if can't find col bool Database::getColNumber(const char* colName,int* retIndex) { - for(unsigned int n=0; n #include #include "../src/types.h" +#include "../src/utils.h" #define SQL_FOREACH(_db, _strQuery) \ if ((_db)->executeSQL(_strQuery)) \ @@ -58,12 +59,15 @@ public: // get Data from the current row bool getNull(const char* colName); char* getStr(const char* colName,std::string& retStr); + std::string getStrBinary(const std::string& strColName); int32 getInt(const char* colName); float getFloat(const char* colName); bool getBool(const char* colName); + // returns amount stored in buf - int getBinary(const char* colName,unsigned char* buf,int maxSize); - std::vector getBinary(const char* colName); + int getBinary(const char* colName, unsigned char* buf, int maxSize); + std::vector getBinary(const std::string& strColName); + uint64 getBigInt(const char* colName); virtual bool getNull(int colIndex)=0;