Saving data to file only in Database::sync()
parent
12b3221144
commit
e5d5d597dd
|
@ -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);
|
||||
}
|
||||
|
|
25
src/db.h
25
src/db.h
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue