public bool Update(string tableName, Tuple <string, string> whereKey, Dictionary <string, string> stringData) { List <string> setStrings = new List <string>(); foreach (KeyValuePair <string, string> stringParam in stringData) { setStrings.Add(String.Format("{0} = '{1}'", stringParam.Key, doubleApostraphes(stringParam.Value))); } string setString = UtilitiesMethods.CommaSeparatedString(setStrings); string commandString = String.Format("update {0} set {1} where {2} = '{3}';", tableName, setString, whereKey.Item1, whereKey.Item2); SQLiteCommand command = new SQLiteCommand(Connection); command.CommandText = commandString; if (command.ExecuteNonQuery() > 0) { return(true); } else { logger.Error("Update failed. Command: {0}", command.CommandText); return(false); } }
public bool Insert(string tableName, Dictionary <string, string> stringData, Dictionary <string, byte[]> byteData = null) { string commandString = "insert into " + tableName + " ("; List <string> colNames = new List <string>(); List <string> stringVals = new List <string>(); List <string> byteRefs = new List <string>(); SQLiteCommand command = new SQLiteCommand(Connection); foreach (KeyValuePair <string, string> stringParam in stringData) { colNames.Add(stringParam.Key); stringVals.Add("'" + doubleApostraphes(stringParam.Value) + "'"); } if (byteData != null) { foreach (KeyValuePair <string, byte[]> byteParam in byteData) { colNames.Add(byteParam.Key); string byteRef = "@" + byteParam.Key; byteRefs.Add("(" + byteRef + ")"); command.Parameters.Add(byteRef, DbType.Binary).Value = byteParam.Value; } } commandString += UtilitiesMethods.CommaSeparatedString(colNames) + ") values (" + UtilitiesMethods.CommaSeparatedString(stringVals); if (byteData != null) { commandString += ", " + UtilitiesMethods.CommaSeparatedString(byteRefs); } commandString += ")"; command.CommandText = commandString; return(command.ExecuteNonQuery() > 0); }