Add getStrBinary to database functions.

This commit is contained in:
Arthur Britto
2012-06-15 20:11:43 -07:00
parent 3ea3feb1c1
commit eb48ea77d7
2 changed files with 56 additions and 33 deletions

View File

@@ -17,68 +17,80 @@ Database::~Database()
bool Database::getNull(const char* colName) bool Database::getNull(const char* colName)
{ {
int index; int index;
if (getColNumber(colName,&index)) if (getColNumber(colName,&index))
{ {
return(getNull(index)); return getNull(index);
} }
return true; return true;
} }
char* Database::getStr(const char* colName,std::string& retStr) char* Database::getStr(const char* colName,std::string& retStr)
{ {
int index; 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) int32 Database::getInt(const char* colName)
{ {
int index; 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) float Database::getFloat(const char* colName)
{ {
int index; 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) bool Database::getBool(const char* colName)
{ {
int index; 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 Database::getBinary(const char* colName,unsigned char* buf,int maxSize)
{ {
int index; int index;
if (getColNumber(colName,&index)) if (getColNumber(colName,&index))
{ {
return(getBinary(index,buf,maxSize)); return(getBinary(index,buf,maxSize));
} }
return(0); return(0);
} }
std::vector<unsigned char> Database::getBinary(const char* colName) std::vector<unsigned char> Database::getBinary(const std::string& strColName)
{ {
int index; int index;
if (getColNumber(colName,&index)) if (getColNumber(strColName.c_str(), &index))
{ {
return getBinary(index); return getBinary(index);
} }
@@ -86,17 +98,23 @@ std::vector<unsigned char> Database::getBinary(const char* colName)
return std::vector<unsigned char>(); return std::vector<unsigned char>();
} }
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) uint64 Database::getBigInt(const char* colName)
{ {
int index; 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 // returns false if can't find col
bool Database::getColNumber(const char* colName,int* retIndex) bool Database::getColNumber(const char* colName,int* retIndex)
@@ -109,7 +127,8 @@ bool Database::getColNumber(const char* colName,int* retIndex)
return(true); return(true);
} }
} }
return(false);
return false;
} }
#if 0 #if 0

View File

@@ -4,6 +4,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "../src/types.h" #include "../src/types.h"
#include "../src/utils.h"
#define SQL_FOREACH(_db, _strQuery) \ #define SQL_FOREACH(_db, _strQuery) \
if ((_db)->executeSQL(_strQuery)) \ if ((_db)->executeSQL(_strQuery)) \
@@ -58,12 +59,15 @@ public:
// get Data from the current row // get Data from the current row
bool getNull(const char* colName); bool getNull(const char* colName);
char* getStr(const char* colName,std::string& retStr); char* getStr(const char* colName,std::string& retStr);
std::string getStrBinary(const std::string& strColName);
int32 getInt(const char* colName); int32 getInt(const char* colName);
float getFloat(const char* colName); float getFloat(const char* colName);
bool getBool(const char* colName); bool getBool(const char* colName);
// returns amount stored in buf // returns amount stored in buf
int getBinary(const char* colName, unsigned char* buf, int maxSize); int getBinary(const char* colName, unsigned char* buf, int maxSize);
std::vector<unsigned char> getBinary(const char* colName); std::vector<unsigned char> getBinary(const std::string& strColName);
uint64 getBigInt(const char* colName); uint64 getBigInt(const char* colName);
virtual bool getNull(int colIndex)=0; virtual bool getNull(int colIndex)=0;