public void ValidateParameters_WhenParametersMatch_ShouldNotThrowException() { command.CommandText = "SELECT * FROM albums WHERE AlbumId = @albumid"; command.AddParameter("albumid", 1); command.ValidateParameters(); }
private void AmendParameters(Weapon weapon, SqliteCommand cmd) { cmd.AddParameter($"@{nameof(weapon.Id)}", weapon.Id); cmd.AddParameter($"@{nameof(weapon.Name)}", weapon.Name); cmd.AddParameter($"@{nameof(weapon.Effectiveness)}", weapon.Effectiveness); cmd.AddParameter($"@{nameof(weapon.Defense)}", weapon.Defense); cmd.AddParameter($"@{nameof(weapon.Speed)}", weapon.Speed); cmd.AddParameter($"@{nameof(weapon.Stun)}", weapon.Stun); cmd.AddParameter($"@{nameof(weapon.Properties)}", weapon.Properties); }
private void AmendParameters(Settings settings, SqliteCommand cmd) { cmd.AddParameter($"@{nameof(settings.Id)}", settings.Id); cmd.AddParameter($"@{nameof(settings.MusicVolume)}", settings.MusicVolume); cmd.AddParameter($"@{nameof(settings.Preferences)}", settings.Preferences); }
public override void Execute() { if (TShock.DB.GetSqlType() == SqlType.Sqlite) { using (IDbConnection db = History.Database.CloneEx()) { db.Open(); using (SqliteTransaction transaction = (SqliteTransaction)db.BeginTransaction()) { using (SqliteCommand command = (SqliteCommand)db.CreateCommand()) { command.CommandText = "INSERT INTO History (Time, Account, Action, XY, Data, Style, Paint, WorldID, Text) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8)"; for (int i = 0; i < 9; i++) { command.AddParameter("@" + i, null); } command.Parameters[7].Value = Main.worldID; foreach (Action a in actions) { command.Parameters[0].Value = a.time; command.Parameters[1].Value = a.account; command.Parameters[2].Value = a.action; command.Parameters[3].Value = (a.x << 16) + a.y; command.Parameters[4].Value = a.data; command.Parameters[5].Value = a.style; command.Parameters[6].Value = a.paint; command.Parameters[8].Value = a.text; command.ExecuteNonQuery(); } } transaction.Commit(); } } } else { using (IDbConnection db = History.Database.CloneEx()) { db.Open(); using (MySqlTransaction transaction = (MySqlTransaction)db.BeginTransaction()) { using (MySqlCommand command = (MySqlCommand)db.CreateCommand()) { command.CommandText = "INSERT INTO History (Time, Account, Action, XY, Data, Style, Paint, WorldID, Text) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8)"; for (int i = 0; i < 9; i++) { command.AddParameter("@" + i, null); } command.Parameters[7].Value = Main.worldID; foreach (Action a in actions) { command.Parameters[0].Value = a.time; command.Parameters[1].Value = a.account; command.Parameters[2].Value = a.action; command.Parameters[3].Value = (a.x << 16) + a.y; command.Parameters[4].Value = a.data; command.Parameters[5].Value = a.style; command.Parameters[6].Value = a.paint; command.Parameters[8].Value = a.text; command.ExecuteNonQuery(); } } transaction.Commit(); } } } }