SQLite Forum

sqlite3.dll is not returning control to my program
Login
I am using C++17 in Visual Studio 2019, and utilizing the sqlite3.dll from sqlite-dll-win64-x64-3360000, using a debug build

I've been working on a video game for the last few weeks. Each time a new game is created, I open the same .db file, and I run a "CREATE TABLE world (tile_type INT)" query for the game world. For now, each table and .db file have had the same names. Lazily, I do not delete the previous .db file nor its tables, so sqlite3_exec() returns 1 since the table is already created, and sqlite3_errmsg prints out the appropriate message. 

As of today, sqlite3_errmsg is not returning control to my program. SQL code has remained the same for the last 2 weeks. When stepping through with a debugger, after sqlite3_errmsg( db ) is called, the debugger step arrow disappears, all the autos/locals/variables get grayed out, the CPU usage drops to 0, and the game freezes.

UPDATE: "DROP TABLE world IF EXISTS" also silently fails and control is not returned. The only way to fix this is to delete the .db file, or to restart the computer.

The relevant code is below:

rc = sqlite3_exec( db, query.c_str(), NULL, NULL, &dbError );

assert( db != nullptr );

if( rc == SQLITE_CORRUPT ) {
	std::cerr << "The DB is corrupt!" << '\n';
}

if( rc ) {																								
	std::cerr << "Error executing SQLite3 statement: " << sqlite3_errmsg( db ) << std::endl;  // <-- the program loses control here
	std::cerr << "QUERY " << query << std::endl;

	sqlite3_free( dbError );
}

For reference, this is called each time a new game is created:

int GameEngine::openDB( string saveName ) {
	string path = savePath + saveName + ".db";															
	rc = sqlite3_open( path.c_str(), &db );																
	if( rc ) {																							
		std::cerr << "Could not open the database: " << path << '\n';
		return 1;
	}
	
	return 0;
}