System.Data.SQLite
Check-in [7810393e98]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Support LINQ queries with EndsWith method, fix for [59edc1018b]. Add test to verify the behavior from ticket [00f86f9739]. Modify test results/handling for ticket [8b7d179c3c] to be consistent with these new tests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7810393e989359693c9827ba4cff9167a8503510
User & Date: mistachkin 2011-09-07 10:31:02
References
2011-09-07
10:32 Closed ticket [59edc1018b]: String.EndsWith doesn't work plus 2 other changes artifact: 39cdf34b7b user: mistachkin
Context
2011-09-11
13:14
Fix debug builds of the native interop assembly by making sure that SQLITE_WIN32_MALLOC is not defined with SQLITE_MEMDEBUG (i.e. they are mutually exclusive at compile-time). check-in: 7ef5b80330 user: mistachkin tags: trunk
2011-09-07
10:31
Support LINQ queries with EndsWith method, fix for [59edc1018b]. Add test to verify the behavior from ticket [00f86f9739]. Modify test results/handling for ticket [8b7d179c3c] to be consistent with these new tests. check-in: 7810393e98 user: mistachkin tags: trunk
2011-09-03
15:36
More comment updates to test suite. check-in: 5f2352effe user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite.Linq/SQL Generation/SqlGenerator.cs.

   331    331         functionHandlers.Add("IndexOf", HandleCanonicalFunctionIndexOf);
   332    332         functionHandlers.Add("Length", HandleCanonicalFunctionLength);
   333    333         functionHandlers.Add("NewGuid", HandleCanonicalFunctionNewGuid);
   334    334         functionHandlers.Add("Round", HandleCanonicalFunctionRound);
   335    335         functionHandlers.Add("ToLower", HandleCanonicalFunctionToLower);
   336    336         functionHandlers.Add("ToUpper", HandleCanonicalFunctionToUpper);
   337    337         functionHandlers.Add("Trim", HandleCanonicalFunctionTrim);
          338  +      functionHandlers.Add("Right", HandleCanonicalFunctionRight);
   338    339         functionHandlers.Add("CurrentDateTime", HandleGetDateFunction);
   339    340         functionHandlers.Add("CurrentUtcDateTime", HandleGetUtcDateFunction);
   340    341   
   341    342         //DatePartFunctions
   342    343         functionHandlers.Add("Year", HandleCanonicalFunctionDatepart);
   343    344         functionHandlers.Add("Month", HandleCanonicalFunctionDatepart);
   344    345         functionHandlers.Add("Day", HandleCanonicalFunctionDatepart);
................................................................................
  2939   2940         Debug.Assert(e.Arguments.Count == 1, "Trim should have one argument");
  2940   2941         result.Append(e.Arguments[0].Accept(sqlgen));
  2941   2942   
  2942   2943         result.Append(")");
  2943   2944   
  2944   2945         return result;
  2945   2946       }
         2947  +
         2948  +    /// <summary>
         2949  +    /// RIGHT(string, length) -> SUBSTR(string, -(length), length)
         2950  +    /// </summary>
         2951  +    /// <param name="sqlgen"></param>
         2952  +    /// <param name="e"></param>
         2953  +    /// <returns></returns>
         2954  +    private static ISqlFragment HandleCanonicalFunctionRight(SqlGenerator sqlgen, DbFunctionExpression e)
         2955  +    {
         2956  +        SqlBuilder result = new SqlBuilder();
         2957  +
         2958  +        result.Append("SUBSTR(");
         2959  +
         2960  +        Debug.Assert(e.Arguments.Count == 2, "Right should have two arguments");
         2961  +        result.Append(e.Arguments[0].Accept(sqlgen));
         2962  +        result.Append(", -(");
         2963  +        result.Append(e.Arguments[1].Accept(sqlgen));
         2964  +        result.Append("), ");
         2965  +        result.Append(e.Arguments[1].Accept(sqlgen));
         2966  +        result.Append(")");
         2967  +
         2968  +        return result;
         2969  +    }
  2946   2970   
  2947   2971       /// <summary>
  2948   2972       ///  Function rename ToLower -> LOWER
  2949   2973       /// </summary>
  2950   2974       /// <param name="sqlgen"></param>
  2951   2975       /// <param name="e"></param>
  2952   2976       /// <returns></returns>

