SubSonic Forums
All Your Database Are Belong To Us

Invalid name for parameter when build a select

Latest post 08-26-2008 12:40 PM by mamcx. 4 replies.
  • 08-20-2008 5:25 PM

    • mamcx
    • Top 500 Contributor
    • Joined on 10-23-2007
    • Posts 9

    Invalid name for parameter when build a select

    Hi, using lastest trunk I found is not posible to build a select with a calculated column like: q.Where(String.Format("LEFT(Convert(varchar, {0} ,103),{1})", "Fecha", ValorStr.Length)).IsEqualTo(ValorStr) I get this: WHERE LEFT(Convert(varchar, Fecha ,103),3) = @LEFTConvertvarchar,Fecha,103,30 This happend alwasy a function is called with ",". However, this work fine: "CAST(Values AS VARCHAR)"
  • 08-21-2008 12:39 AM In reply to

    • ranomore
    • Top 10 Contributor
    • Joined on 11-05-2007
    • Salt Lake City
    • Posts 322

    Re: Invalid name for parameter when build a select

    mamcx:
    @LEFTConvertvarchar,Fecha,103,30

    Subsonic is trying to to parameterize your query, and commas don't work in parameter names. can you try using the "as" keyword?

     

  • 08-22-2008 4:12 PM In reply to

    • mamcx
    • Top 500 Contributor
    • Joined on 10-23-2007
    • Posts 9

    Re: Invalid name for parameter when build a select

    Generate this: @LEFTConvertvarchar,Fecha,103,3ASFecha0 Subsonic need clean the generated name. You know where is that function so I can fix it ?
  • 08-23-2008 2:35 PM In reply to

    • stefana62
    • Top 500 Contributor
    • Joined on 02-01-2008
    • Gothenburg, Sweden
    • Posts 8

    Re: Invalid name for parameter when build a select

    I think changing the function

    public
    static string PrefixParameter(string parameter, DataProvider provider)

    in Utility.cs so that it removes any illegal characters in the string it returns
    would do the trick.

    //stefan
    //Stefan
  • 08-26-2008 12:40 PM In reply to

    • mamcx
    • Top 500 Contributor
    • Joined on 10-23-2007
    • Posts 9

    Re: Invalid name for parameter when build a select

    Ok, I put this code and work fine: Also, I think that StripNonAlphaNumeric is not rigth. The best is check for valid chars, not hardcode what is wrong.
            public static string PrefixParameter(string parameter, DataProvider provider)
            {
                //added this check for Unit Testing weirdness - RC
                if(provider == null)
                    provider = DataService.Provider;
    
                string prefix = provider.GetParameterPrefix();
    
                if(!parameter.StartsWith(prefix))
                    parameter = String.Concat(prefix, parameter.Replace(" ", String.Empty));
                //clean non-valid chars
                string regex = "@|\\w+|\\d+";
                RegexOptions options = ((RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline) 
                            | RegexOptions.IgnoreCase);
                Regex reg = new Regex(regex, options);
    
                string clean = "";
                MatchCollection theMatches = reg.Matches(parameter);
    
                for (int counter = 0; counter 
Page 1 of 1 (5 items) | RSS