public override ResultMap Execute(Dictionary <string, object> parameters) { //Build FieldSQL for parameters string fieldSQL = FieldSQL; if (fieldSQL == null && Fields != null && Fields.Count() > 0) { foreach (string field in Fields) { if (fieldSQL == null) { FieldSQL = MySQLConnection.FieldEscape(field); continue; } fieldSQL += ", " + MySQLConnection.FieldEscape(field); } } else { fieldSQL = "*"; } if (base.Conditions.Count() < 1) { Console.WriteLine(String.Format("SELECT {0} FROM {1}", fieldSQL, Table)); return(Database.ExecuteQuery(String.Format("SELECT {0} FROM {1}", fieldSQL, Table))); } string query = String.Format("SELECT {0} FROM {1} WHERE {2}", fieldSQL, Table, Database.BuildConditionSQL(base.Conditions, ref parameters)); return(Database.ExecuteQuery(query, parameters)); }
public override Boolean Execute(Dictionary <string, object> parameters) { List <string> sqlValueList = new List <string>(); foreach (object[] valuesArr in base.ValuesList) { if (base.Fields != null && base.Fields.Count() != valuesArr.Count()) { throw new ArgumentException("Provided ValueSet does not match the size of Field List"); } List <string> values = new List <string>(); foreach (object value in valuesArr) { if (value is Array) { object[] valuePair = (object[])value; values.Add(MySQLConnection.EscapeValue( valuePair[0].ToString(), (int)valuePair[1], ref parameters) ); continue; } if (value == null) { values.Add("NULL"); continue; } values.Add(MySQLConnection.EscapeValue( value.ToString(), ParameterFormat.PREPARED_STATEMENT_ARGUMENT, ref parameters) ); } sqlValueList.Add(String.Format("({0})", String.Join(", ", values))); } String query; if (base.Fields == null || base.Fields.Count() < 1) { query = String.Format("INSERT INTO {0} VALUES {1}", base.Table, String.Join(",", sqlValueList)); } else { List <string> fields = new List <String>(); foreach (String field in base.Fields) { fields.Add(MySQLConnection.FieldEscape(field)); } query = String.Format("INSERT INTO {0} ({1}) VALUES {2}", base.Table, String.Join(", ", fields), String.Join(", ", sqlValueList)); } return(Database.ExecuteUpdate(query, parameters)); }
public static string EscapeValue(string value, int format, ref Dictionary <string, object> parameters) { string param = null; switch (format) { case ParameterFormat.RAW: param = value; break; case ParameterFormat.ESCAPE_PARAMETER_AS_FIELD: param = MySQLConnection.FieldEscape(value); break; default: param = String.Format("@val{0}", (parameters.Count + 1)); parameters.Add("@val" + (parameters.Count + 1), value); break; } return(param); }
public override bool Execute(Dictionary <string, object> parameters) { List <string> setFields = new List <string>(); foreach (FieldUpdate field in base.FieldUpdates) { string fieldEscaped = MySQLConnection.FieldEscape(field.Field); string value = MySQLConnection.EscapeValue(field.Value, field.ValueFormat, ref parameters); setFields.Add(String.Format("{0}={1}", fieldEscaped, value)); } string fieldSQL = String.Join(", ", setFields); if (base.Conditions.Count() < 1) { return(Database.ExecuteUpdate(String.Format("UPDATE {0} SET {1}", fieldSQL, Table))); } string query = String.Format("UPDATE {0} SET {1} WHERE {2}", base.Table, fieldSQL, Database.BuildConditionSQL(base.Conditions, ref parameters)); return(Database.ExecuteUpdate(query, parameters)); }