Remove confusing code block from SQLite3 database
authorShadowNinja <shadowninja@minetest.net>
Mon, 23 Jun 2014 19:27:54 +0000 (15:27 -0400)
committerShadowNinja <shadowninja@minetest.net>
Mon, 23 Jun 2014 19:36:45 +0000 (15:36 -0400)
src/database-sqlite3.cpp

index 268687c203c8e7c24352416e907eeba2016cc52b..7f7850719ee4e0116986dcbf5ddd6f3247c3f0d1 100644 (file)
@@ -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)