public List<Game> SearchForGame(string GameName)
{
//Search for a game
//return a maximum of 50 results since we have no way to reliable determine
//the number of results we get from the query.
LogInstance.WriteToFile(1, "Searching for " + GameName + " in the database.", LogSource);
if (!connectionopen)
{
DBConnector.Open();
connectionopen = true;
}
FbTransaction DBTransaction = DBConnector.BeginTransaction();
FbCommand DBCommand = new FbCommand("SELECT * FROM games WHERE name_of_game LIKE '" + GameName + "'", DBConnector, DBTransaction);
FbDataReader DBReader = DBCommand.ExecuteReader();
List<Game> Result = new List<Game>();
while (DBReader.Read())
{
Game SingleResult = new Game();
SingleResult.Name = DBReader.GetString(1);
SingleResult.ID = DBReader.GetInt32(0);
SingleResult.InfoXML = new XmlDocument();
SingleResult.InfoXML.LoadXml(DBReader.GetString(2));
SingleResult.ReleaseDate = DateTime.Parse(DBReader.GetString(6));
SingleResult.InstallPath = DBReader.GetString(7);
SingleResult.scraper_gdb_id = DBReader.GetInt32(8);
SingleResult.Platform = DBReader.GetString(9);
if (DBReader.GetInt32(3) != 0)
SingleResult.Downloaded = true;
else
SingleResult.Downloaded = false;
if (DBReader.GetInt32(4) != 0)
SingleResult.Snatched = true;
else
SingleResult.Snatched = false;
if (DBReader.GetInt32(5) != 0)
SingleResult.Wanted = true;
else
SingleResult.Wanted = false;
Result.Add(SingleResult);
}
//If there aren't any results, x will still be a 0
if (Result.Count == 0)
{
DBConnector.Close();
connectionopen = false;
return null;
}
DBConnector.Close();
connectionopen = false;
return Result;
}