From c6b290c474180e0beec1a1788c0d2a323f00589f Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Thu, 7 Jun 2012 13:14:39 -0700 Subject: [PATCH] Sql binary support for vector. --- database/SqliteDatabase.cpp | 16 ++++++++++++++-- database/SqliteDatabase.h | 1 + database/database.cpp | 12 ++++++++++++ database/database.h | 2 ++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/database/SqliteDatabase.cpp b/database/SqliteDatabase.cpp index d3625e7384..d29374acee 100644 --- a/database/SqliteDatabase.cpp +++ b/database/SqliteDatabase.cpp @@ -3,6 +3,7 @@ #include #include #include + using namespace std; SqliteDatabase::SqliteDatabase(const char* host) : Database(host,"","") @@ -13,8 +14,7 @@ SqliteDatabase::SqliteDatabase(const char* host) : Database(host,"","") void SqliteDatabase::connect() { - -; int rc = sqlite3_open(mHost.c_str(), &mConnection); + int rc = sqlite3_open(mHost.c_str(), &mConnection); if( rc ) { cout << "Can't open database: " << mHost << " " << rc << endl; @@ -155,6 +155,18 @@ int SqliteDatabase::getBinary(int colIndex,unsigned char* buf,int maxSize) return(size); } +std::vector SqliteDatabase::getBinary(int colIndex) +{ + const unsigned char* blob = reinterpret_cast(sqlite3_column_blob(mCurrentStmt, colIndex)); + size_t iSize = sqlite3_column_bytes(mCurrentStmt, colIndex); + std::vector vucResult; + + vucResult.resize(iSize); + std::copy(blob, blob+iSize, vucResult.begin()); + + return vucResult; +} + uint64 SqliteDatabase::getBigInt(int colIndex) { return(sqlite3_column_int64(mCurrentStmt, colIndex)); diff --git a/database/SqliteDatabase.h b/database/SqliteDatabase.h index f615aed578..7cd94f45e1 100644 --- a/database/SqliteDatabase.h +++ b/database/SqliteDatabase.h @@ -36,6 +36,7 @@ public: bool getBool(int colIndex); // returns amount stored in buf int getBinary(int colIndex,unsigned char* buf,int maxSize); + std::vector getBinary(int colIndex); uint64 getBigInt(int colIndex); void escape(const unsigned char* start,int size,std::string& retStr); diff --git a/database/database.cpp b/database/database.cpp index 66c2eb080f..f0148e5949 100644 --- a/database/database.cpp +++ b/database/database.cpp @@ -74,6 +74,18 @@ int Database::getBinary(const char* colName,unsigned char* buf,int maxSize) return(0); } +std::vector Database::getBinary(const char* colName) +{ + int index; + + if (getColNumber(colName,&index)) + { + return getBinary(index); + } + + return std::vector(); +} + uint64 Database::getBigInt(const char* colName) { int index; diff --git a/database/database.h b/database/database.h index 7e94693fbe..4babf93fc6 100644 --- a/database/database.h +++ b/database/database.h @@ -59,6 +59,7 @@ public: 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); uint64 getBigInt(const char* colName); virtual bool getNull(int colIndex)=0; @@ -68,6 +69,7 @@ public: virtual bool getBool(int colIndex)=0; virtual int getBinary(int colIndex,unsigned char* buf,int maxSize)=0; virtual uint64 getBigInt(int colIndex)=0; + virtual std::vector getBinary(int colIndex)=0; // int getSingleDBValueInt(const char* sql); // float getSingleDBValueFloat(const char* sql);