/// <summary> /// create where string from params /// </summary> /// <param name="whereClause"> params collection</param> /// <returns> converted string </returns> private static String p_generateWhereClause(WhereClause whereClause) { StringBuilder whereBuilder = new StringBuilder(); //generate where clause if (whereClause == null) { return(whereBuilder.ToString()); } whereBuilder.Append(" WHERE "); //convert all columns from whereParameter to where clause // as result we have WHERE col1 = @col1 and col2 = @col2...... for (int i = 0; i < whereClause.Count; i++) { //if current paramater is a string array , then we have IN clause. //example : columnName IN ( value1, value2)... if (((valueObject)whereClause.ElementAt(i).Value).inValue.GetType().Name == (typeof(System.String[]).Name)) { whereBuilder.Append(createINString(whereClause.ElementAt(i))); } //regular parameter else { valueObject whereValue = whereClause.ElementAt(i).Value as valueObject; //create where clause : [ColumnName] [operator] @[parameter] whereBuilder.AppendFormat(" {0} {1} @{0} ", whereClause.ElementAt(i).Key, whereValue.getOperationString()); } whereBuilder.Append(" AND "); } //remove last "AND "(4 characters) whereBuilder.Remove(whereBuilder.Length - 4, 4); return(whereBuilder.ToString()); }
/// <summary> /// bind NAMED parameters to sql statement /// </summary> /// <param name="whereClause"></param> /// <returns></returns> private static List <MySqlParameter> p_createParamList(WhereClause whereClause) { List <MySqlParameter> paramCol = null; //add all parameters to current command if (whereClause != null) { paramCol = new List <MySqlParameter>(); for (int i = 0; i < whereClause.Count; i++) { String Key = whereClause.ElementAt(i).Key; valueObject Value = whereClause.ElementAt(i).Value as valueObject; //if currnt value is string array , add parameters if (Value.inValue.GetType().Name == (typeof(System.String[]).Name)) { String[] columns = Value.inValue as String[]; for (int j = 0; j < columns.Length; j++) { //add parameters to command in format IN (:COLUMNNAME1,:COLUMNAME2....) MySqlParameter parameter = new MySqlParameter(String.Format("{0}{1}", Key, j), columns[j]); paramCol.Add(parameter); } } //else add regular parameter else { MySqlParameter parameter = new MySqlParameter(Key, Value.inValue); paramCol.Add(parameter); } // Log.Trace(String.Format("{0}. {1} = {2}", i, Key, Value)); IFD DD } } return(paramCol); }