aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-06-23 15:27:54 -0400
committerShadowNinja <shadowninja@minetest.net>2014-06-23 15:36:45 -0400
commit50127510e72732b069be040db2d2bbdad4d0be1c (patch)
treedb96476a583600f4221cfc2b7d609d11f4e6482a /src
parentd9de29fa50a7d264d68f2530f0b57ada0f8b4903 (diff)
downloadminetest-50127510e72732b069be040db2d2bbdad4d0be1c.tar.gz
minetest-50127510e72732b069be040db2d2bbdad4d0be1c.tar.bz2
minetest-50127510e72732b069be040db2d2bbdad4d0be1c.zip
Remove confusing code block from SQLite3 database
Diffstat (limited to 'src')
-rw-r--r--src/database-sqlite3.cpp80
1 files changed, 38 insertions, 42 deletions
diff --git a/src/database-sqlite3.cpp b/src/database-sqlite3.cpp
index 268687c20..7f7850719 100644
--- a/src/database-sqlite3.cpp
+++ b/src/database-sqlite3.cpp
@@ -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();
+ 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");
+ }
- 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");
- }
+ if(needs_create)
+ createDatabase();
- 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");
- }
+ 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, "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 `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, "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");
- }
+ 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");
+ }
- infostream<<"ServerMap: SQLite3 database opened"<<std::endl;
+ 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)