implemented most of rsdataservice,

updated rsnxsitems with discrete msgs and grp item rather than collection of msgs/grps
added flags header file 
added first declaration of implemented genexchange service (client API interface)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5180 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-05-21 22:07:43 +00:00
parent f05ed342ed
commit add4715da0
16 changed files with 1179 additions and 554 deletions

View file

@ -29,7 +29,13 @@
#include "retrodb.h"
#define RETRODB_DEBUG
//#define RETRODB_DEBUG
void free_blob(void* dat){
char* c = (char*) dat;
delete[] c;
}
const uint8_t ContentValue::BOOL_TYPE = 1;
const uint8_t ContentValue::DATA_TYPE = 2;
@ -217,6 +223,8 @@ bool RetroDb::sqlInsert(const std::string &table, const std::string& nullColumnH
// build values part of insertion
std::string qValues = "VALUES(";
std::ostringstream oStrStream;
uint32_t index = 0;
std::list<RetroDbBlob> blobL;
for(mit=keyTypeMap.begin(); mit!=keyTypeMap.end(); mit++){
@ -246,8 +254,12 @@ bool RetroDb::sqlInsert(const std::string &table, const std::string& nullColumnH
char* value;
uint32_t len;
cv.getAsData(key, len, value);
oStrStream.write(value, len);
qValues += "'" + oStrStream.str() + "'";
RetroDbBlob b;
b.data = value;
b.length = len;
b.index = ++index;
blobL.push_back(b);
qValues += "?"; // parameter
break;
}
case ContentValue::STRING_TYPE:
@ -297,10 +309,81 @@ bool RetroDb::sqlInsert(const std::string &table, const std::string& nullColumnH
#endif
// execute query
execSQL(sqlQuery);
execSQL_bind_blobs(sqlQuery, blobL);
return true;
}
bool RetroDb::execSQL_bind_blobs(const std::string &query, std::list<RetroDbBlob> &blobs){
// prepare statement
sqlite3_stmt* stm = NULL;
#ifdef RETRODB_DEBUG
std::cerr << "Query: " << query << std::endl;
#endif
int rc = sqlite3_prepare_v2(mDb, query.c_str(), query.length(), &stm, NULL);
// check if there are any errors
if(rc != SQLITE_OK){
std::cerr << "RetroDb::execSQL(): Error preparing statement\n";
std::cerr << "Error code: " << sqlite3_errmsg(mDb)
<< std::endl;
return false;
}
std::list<RetroDbBlob>::iterator lit = blobs.begin();
for(; lit != blobs.end(); lit++){
const RetroDbBlob& b = *lit;
sqlite3_bind_blob(stm, b.index, b.data, b.length, free_blob);
}
uint32_t delta = 3;
time_t stamp = time(NULL), now = 0;
bool timeOut = false, ok = false;
while(!timeOut){
rc = sqlite3_step(stm);
if(rc == SQLITE_DONE){
ok = true;
break;
}
if(rc != SQLITE_BUSY){
ok = false;
break;
}
now = time(NULL);
delta = stamp - now;
if(delta > TIME_LIMIT){
ok = false;
timeOut = true;
}
// TODO add sleep so not to waste
// precious cycles
}
if(!ok){
if(rc == SQLITE_BUSY){
std::cerr << "RetroDb::execSQL()\n" ;
std::cerr << "SQL timed out!" << std::endl;
}else{
std::cerr << "RetroDb::execSQL(): Error executing statement (code: " << rc << ")\n";
std::cerr << "Sqlite Error msg: " << sqlite3_errmsg(mDb)
<< std::endl;
}
}
// finalise statement or else db cannot be closed
sqlite3_finalize(stm);
return ok;
}
bool RetroDb::sqlDelete(const std::string &tableName, const std::string &whereClause, const std::string &whereArgs){
@ -641,7 +724,6 @@ ContentValue::ContentValue(){
ContentValue::~ContentValue(){
}
ContentValue::ContentValue(ContentValue &from){

View file

@ -149,6 +149,18 @@ public:
private:
class RetroDbBlob{
public:
char* data;
uint32_t length;
uint32_t index;
};
bool execSQL_bind_blobs(const std::string &query, std::list<RetroDbBlob>& blobs);
private:
sqlite3* mDb;
@ -260,6 +272,8 @@ public:
/*!
* Returns the value of the requested column as a String.
* data returned must be copied, as it is freed after RetroDb
* is closed or destroyed
* @param columnIndex the zero-based index of the target column.
* @return the value of the column as pointer to raw data
*/

View file

@ -1,17 +1,18 @@
/*
* rsversion.h
*
* Created on: Jun 23, 2009
* Author: alexandrut
*/
#include <string>
#define LIB_VERSION "0.5.2a"
#define SVN_REVISION "Revision 4550"
namespace RsUtil {
std::string retroshareVersion();
}
/*
* rsversion.h
*
* Created on: Jun 23, 2009
* Author: alexandrut
*/
#include <string>
#define LIB_VERSION "0.5.2a"
#define SVN_REVISION "Revision: 4974"
namespace RsUtil {
std::string retroshareVersion();
}