/// <summary> /// Creates the table using a SQL statement /// </summary> public void CreateTable_Query() { string sql; // Start a transaction to batch the commands together dbManager.BeginTransaction(); // Create the table sql = "CREATE TABLE \"StarShip\" " + "(\"StarShipID\" INTEGER PRIMARY KEY NOT NULL, " + "\"StarShipName\" varchar(60) NOT NULL, " + "\"HomePlanet\" varchar(100) DEFAULT Earth, " + "\"Range\" FLOAT NOT NULL, " + "\"Armor\" FLOAT DEFAULT 120, " + "\"Firepower\" FLOAT)"; dbManager.Execute(sql); // Create an index on the starship name sql = "CREATE INDEX \"StarShip_StarShipName\" on \"StarShip\"(\"StarShipName\")"; dbManager.Execute(sql); // Commit the transaction and run all the commands dbManager.Commit(); Results("Create Table Query Success!"); }
//Create User_Table public void Create_UnlockedCharacterTable() { dbManager.BeginTransaction(); string sql = "CREATE TABLE IF NOT EXISTS \"User_Table\" " + "(\"UNLOCKED_CHAR_ID\" INTEGER, " + "\"UNLOCKED_CHAR_NAME\" varchar(40))"; dbManager.Execute(sql); dbManager.Commit(); dbManager.Close(); }
/// <summary> /// Saves the player stats three times using a SQL statement. The calls are made inside of a transaction /// by using BeginTransaction and Commit. Transactions vastly reduce the amount of time it takes /// to save multiple records. /// </summary> /// <param name='playerName'> /// Player name. /// </param> /// <param name='totalKills'> /// Total kills. /// </param> /// <param name='points'> /// Points. /// </param> private void SavePlayerStats_QueryThreeTimes(string playerName, int totalKills, int points) { // set up our insert SQL statement with ? parameters string sql = "INSERT INTO PlayerStats (PlayerName, TotalKills, Points) VALUES (?, ?, ?)"; // start a transaction dbManager.BeginTransaction(); // execute the SQL statement three times dbManager.Execute(sql, playerName, totalKills, points); dbManager.Execute(sql, playerName, totalKills, points); dbManager.Execute(sql, playerName, totalKills, points); // commit our transaction to the database dbManager.Commit(); }