mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-25 20:56:40 +00:00 
			
		
		
		
	Use "pragma max_page_count" to define max allowed file size in combination with "pragma page_size" based on a new setting "max navmeshdb file size". * Stop navmeshtool on the first db error. * Disable writes to db in the engine on first "database or disk is full" SQLite3 error. There is no special error code for this error. * Change default "write to navmeshdb" to true. * Use time intervals for transaction duration instead of number of changes.
		
			
				
	
	
		
			34 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include "db.hpp"
 | |
| 
 | |
| #include <sqlite3.h>
 | |
| 
 | |
| #include <stdexcept>
 | |
| #include <string>
 | |
| #include <string_view>
 | |
| 
 | |
| namespace Sqlite3
 | |
| {
 | |
|     void CloseSqlite3::operator()(sqlite3* handle) const noexcept
 | |
|     {
 | |
|         sqlite3_close_v2(handle);
 | |
|     }
 | |
| 
 | |
|     Db makeDb(std::string_view path, const char* schema)
 | |
|     {
 | |
|         sqlite3* handle = nullptr;
 | |
|         // All uses of NavMeshDb are protected by a mutex (navmeshtool) or serialized in a single thread (DbWorker)
 | |
|         // so additional synchronization between threads is not required and SQLITE_OPEN_NOMUTEX can be used.
 | |
|         // This is unsafe to use NavMeshDb without external synchronization because of internal state.
 | |
|         const int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX;
 | |
|         if (const int ec = sqlite3_open_v2(std::string(path).c_str(), &handle, flags, nullptr); ec != SQLITE_OK)
 | |
|         {
 | |
|             const std::string message(sqlite3_errmsg(handle));
 | |
|             sqlite3_close(handle);
 | |
|             throw std::runtime_error("Failed to open database: " + message);
 | |
|         }
 | |
|         Db result(handle);
 | |
|         if (const int ec = sqlite3_exec(result.get(), schema, nullptr, nullptr, nullptr); ec != SQLITE_OK)
 | |
|             throw std::runtime_error("Failed create database schema: " + std::string(sqlite3_errmsg(handle)));
 | |
|         return result;
 | |
|     }
 | |
| }
 |