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

@@ -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<unsigned char> Database::getBinary(const char* colName)
std::vector<unsigned char> 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<unsigned char> Database::getBinary(const char* colName)
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)
{
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<mColNameTable.size(); n++)
for (unsigned int n=0; n<mColNameTable.size(); n++)
{
if(strcmp(colName,mColNameTable[n].c_str())==0)
if (strcmp(colName,mColNameTable[n].c_str())==0)
{
*retIndex=n;
return(true);
}
}
return(false);
return false;
}
#if 0
int Database::getSingleDBValueInt(const char* sql)
{
int ret;
if( executeSQL(sql) && startIterRows()
if ( executeSQL(sql) && startIterRows()
{
ret=getInt(0);
endIterRows();
@@ -134,7 +153,7 @@ int Database::getSingleDBValueInt(const char* sql)
float Database::getSingleDBValueFloat(const char* sql)
{
float ret;
if(executeSQL(sql) && startIterRows() && getNextRow())
if (executeSQL(sql) && startIterRows() && getNextRow())
{
ret=getFloat(0);
endIterRows();
@@ -152,7 +171,7 @@ float Database::getSingleDBValueFloat(const char* sql)
char* Database::getSingleDBValueStr(const char* sql,std::string& retStr)
{
char* ret;
if(executeSQL(sql) && startIterRows())
if (executeSQL(sql) && startIterRows())
{
ret=getStr(0,retStr);
endIterRows();

View File

@@ -4,6 +4,7 @@
#include <string>
#include <vector>
#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<unsigned char> getBinary(const char* colName);
int getBinary(const char* colName, unsigned char* buf, int maxSize);
std::vector<unsigned char> getBinary(const std::string& strColName);
uint64 getBigInt(const char* colName);
virtual bool getNull(int colIndex)=0;