mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 17:09:34 -05:00
merge before commit
This commit is contained in:
commit
eb4313fef2
@ -570,7 +570,7 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData* >::iterator mit = msg.begin();
|
||||
|
||||
// start a transaction
|
||||
mDb->execSQL("BEGIN;");
|
||||
mDb->beginTransaction();
|
||||
|
||||
for(; mit != msg.end(); ++mit){
|
||||
|
||||
@ -654,7 +654,7 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
|
||||
}
|
||||
|
||||
// finish transaction
|
||||
bool ret = mDb->execSQL("COMMIT;");
|
||||
bool ret = mDb->commitTransaction();
|
||||
|
||||
for(mit = msg.begin(); mit != msg.end(); ++mit)
|
||||
{
|
||||
@ -685,7 +685,7 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData* >::iterator sit = grp.begin();
|
||||
|
||||
// begin transaction
|
||||
mDb->execSQL("BEGIN;");
|
||||
mDb->beginTransaction();
|
||||
|
||||
for(; sit != grp.end(); ++sit)
|
||||
{
|
||||
@ -769,7 +769,7 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
}
|
||||
}
|
||||
// finish transaction
|
||||
bool ret = mDb->execSQL("COMMIT;");
|
||||
bool ret = mDb->commitTransaction();
|
||||
|
||||
for(sit = grp.begin(); sit != grp.end(); ++sit)
|
||||
{
|
||||
@ -791,7 +791,7 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData* >::iterator sit = grp.begin();
|
||||
|
||||
// begin transaction
|
||||
mDb->execSQL("BEGIN;");
|
||||
mDb->beginTransaction();
|
||||
|
||||
for(; sit != grp.end(); ++sit)
|
||||
{
|
||||
@ -858,7 +858,7 @@ int RsDataService::updateGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
|
||||
mDb->sqlUpdate(GRP_TABLE_NAME, "grpId='" + grpPtr->grpId.toStdString() + "'", cv);
|
||||
}
|
||||
// finish transaction
|
||||
bool ret = mDb->execSQL("COMMIT;");
|
||||
bool ret = mDb->commitTransaction();
|
||||
|
||||
for(sit = grp.begin(); sit != grp.end(); ++sit)
|
||||
{
|
||||
@ -877,7 +877,7 @@ int RsDataService::updateGroupKeys(const RsGxsGroupId& grpId,const RsTlvSecurity
|
||||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
// begin transaction
|
||||
mDb->execSQL("BEGIN;");
|
||||
mDb->beginTransaction();
|
||||
|
||||
/*!
|
||||
* STORE key set
|
||||
@ -895,7 +895,7 @@ int RsDataService::updateGroupKeys(const RsGxsGroupId& grpId,const RsTlvSecurity
|
||||
mDb->sqlUpdate(GRP_TABLE_NAME, "grpId='" + grpId.toStdString() + "'", cv);
|
||||
|
||||
// finish transaction
|
||||
return mDb->execSQL("COMMIT;");
|
||||
return mDb->commitTransaction();
|
||||
}
|
||||
|
||||
bool RsDataService::validSize(RsNxsGrp* grp) const
|
||||
@ -1608,7 +1608,7 @@ int RsDataService::retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std
|
||||
bool RsDataService::locked_updateMessageEntries(const MsgUpdates& updates)
|
||||
{
|
||||
// start a transaction
|
||||
bool ret = mDb->execSQL("BEGIN;");
|
||||
bool ret = mDb->beginTransaction();
|
||||
|
||||
MsgUpdates::const_iterator mit = updates.begin();
|
||||
|
||||
@ -1627,7 +1627,7 @@ bool RsDataService::locked_updateMessageEntries(const MsgUpdates& updates)
|
||||
}
|
||||
}
|
||||
|
||||
ret &= mDb->execSQL("COMMIT;");
|
||||
ret &= mDb->commitTransaction();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -1635,7 +1635,7 @@ bool RsDataService::locked_updateMessageEntries(const MsgUpdates& updates)
|
||||
bool RsDataService::locked_removeMessageEntries(const GxsMsgReq& msgIds)
|
||||
{
|
||||
// start a transaction
|
||||
bool ret = mDb->execSQL("BEGIN;");
|
||||
bool ret = mDb->beginTransaction();
|
||||
|
||||
GxsMsgReq::const_iterator mit = msgIds.begin();
|
||||
|
||||
@ -1653,7 +1653,7 @@ bool RsDataService::locked_removeMessageEntries(const GxsMsgReq& msgIds)
|
||||
}
|
||||
}
|
||||
|
||||
ret &= mDb->execSQL("COMMIT;");
|
||||
ret &= mDb->commitTransaction();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -1661,7 +1661,7 @@ bool RsDataService::locked_removeMessageEntries(const GxsMsgReq& msgIds)
|
||||
bool RsDataService::locked_removeGroupEntries(const std::vector<RsGxsGroupId>& grpIds)
|
||||
{
|
||||
// start a transaction
|
||||
bool ret = mDb->execSQL("BEGIN;");
|
||||
bool ret = mDb->beginTransaction();
|
||||
|
||||
std::vector<RsGxsGroupId>::const_iterator vit = grpIds.begin();
|
||||
|
||||
@ -1672,7 +1672,7 @@ bool RsDataService::locked_removeGroupEntries(const std::vector<RsGxsGroupId>& g
|
||||
mDb->sqlDelete(GRP_TABLE_NAME, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", "");
|
||||
}
|
||||
|
||||
ret &= mDb->execSQL("COMMIT;");
|
||||
ret &= mDb->commitTransaction();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -264,6 +264,32 @@ std::string RetroDb::getKey() const
|
||||
return mKey;
|
||||
}
|
||||
|
||||
bool RetroDb::beginTransaction()
|
||||
{
|
||||
if (!isOpen()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return execSQL("BEGIN;");
|
||||
}
|
||||
|
||||
bool RetroDb::commitTransaction()
|
||||
{
|
||||
if (!isOpen()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return execSQL("COMMIT;");
|
||||
}
|
||||
bool RetroDb::rollbackTransaction()
|
||||
{
|
||||
if (!isOpen()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return execSQL("ROLLBACK;");
|
||||
}
|
||||
|
||||
bool RetroDb::execSQL_bind(const std::string &query, std::list<RetroBind*> ¶mBindings){
|
||||
|
||||
// prepare statement
|
||||
@ -531,6 +557,43 @@ bool RetroDb::sqlUpdate(const std::string &tableName, std::string whereClause, c
|
||||
return execSQL_bind(sqlQuery, paramBindings);
|
||||
}
|
||||
|
||||
bool RetroDb::tableExists(const std::string &tableName)
|
||||
{
|
||||
if (!isOpen()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string sqlQuery = "PRAGMA table_info(" + tableName + ");";
|
||||
|
||||
bool result = false;
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
|
||||
int rc = sqlite3_prepare_v2(mDb, sqlQuery.c_str(), sqlQuery.length(), &stmt, NULL);
|
||||
if (rc == SQLITE_OK) {
|
||||
rc = sqlite3_step(stmt);
|
||||
switch (rc) {
|
||||
case SQLITE_ROW:
|
||||
result = true;
|
||||
break;
|
||||
case SQLITE_DONE:
|
||||
break;
|
||||
default:
|
||||
std::cerr << "RetroDb::tableExists(): Error executing statement (code: " << rc << ")"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
std::cerr << "RetroDb::tableExists(): Error preparing statement\n";
|
||||
std::cerr << "Error code: " << sqlite3_errmsg(mDb)
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
if (stmt) {
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/********************** RetroCursor ************************/
|
||||
|
||||
|
@ -38,8 +38,6 @@
|
||||
|
||||
#include "contentvalue.h"
|
||||
|
||||
|
||||
|
||||
class RetroCursor;
|
||||
|
||||
/*!
|
||||
@ -90,7 +88,23 @@ public:
|
||||
/* modifying db */
|
||||
public:
|
||||
|
||||
/*!
|
||||
* Start transaction
|
||||
* @return true/false
|
||||
*/
|
||||
bool beginTransaction();
|
||||
|
||||
/*!
|
||||
* Commit transaction
|
||||
* @return true/false
|
||||
*/
|
||||
bool commitTransaction();
|
||||
|
||||
/*!
|
||||
* Rollback transaction
|
||||
* @return true/false
|
||||
*/
|
||||
bool rollbackTransaction();
|
||||
|
||||
/*!
|
||||
* To a make query which do not return a result \n
|
||||
@ -153,22 +167,13 @@ public:
|
||||
*/
|
||||
void vacuum();
|
||||
|
||||
|
||||
/*!
|
||||
* Build the "VALUE" part of an insertiong sql query
|
||||
* @param parameter contains place holder query
|
||||
* @param paramBindings
|
||||
* Check if table exist in database
|
||||
* @param tableName table to check
|
||||
* @return true/false
|
||||
*/
|
||||
void buildInsertQueryValue(const std::map<std::string, uint8_t> keyMap, const ContentValue& cv,
|
||||
std::string& parameter, std::list<RetroBind*>& paramBindings);
|
||||
bool tableExists(const std::string& tableName);
|
||||
|
||||
/*!
|
||||
* Build the "VALUE" part of an insertiong sql query
|
||||
* @param parameter contains place holder query
|
||||
* @param paramBindings
|
||||
*/
|
||||
void buildUpdateQueryValue(const std::map<std::string, uint8_t> keyMap, const ContentValue& cv,
|
||||
std::string& parameter, std::list<RetroBind*>& paramBindings);
|
||||
public:
|
||||
|
||||
static const int OPEN_READONLY;
|
||||
@ -179,6 +184,22 @@ private:
|
||||
|
||||
bool execSQL_bind(const std::string &query, std::list<RetroBind*>& blobs);
|
||||
|
||||
/*!
|
||||
* Build the "VALUE" part of an insertiong sql query
|
||||
* @param parameter contains place holder query
|
||||
* @param paramBindings
|
||||
*/
|
||||
void buildInsertQueryValue(const std::map<std::string, uint8_t> keyMap, const ContentValue& cv,
|
||||
std::string& parameter, std::list<RetroBind*>& paramBindings);
|
||||
|
||||
/*!
|
||||
* Build the "VALUE" part of an insertiong sql query
|
||||
* @param parameter contains place holder query
|
||||
* @param paramBindings
|
||||
*/
|
||||
void buildUpdateQueryValue(const std::map<std::string, uint8_t> keyMap, const ContentValue& cv,
|
||||
std::string& parameter, std::list<RetroBind*>& paramBindings);
|
||||
|
||||
private:
|
||||
|
||||
sqlite3* mDb;
|
||||
|
Loading…
Reference in New Issue
Block a user