public static void ValidateBindVariables(this System.Data.Common.DbCommand command)
        {
            if (command.CommandType != System.Data.CommandType.Text)
            {
                throw new Exception("Cannot call ValidateBindVariables if not parameterized query");
            }
            List <string> bindVariables = DatabaseUtilities.ExtractBindVariables(command.CommandText);

            System.Data.Common.DbParameterCollection dbParameters = command.Parameters;
            foreach (string variable in bindVariables)
            {
                bool bound = false;
                foreach (System.Data.Common.DbParameter parameter in dbParameters)
                {
                    if (parameter.ParameterName.Equals(variable, System.StringComparison.CurrentCultureIgnoreCase))
                    {
                        bound = true;
                        break;
                    }
                }
                if (!bound)
                {
                    throw new Exception(string.Format("{0} is not bound", variable));
                }
            }
        }
Beispiel #2
0
 public void AddParametersFrom <T>(DbCommand command, T input)
 {
     if (command.CommandType != System.Data.CommandType.Text)
     {
         throw new Exception("The feature is only supported for inline SQL");
     }
     string[] parametersToAdd = DatabaseUtilities.ExtractBindVariables(command.CommandText).ToArray();
     this.AddParametersFrom <T>(command, input, parametersToAdd);
 }