Saving data to file only in Database::sync()

master
jachoo 2012-02-18 10:22:47 +01:00
parent 12b3221144
commit e5d5d597dd
3 changed files with 26 additions and 11 deletions

View File

@ -265,11 +265,17 @@ Database::Database(const std::string& file)
//infostream<<"WARNING: Database failed to open: "<<sqlite3_errmsg(m_database)<<std::endl;
throw FileNotGoodException("Cannot create/open database file");
}
//begin first transaction
begin();
}
Database::~Database()
{
tables.clear(); //finalize all queries to tables
commit(); //commit changes
if(m_database)
sqlite3_close(m_database);
}

View File

@ -344,16 +344,11 @@ public:
//if old_names=true, then primary key will have name 'pos' instead of 'id'
ITable& getTable(const std::string& name, bool old_names = false);
//begins a transaction
void begin()
//commits all changes to database and begins a new transaction
void sync()
{
sqlite3_exec(m_database,"BEGIN;", NULL, NULL, NULL);
}
//commits a transaction
void commit()
{
sqlite3_exec(m_database,"COMMIT;", NULL, NULL, NULL);
commit();
begin();
}
//returns true if database was created from scratch (i.e. no database file existed before)
@ -366,6 +361,18 @@ private:
sqlite3* m_database;
std::map<std::string,SharedPtr<ITable> > tables;
bool m_is_new;
//commits a transaction
void commit()
{
sqlite3_exec(m_database,"COMMIT;", NULL, NULL, NULL);
}
//begins a transaction
void begin()
{
sqlite3_exec(m_database,"BEGIN;", NULL, NULL, NULL);
}
};

View File

@ -2813,11 +2813,13 @@ bool ServerMap::loadSectorMeta(v2s16 p2d)
void ServerMap::beginSave() {
m_database->begin();
//m_database->begin();
//m_database->sync();
}
void ServerMap::endSave() {
m_database->commit();
//m_database->commit();
m_database->sync();
}
void ServerMap::saveBlock(MapBlock *block)