public override List <TransliterationRule> ListRules(bool enabledOnly = true) { Refresh(); SqlCommand cmd = new SqlCommand("SELECT * FROM TransPhonetic WHERE LangId1='" + srcLanguage.Code + "' AND LangId2='" + dstLanguage.Code + "'" + (enabledOnly ? " AND Disabled='FALSE'" : string.Empty), connection); SqlDataReader reader = cmd.ExecuteReader(); List <TransliterationRule> list = new List <TransliterationRule>(); while (reader.Read()) { TransliterationRule rule = new TransliterationRule() { Source = reader.GetString(2), Destination = reader.GetString(3), Examples = reader.GetString(4), CounterExamples = reader.IsDBNull(5) ? string.Empty : reader.GetString(5), Comment = reader.IsDBNull(6) ? string.Empty : reader.GetString(6), Disabled = reader.GetBoolean(7) }; list.Add(rule); // German Sharp s handling: SQL treats sharp s and double ss the same. // This is a workaround. if (srcLanguage.Code == "DE" && rule.Source == "ß" && !rule.Disabled) { list.Add(new TransliterationRule { Source = "ss", Destination = rule.Destination, Examples = string.Empty, CounterExamples = string.Empty, Disabled = false, Comment = "This is automatically created rule based on ß rule" }); } } reader.Close(); return(list); }
public override void UpdateRule(TransliterationRule rule, string source) { Refresh(); SqlCommand cmd = new SqlCommand( string.Format("UPDATE TransPhonetic SET " + "Source=N'{0}', Destination=N'{1}', Examples=N'{2}', CounterExamples=N'{3}', Comment=N'{4}', Disabled=N'{5}' " + "WHERE LangId1=N'{6}' AND LangId2=N'{7}' AND Source=N'{8}'", Normalize(rule.Source), Normalize(rule.Destination), Normalize(rule.Examples), Normalize(rule.CounterExamples), Normalize(rule.Comment), rule.Disabled, this.srcLanguage.Code, this.dstLanguage.Code, source), connection); if (cmd.ExecuteNonQuery() != 1) { throw new Exception("SQL UPDATE did not affect 1 row"); } }
public override void CreateRule(TransliterationRule rule) { Refresh(); SqlCommand cmd = new SqlCommand( "INSERT INTO TransPhonetic " + "(LangId1, LangId2, Source, Destination, Examples, CounterExamples, Comment, Disabled) " + string.Format("VALUES ('{0}', '{1}', N'{2}', N'{3}', N'{4}', N'{5}', '{6}', '{7}')", this.srcLanguage.Code, this.dstLanguage.Code, Normalize(rule.Source), Normalize(rule.Destination), Normalize(rule.Examples), Normalize(rule.CounterExamples), Normalize(rule.Comment), rule.Disabled), connection); if (cmd.ExecuteNonQuery() != 1) { throw new Exception("SQL INSERT did not affect 1 column"); } }
public override void UpdateRule(TransliterationRule rule, string source) { throw new NotImplementedException(); }
public override void CreateRule(TransliterationRule rule) { throw new NotImplementedException(); }
public abstract void UpdateRule(TransliterationRule rule, string source);
public abstract void CreateRule(TransliterationRule rule);