System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
Ticket Hash: 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:
<verbatim>
          var query = from c in db.Customers
                      where c.City.EndsWith("don")
                      orderby c.CompanyName
                      select c;

          int cc = query.Count();
</verbatim>
results in the following SQL:
<verbatim>
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
</verbatim>
which is rejected by SQLite.
The following addition to SqlGenerator fixes the problem:
<verbatim>
    /// <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;
    }
</verbatim>

<hr /><i>mistachkin added on 2011-09-07 10:32:35 UTC:</i><br />
Fixed by check-in [7810393e98].