Added Tests/tkt-00f86f9739.eagle.

            1  +###############################################################################
            2  +#
            3  +# tkt-00f86f9739.eagle --
            4  +#
            5  +# Written by Joe Mistachkin.
            6  +# Released to the public domain, use at your own risk!
            7  +#
            8  +###############################################################################
            9  +
           10  +package require Eagle
           11  +package require EagleLibrary
           12  +package require EagleTest
           13  +
           14  +runTestPrologue
           15  +
           16  +###############################################################################
           17  +
           18  +source [file join $path common.eagle]
           19  +runSQLiteTestPrologue
           20  +
           21  +###############################################################################
           22  +
           23  +#
           24  +# NOTE: Setup the variables that refer to the various files required by the
           25  +#       tests in this file.
           26  +#
           27  +set testLinqExeFile [getBuildFileName testlinq.exe]
           28  +set northwindEfDbFile [file nativename [file join [file dirname $path] \
           29  +    testlinq northwindEF.db]]
           30  +
           31  +#
           32  +# NOTE: Setup the test constraints specific to the tests in this file.
           33  +#
           34  +if {![haveConstraint file_[file tail $testLinqExeFile]]} then {
           35  +  checkForFile $test_channel $testLinqExeFile
           36  +}
           37  +
           38  +if {![haveConstraint file_[file tail $northwindEfDbFile]]} then {
           39  +  checkForFile $test_channel $northwindEfDbFile
           40  +}
           41  +
           42  +###############################################################################
           43  +
           44  +runTest {test tkt-00f86f9739-1.1 {LINQ with StartsWith} -body {
           45  +  set result [list]
           46  +
           47  +  foreach value [list "" a b z 1+1 don notthere] {
           48  +    set code [catch {
           49  +      testExec $testLinqExeFile [list -eventflags Wait -directory \
           50  +      [file dirname $testLinqExeFile] -nocarriagereturns -stdout output \
           51  +      -success 0] -startsWith $value
           52  +    } error]
           53  +
           54  +    tlog "---- BEGIN STDOUT OUTPUT\n"
           55  +    tlog $output
           56  +    tlog "\n---- END STDOUT OUTPUT\n"
           57  +
           58  +    lappend result $code
           59  +
           60  +    if {$code == 0} then {
           61  +      lappend result [string trim $output]
           62  +    } else {
           63  +      lappend result [string trim $error]
           64  +    }
           65  +  }
           66  +
           67  +  set result
           68  +} -cleanup {
           69  +  unset -nocomplain code output error result value
           70  +} -constraints {eagle file_testlinq.exe file_northwindEF.db} -result \
           71  +{0 {} 0 {DRACD OLDWO RATTC} 0 {ALFKI CACTU CHOPS FOLKO GALED KOENE LILAS MAGAA\
           72  +MAISD OCEAN RANCH SAVEA THECR} 0 {} 0 {} 0 {} 0 {}}}
           73  +
           74  +###############################################################################
           75  +
           76  +unset -nocomplain testLinqExeFile northwindEfDbFile
           77  +
           78  +###############################################################################
           79  +
           80  +runSQLiteTestEpilogue
           81  +runTestEpilogue

