mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
Remove confusing code block from SQLite3 database
This commit is contained in:
parent
d9de29fa50
commit
50127510e7
@ -86,58 +86,54 @@ void Database_SQLite3::verifyDatabase() {
|
||||
if(m_database)
|
||||
return;
|
||||
|
||||
{
|
||||
std::string dbp = m_savedir + DIR_DELIM + "map.sqlite";
|
||||
bool needs_create = false;
|
||||
int d;
|
||||
std::string dbp = m_savedir + DIR_DELIM "map.sqlite";
|
||||
bool needs_create = false;
|
||||
int d;
|
||||
|
||||
/*
|
||||
Open the database connection
|
||||
*/
|
||||
// Open the database connection
|
||||
|
||||
createDirs(m_savedir); // ?
|
||||
createDirs(m_savedir); // ?
|
||||
|
||||
if(!fs::PathExists(dbp))
|
||||
needs_create = true;
|
||||
if(!fs::PathExists(dbp))
|
||||
needs_create = true;
|
||||
|
||||
d = sqlite3_open_v2(dbp.c_str(), &m_database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
|
||||
if(d != SQLITE_OK) {
|
||||
infostream<<"WARNING: SQLite3 database failed to open: "<<sqlite3_errmsg(m_database)<<std::endl;
|
||||
throw FileNotGoodException("Cannot open database file");
|
||||
}
|
||||
|
||||
if(needs_create)
|
||||
createDatabase();
|
||||
|
||||
std::string querystr = std::string("PRAGMA synchronous = ")
|
||||
+ itos(g_settings->getU16("sqlite_synchronous"));
|
||||
d = sqlite3_exec(m_database, querystr.c_str(), NULL, NULL, NULL);
|
||||
if(d != SQLITE_OK) {
|
||||
infostream<<"WARNING: Database pragma set failed: "
|
||||
<<sqlite3_errmsg(m_database)<<std::endl;
|
||||
throw FileNotGoodException("Cannot set pragma");
|
||||
}
|
||||
|
||||
d = sqlite3_prepare(m_database, "SELECT `data` FROM `blocks` WHERE `pos`=? LIMIT 1", -1, &m_database_read, NULL);
|
||||
if(d != SQLITE_OK) {
|
||||
infostream<<"WARNING: SQLite3 database read statment failed to prepare: "<<sqlite3_errmsg(m_database)<<std::endl;
|
||||
throw FileNotGoodException("Cannot prepare read statement");
|
||||
}
|
||||
|
||||
d = sqlite3_prepare(m_database, "REPLACE INTO `blocks` VALUES(?, ?)", -1, &m_database_write, NULL);
|
||||
if(d != SQLITE_OK) {
|
||||
infostream<<"WARNING: SQLite3 database write statment failed to prepare: "<<sqlite3_errmsg(m_database)<<std::endl;
|
||||
throw FileNotGoodException("Cannot prepare write statement");
|
||||
}
|
||||
|
||||
d = sqlite3_prepare(m_database, "SELECT `pos` FROM `blocks`", -1, &m_database_list, NULL);
|
||||
if(d != SQLITE_OK) {
|
||||
infostream<<"WARNING: SQLite3 database list statment failed to prepare: "<<sqlite3_errmsg(m_database)<<std::endl;
|
||||
throw FileNotGoodException("Cannot prepare read statement");
|
||||
}
|
||||
|
||||
infostream<<"ServerMap: SQLite3 database opened"<<std::endl;
|
||||
d = sqlite3_open_v2(dbp.c_str(), &m_database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
|
||||
if(d != SQLITE_OK) {
|
||||
infostream<<"WARNING: SQLite3 database failed to open: "<<sqlite3_errmsg(m_database)<<std::endl;
|
||||
throw FileNotGoodException("Cannot open database file");
|
||||
}
|
||||
|
||||
if(needs_create)
|
||||
createDatabase();
|
||||
|
||||
std::string querystr = std::string("PRAGMA synchronous = ")
|
||||
+ itos(g_settings->getU16("sqlite_synchronous"));
|
||||
d = sqlite3_exec(m_database, querystr.c_str(), NULL, NULL, NULL);
|
||||
if(d != SQLITE_OK) {
|
||||
infostream<<"WARNING: Database pragma set failed: "
|
||||
<<sqlite3_errmsg(m_database)<<std::endl;
|
||||
throw FileNotGoodException("Cannot set pragma");
|
||||
}
|
||||
|
||||
d = sqlite3_prepare(m_database, "SELECT `data` FROM `blocks` WHERE `pos`=? LIMIT 1", -1, &m_database_read, NULL);
|
||||
if(d != SQLITE_OK) {
|
||||
infostream<<"WARNING: SQLite3 database read statment failed to prepare: "<<sqlite3_errmsg(m_database)<<std::endl;
|
||||
throw FileNotGoodException("Cannot prepare read statement");
|
||||
}
|
||||
|
||||
d = sqlite3_prepare(m_database, "REPLACE INTO `blocks` VALUES(?, ?)", -1, &m_database_write, NULL);
|
||||
if(d != SQLITE_OK) {
|
||||
infostream<<"WARNING: SQLite3 database write statment failed to prepare: "<<sqlite3_errmsg(m_database)<<std::endl;
|
||||
throw FileNotGoodException("Cannot prepare write statement");
|
||||
}
|
||||
|
||||
d = sqlite3_prepare(m_database, "SELECT `pos` FROM `blocks`", -1, &m_database_list, NULL);
|
||||
if(d != SQLITE_OK) {
|
||||
infostream<<"WARNING: SQLite3 database list statment failed to prepare: "<<sqlite3_errmsg(m_database)<<std::endl;
|
||||
throw FileNotGoodException("Cannot prepare read statement");
|
||||
}
|
||||
|
||||
infostream<<"ServerMap: SQLite3 database opened"<<std::endl;
|
||||
}
|
||||
|
||||
void Database_SQLite3::saveBlock(MapBlock *block)
|
||||
|
Loading…
Reference in New Issue
Block a user