0 Replies - 979 Views - Last Post: 09 April 2011 - 06:59 AM Rate Topic: -----

#1 hypertyper  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 13-December 10

SQLite in C++ causing rare crashes

Posted 09 April 2011 - 06:59 AM

I'm trying to learn some C++ and SQL so I'm playing around with a game I'm trying to make. I've spent a lot of time trying find out why this piece of code causes a crash. I've isolated this part as the definite root of all evil but I don't see what's wrong with it. It works most of the time and sometimes is crashes my application.

This code loads a player model and range multiplier from and sqlite db. It goes through all the players and loads their information.

This is the first time I'm using sqlite in C++ so I'm not sure what to look for. Can anybody see any mistakes?

Thank you

void LoadOpponentData()	
{
	sqlite3 *db;

	sqlite3_stmt    *res;
	int             rec_count = 0;
	const char      *errMSG;
	const char      *tail;

	std::string p_name = "";
	std::string queryString = "";

	const char* queryCommand = "";
	const char* filename = dbName.c_str ();

	int error = sqlite3_open(filename, &db);

	if (error && log_sql==1)
	{
		writeSQLErrorLog(error);
	}

	for (int p = 0; p < oh_nchairs; p++)
	{
		p_name = "";

		p_name =player[p];

		if (p_name != "")
		{
			player_name[p] = p_name;

			queryString = "";
			queryCommand = "";

			queryString = "SELECT PlayerType, Multiplier FROM OpponentData WHERE Name = '";
			queryString = queryString += p_name += "'";

			queryCommand = queryString.c_str();

			error = sqlite3_prepare_v2(db, queryCommand, 1000, &res, &tail);

			if (error == SQLITE_OK)
			{
				while (sqlite3_step(res) == SQLITE_ROW)
				{
					player_type[p] = sqlite3_column_int(res, 0);
					range_multiplier[p] = sqlite3_column_double(res, 1);
				}
			}
			else
			{
				if (log_sql==1) {writeSQLErrorLog(error);}
			}
		}
	}

	sqlite3_finalize(res);
	sqlite3_close (db);
	}
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1