Added Tests/tkt-59edc1018b.eagle.

            1  +###############################################################################
            2  +#
            3  +# tkt-59edc1018b.eagle --
            4  +#
            5  +# Written by Joe Mistachkin.
            6  +# Released to the public domain, use at your own risk!
            7  +#
            8  +###############################################################################
            9  +
           10  +package require Eagle
           11  +package require EagleLibrary
           12  +package require EagleTest
           13  +
           14  +runTestPrologue
           15  +
           16  +###############################################################################
           17  +
           18  +source [file join $path common.eagle]
           19  +runSQLiteTestPrologue
           20  +
           21  +###############################################################################
           22  +
           23  +#
           24  +# NOTE: Setup the variables that refer to the various files required by the
           25  +#       tests in this file.
           26  +#
           27  +set testLinqExeFile [getBuildFileName testlinq.exe]
           28  +set northwindEfDbFile [file nativename [file join [file dirname $path] \
           29  +    testlinq northwindEF.db]]
           30  +
           31  +#
           32  +# NOTE: Setup the test constraints specific to the tests in this file.
           33  +#
           34  +if {![haveConstraint file_[file tail $testLinqExeFile]]} then {
           35  +  checkForFile $test_channel $testLinqExeFile
           36  +}
           37  +
           38  +if {![haveConstraint file_[file tail $northwindEfDbFile]]} then {
           39  +  checkForFile $test_channel $northwindEfDbFile
           40  +}
           41  +
           42  +###############################################################################
           43  +
           44  +runTest {test tkt-59edc1018b-1.1 {LINQ with EndsWith} -body {
           45  +  set result [list]
           46  +
           47  +  foreach value [list "" a b z 1+1 don notthere] {
           48  +    set code [catch {
           49  +      testExec $testLinqExeFile [list -eventflags Wait -directory \
           50  +      [file dirname $testLinqExeFile] -nocarriagereturns -stdout output \
           51  +      -success 0] -endsWith $value
           52  +    } error]
           53  +
           54  +    tlog "---- BEGIN STDOUT OUTPUT\n"
           55  +    tlog $output
           56  +    tlog "\n---- END STDOUT OUTPUT\n"
           57  +
           58  +    lappend result $code
           59  +
           60  +    if {$code == 0} then {
           61  +      lappend result [string trim $output]
           62  +    } else {
           63  +      lappend result [string trim $error]
           64  +    }
           65  +  }
           66  +
           67  +  set result
           68  +} -cleanup {
           69  +  unset -nocomplain code output error result value
           70  +} -constraints {eagle file_testlinq.exe file_northwindEF.db} -result \
           71  +{0 {} 0 {FURIB GALED GODOS LAZYK LINOD PRINI REGGC WOLZA} 0 {} 0 ERNSH 0 {} 0\
           72  +{AROUT BSBEV CONSH EASTC NORTS SEVES} 0 {}}}
           73  +
           74  +###############################################################################
           75  +
           76  +unset -nocomplain testLinqExeFile northwindEfDbFile
           77  +
           78  +###############################################################################
           79  +
           80  +runSQLiteTestEpilogue
           81  +runTestEpilogue

