Sql binary support for vector.

This commit is contained in:
Arthur Britto
2012-06-07 13:14:39 -07:00
parent 24c7689808
commit c6b290c474
4 changed files with 29 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
using namespace std; using namespace std;
SqliteDatabase::SqliteDatabase(const char* host) : Database(host,"","") SqliteDatabase::SqliteDatabase(const char* host) : Database(host,"","")
@@ -13,8 +14,7 @@ SqliteDatabase::SqliteDatabase(const char* host) : Database(host,"","")
void SqliteDatabase::connect() void SqliteDatabase::connect()
{ {
int rc = sqlite3_open(mHost.c_str(), &mConnection);
; int rc = sqlite3_open(mHost.c_str(), &mConnection);
if( rc ) if( rc )
{ {
cout << "Can't open database: " << mHost << " " << rc << endl; cout << "Can't open database: " << mHost << " " << rc << endl;
@@ -155,6 +155,18 @@ int SqliteDatabase::getBinary(int colIndex,unsigned char* buf,int maxSize)
return(size); return(size);
} }
std::vector<unsigned char> SqliteDatabase::getBinary(int colIndex)
{
const unsigned char* blob = reinterpret_cast<const unsigned char*>(sqlite3_column_blob(mCurrentStmt, colIndex));
size_t iSize = sqlite3_column_bytes(mCurrentStmt, colIndex);
std::vector<unsigned char> vucResult;
vucResult.resize(iSize);
std::copy(blob, blob+iSize, vucResult.begin());
return vucResult;
}
uint64 SqliteDatabase::getBigInt(int colIndex) uint64 SqliteDatabase::getBigInt(int colIndex)
{ {
return(sqlite3_column_int64(mCurrentStmt, colIndex)); return(sqlite3_column_int64(mCurrentStmt, colIndex));

View File

@@ -36,6 +36,7 @@ public:
bool getBool(int colIndex); bool getBool(int colIndex);
// returns amount stored in buf // returns amount stored in buf
int getBinary(int colIndex,unsigned char* buf,int maxSize); int getBinary(int colIndex,unsigned char* buf,int maxSize);
std::vector<unsigned char> getBinary(int colIndex);
uint64 getBigInt(int colIndex); uint64 getBigInt(int colIndex);
void escape(const unsigned char* start,int size,std::string& retStr); void escape(const unsigned char* start,int size,std::string& retStr);

View File

@@ -74,6 +74,18 @@ int Database::getBinary(const char* colName,unsigned char* buf,int maxSize)
return(0); return(0);
} }
std::vector<unsigned char> Database::getBinary(const char* colName)
{
int index;
if (getColNumber(colName,&index))
{
return getBinary(index);
}
return std::vector<unsigned char>();
}
uint64 Database::getBigInt(const char* colName) uint64 Database::getBigInt(const char* colName)
{ {
int index; int index;

View File

@@ -59,6 +59,7 @@ public:
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);
uint64 getBigInt(const char* colName); uint64 getBigInt(const char* colName);
virtual bool getNull(int colIndex)=0; virtual bool getNull(int colIndex)=0;
@@ -68,6 +69,7 @@ public:
virtual bool getBool(int colIndex)=0; virtual bool getBool(int colIndex)=0;
virtual int getBinary(int colIndex,unsigned char* buf,int maxSize)=0; virtual int getBinary(int colIndex,unsigned char* buf,int maxSize)=0;
virtual uint64 getBigInt(int colIndex)=0; virtual uint64 getBigInt(int colIndex)=0;
virtual std::vector<unsigned char> getBinary(int colIndex)=0;
// int getSingleDBValueInt(const char* sql); // int getSingleDBValueInt(const char* sql);
// float getSingleDBValueFloat(const char* sql); // float getSingleDBValueFloat(const char* sql);