System.Data.SQLite
View Ticket
Not logged in
Ticket UUID: 59edc1018b1b07e7d96870d5f404eb98cd448f9c
Title: String.EndsWith doesn't work
Status: Closed Type: Code_Defect
Severity: Severe Priority: Immediate
Subsystem: LINQ Resolution: Fixed
Last Modified: 2011-09-07 10:32:35
Version Found In: 1.0.74.0
Description:
String.EndsWith doesn't work. For example modifying testlinq's OldTests function to read:
          var query = from c in db.Customers
                      where c.City.EndsWith("don")
                      orderby c.CompanyName
                      select c;

          int cc = query.Count();
results in the following SQL:
SELECT 
[GroupBy1].[A1] AS [C1]
FROM   ( SELECT 1 AS X ) AS [SingleRowTable1]
LEFT OUTER JOIN  (SELECT 
	Count([Filter1].[A1]) AS [A1]
	FROM ( SELECT 
		1 AS [A1]
		FROM [Customers] AS [Extent1]
		WHERE (Right([Extent1].[City], LENGTH('don'))) = 'don'
	)  AS [Filter1] ) AS [GroupBy1] ON 1 = 1
which is rejected by SQLite. The following addition to SqlGenerator fixes the problem:
    /// <summary>
    ///  Right(arg, len) -> SUBSTR(str, -len, len)
    /// </summary>
    /// <param name="sqlgen"></param>
    /// <param name="e"></param>
    /// <returns></returns>
    private static ISqlFragment HandleCanonicalFunctionRight(SqlGenerator sqlgen, DbFunctionExpression e)
    {
        SqlBuilder result = new SqlBuilder();

        result.Append("SUBSTR(");

        Debug.Assert(e.Arguments.Count == 2, "Right should have two arguments");
        result.Append(e.Arguments[0].Accept(sqlgen));
        result.Append(", -");
        result.Append(e.Arguments[1].Accept(sqlgen));
        result.Append(", ");
        result.Append(e.Arguments[1].Accept(sqlgen));

        result.Append(")");

        return result;
    }

mistachkin added on 2011-09-07 10:32:35 UTC:
Fixed by check-in [7810393e98].