Changes to Tests/tkt-8b7d179c3c.eagle.

    51     51         -success 0] -skip $pageSize
    52     52       } error]
    53     53   
    54     54       tlog "---- BEGIN STDOUT OUTPUT\n"
    55     55       tlog $output
    56     56       tlog "\n---- END STDOUT OUTPUT\n"
    57     57   
    58         -    lappend result $output
           58  +    lappend result $code
           59  +
           60  +    if {$code == 0} then {
           61  +      lappend result [string trim $output]
           62  +    } else {
           63  +      lappend result [string trim $error]
           64  +    }
    59     65     }
    60     66   
    61         -  list $code [expr {$code == 0 ? "" : $error}] $result
           67  +  set result
    62     68   } -cleanup {
    63     69     unset -nocomplain code output error result pageSize
    64         -} -constraints \
    65         -{eagle file_testlinq.exe file_northwindEF.db} -result {0 {} {{} {DRACD RATTC\
    66         -OLDWO GALED LILAS MAGAA ALFKI CHOPS SAVEA KOENE MAISD FOLKO CACTU OCEAN RANCH\
    67         -THECR GOURL GROSR SUPRD HUNGO ISLAT QUICK HUNGC GREAL LEHMS RICSU ERNSH WILMK\
    68         -LINOD TRAIH SIMOB OTTIK SPLIR MORGK FOLIG FURIB PRINI AROUT BSBEV CONSH EASTC\
    69         -NORTS SEVES BERGS VICTE BOLID FISSA ROMEY BLAUS BONAP MEREP ANATR ANTON CENTC\
    70         -PERIC TORTU FRANK TOMSP DUMON FRANR WARTH PARIS SPECD LONEP THEBI REGGC VINET\
    71         -WELLI HANAR QUEDE RICAR PICCO HILAA LETSS COMMI FAMIA QUEEN TRADH WHITC GODOS\
    72         -SANTG BLONP WANDK FRANS LAMAI BOTTM LAUGB LACOR LAZYK WOLZA VAFFE
    73         -} {DRACD RATTC OLDWO GALED LILAS MAGAA ALFKI CHOPS SAVEA KOENE MAISD FOLKO\
    74         -CACTU OCEAN RANCH THECR GOURL GROSR SUPRD HUNGO ISLAT QUICK HUNGC GREAL LEHMS\
    75         -RICSU ERNSH WILMK LINOD TRAIH SIMOB OTTIK SPLIR MORGK FOLIG FURIB PRINI AROUT\
    76         -BSBEV CONSH EASTC NORTS SEVES BERGS VICTE BOLID FISSA ROMEY BLAUS BONAP MEREP\
    77         -ANATR ANTON CENTC PERIC TORTU FRANK TOMSP DUMON FRANR WARTH PARIS SPECD LONEP\
    78         -THEBI REGGC VINET WELLI HANAR QUEDE RICAR PICCO HILAA LETSS COMMI FAMIA QUEEN\
    79         -TRADH WHITC GODOS SANTG BLONP WANDK FRANS LAMAI BOTTM LAUGB LACOR LAZYK WOLZA\
    80         -VAFFE
    81         -}}}}
           70  +} -constraints {eagle file_testlinq.exe file_northwindEF.db} -result \
           71  +{0 {} 0 {DRACD RATTC OLDWO GALED LILAS MAGAA ALFKI CHOPS SAVEA KOENE MAISD\
           72  +FOLKO CACTU OCEAN RANCH THECR GOURL GROSR SUPRD HUNGO ISLAT QUICK HUNGC GREAL\
           73  +LEHMS RICSU ERNSH WILMK LINOD TRAIH SIMOB OTTIK SPLIR MORGK FOLIG FURIB PRINI\
           74  +AROUT BSBEV CONSH EASTC NORTS SEVES BERGS VICTE BOLID FISSA ROMEY BLAUS BONAP\
           75  +MEREP ANATR ANTON CENTC PERIC TORTU FRANK TOMSP DUMON FRANR WARTH PARIS SPECD\
           76  +LONEP THEBI REGGC VINET WELLI HANAR QUEDE RICAR PICCO HILAA LETSS COMMI FAMIA\
           77  +QUEEN TRADH WHITC GODOS SANTG BLONP WANDK FRANS LAMAI BOTTM LAUGB LACOR LAZYK\
           78  +WOLZA VAFFE} 0 {DRACD RATTC OLDWO GALED LILAS MAGAA ALFKI CHOPS SAVEA KOENE\
           79  +MAISD FOLKO CACTU OCEAN RANCH THECR GOURL GROSR SUPRD HUNGO ISLAT QUICK HUNGC\
           80  +GREAL LEHMS RICSU ERNSH WILMK LINOD TRAIH SIMOB OTTIK SPLIR MORGK FOLIG FURIB\
           81  +PRINI AROUT BSBEV CONSH EASTC NORTS SEVES BERGS VICTE BOLID FISSA ROMEY BLAUS\
           82  +BONAP MEREP ANATR ANTON CENTC PERIC TORTU FRANK TOMSP DUMON FRANR WARTH PARIS\
           83  +SPECD LONEP THEBI REGGC VINET WELLI HANAR QUEDE RICAR PICCO HILAA LETSS COMMI\
           84  +FAMIA QUEEN TRADH WHITC GODOS SANTG BLONP WANDK FRANS LAMAI BOTTM LAUGB LACOR\
           85  +LAZYK WOLZA VAFFE}}}
    82     86   
    83     87   ###############################################################################
    84     88   
    85     89   unset -nocomplain testLinqExeFile northwindEfDbFile
    86     90   
    87     91   ###############################################################################
    88     92   
    89     93   runSQLiteTestEpilogue
    90     94   runTestEpilogue

