/* Minetest Copyright (C) 2013 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* SQLite format specification: - Initially only replaces sectors/ and sectors2/ If map.sqlite does not exist in the save dir or the block was not found in the database the map will try to load from sectors folder. In either case, map.sqlite will be created and all future saves will save there. Structure of map.sqlite: Tables: blocks (PK) INT pos BLOB data */ #include "database-sqlite3.h" #include "map.h" #include "mapsector.h" #include "mapblock.h" #include "serialization.h" #include "main.h" #include "settings.h" #include "log.h" #include "filesys.h" Database_SQLite3::Database_SQLite3(ServerMap *map, std::string savedir) { m_database = NULL; m_database_read = NULL; m_database_write = NULL; m_database_list = NULL; m_database_delete = NULL; m_savedir = savedir; srvmap = map; } int Database_SQLite3::Initialized(void) { return m_database ? 1 : 0; } void Database_SQLite3::beginSave() { verifyDatabase(); if(sqlite3_exec(m_database, "BEGIN;", NULL, NULL, NULL) != SQLITE_OK) errorstream<<"WARNING: beginSave() failed, saving might be slow."; } void Database_SQLite3::endSave() { verifyDatabase(); if(sqlite3_exec(m_database, "COMMIT;", NULL, NULL, NULL) != SQLITE_OK) errorstream<<"WARNING: endSave() failed, map might not have saved."; } void Database_SQLite3::createDirs(std::string path) { if(fs::CreateAllDirs(path) == false) { infostream< &dst) { verifyDatabase(); while(sqlite3_step(m_database_list) == SQLITE_ROW) { sqlite3_int64 block_i = sqlite3_column_int64(m_database_list, 0); v3s16 p = getIntegerAsBlock(block_i); //dstream<<"block_i="<