Catch SQLITE_BUSY and try again

This commit is contained in:
Sfan5 2014-03-05 21:46:40 +01:00
parent 393d7e2ac0
commit c497397111

@ -1,5 +1,6 @@
#include "db-sqlite3.h" #include "db-sqlite3.h"
#include <stdexcept> #include <stdexcept>
#include <unistd.h> // for usleep
DBSQLite3::DBSQLite3(const std::string &mapdir) { DBSQLite3::DBSQLite3(const std::string &mapdir) {
@ -24,7 +25,8 @@ std::vector<int64_t> DBSQLite3::getBlockPos() {
if(result == SQLITE_ROW) { if(result == SQLITE_ROW) {
sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0); sqlite3_int64 blocknum = sqlite3_column_int64(statement, 0);
vec.push_back(blocknum); vec.push_back(blocknum);
} } else if (result == SQLITE_BUSY) // Wait some time and try again
usleep(10000);
else else
break; break;
} }
@ -59,8 +61,9 @@ DBBlockList DBSQLite3::getBlocksOnZ(int zPos)
const unsigned char *data = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(statement, 1)); const unsigned char *data = reinterpret_cast<const unsigned char *>(sqlite3_column_blob(statement, 1));
int size = sqlite3_column_bytes(statement, 1); int size = sqlite3_column_bytes(statement, 1);
blocks.push_back(DBBlock(blocknum, std::basic_string<unsigned char>(data, size))); blocks.push_back(DBBlock(blocknum, std::basic_string<unsigned char>(data, size)));
} } else if (result == SQLITE_BUSY) { // Wait some time and try again
else { usleep(10000);
} else {
break; break;
} }
} }