Changes to testlinq/Program.cs.

    55     55   
    56     56                             if (arg != null)
    57     57                                 pageSize = int.Parse(arg.Trim());
    58     58                         }
    59     59   
    60     60                         return SkipTest(pageSize);
    61     61                     }
           62  +              case "endswith":
           63  +                  {
           64  +                      string value = null;
           65  +
           66  +                      if (args.Length > 1)
           67  +                      {
           68  +                          value = args[1];
           69  +
           70  +                          if (value != null)
           71  +                              value = value.Trim();
           72  +                      }
           73  +
           74  +                      return EndsWithTest(value);
           75  +                  }
           76  +              case "startswith":
           77  +                  {
           78  +                      string value = null;
           79  +
           80  +                      if (args.Length > 1)
           81  +                      {
           82  +                          value = args[1];
           83  +
           84  +                          if (value != null)
           85  +                              value = value.Trim();
           86  +                      }
           87  +
           88  +                      return StartsWithTest(value);
           89  +                  }
    62     90                 default:
    63     91                     {
    64     92                         Console.WriteLine("unknown test \"{0}\"", arg);
    65     93                         return 1;
    66     94                     }
    67     95             }
    68     96         }
    69     97   
           98  +      //
           99  +      // NOTE: Used to test the fix for ticket [8b7d179c3c].
          100  +      //
    70    101         private static int SkipTest(int pageSize)
    71    102         {
    72    103             using (northwindEFEntities db = new northwindEFEntities())
    73    104             {
    74    105                 bool once = false;
    75    106                 int count = db.Customers.Count();
    76    107   
................................................................................
    89    120   
    90    121                         Console.Write(customers.CustomerID);
    91    122   
    92    123                         once = true;
    93    124                     }
    94    125                 }
    95    126             }
          127  +
          128  +          return 0;
          129  +      }
          130  +
          131  +      //
          132  +      // NOTE: Used to test the fix for ticket [59edc1018b].
          133  +      //
          134  +      private static int EndsWithTest(string value)
          135  +      {
          136  +          using (northwindEFEntities db = new northwindEFEntities())
          137  +          {
          138  +              bool once = false;
          139  +              var query = from c in db.Customers
          140  +                          where c.City.EndsWith(value)
          141  +                          orderby c.CustomerID
          142  +                          select c;
          143  +
          144  +              foreach (Customers customers in query)
          145  +              {
          146  +                  if (once)
          147  +                      Console.Write(' ');
          148  +
          149  +                  Console.Write(customers.CustomerID);
          150  +
          151  +                  once = true;
          152  +              }
          153  +          }
          154  +
          155  +          return 0;
          156  +      }
          157  +
          158  +      //
          159  +      // NOTE: Used to verify the behavior from ticket [00f86f9739].
          160  +      //
          161  +      private static int StartsWithTest(string value)
          162  +      {
          163  +          using (northwindEFEntities db = new northwindEFEntities())
          164  +          {
          165  +              bool once = false;
          166  +              var query = from c in db.Customers
          167  +                          where c.City.StartsWith(value)
          168  +                          orderby c.CustomerID
          169  +                          select c;
          170  +
          171  +              foreach (Customers customers in query)
          172  +              {
          173  +                  if (once)
          174  +                      Console.Write(' ');
          175  +
          176  +                  Console.Write(customers.CustomerID);
          177  +
          178  +                  once = true;
          179  +              }
          180  +          }
    96    181   
    97    182             return 0;
    98    183         }
    99    184   
   100    185       private static int OldTests()
   101    186       {
   102    187         using (northwindEFEntities db = new northwindEFEntities())