System.Data.SQLite
Check-in [369779a300]
Not logged in

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

Overview
Comment:Honor the second argument to Math.Round when using LINQ.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 369779a30009d32d42bee0e3b8369b8ffe78f7b4
User & Date: mistachkin 2015-07-29 22:03:59
Context
2015-07-30
00:15
Update SQLite core library to the 3.8.11.1 release. check-in: e2757bd694 user: mistachkin tags: trunk
2015-07-29
22:03
Honor the second argument to Math.Round when using LINQ. check-in: 369779a300 user: mistachkin tags: trunk
02:57
Enhancements to the stress test. check-in: d8612b51e0 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Doc/Extra/Provider/version.html.

    44     44       <div id="mainBody">
    45     45       <h1 class="heading">Version History</h1>
    46     46       <p><b>1.0.98.0 - August XX, 2015 <font color="red">(release scheduled)</font></b></p>
    47     47       <ul>
    48     48         <li>Updated to <a href="https://www.sqlite.org/releaselog/3_8_11.html">SQLite 3.8.11</a>.</li>
    49     49         <li>Add full support for Visual Studio 2015 and the .NET Framework 4.6.</li>
    50     50         <li>Implement the Substring method for LINQ using the &quot;substr&quot; core SQL function.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           51  +      <li>Honor the second argument to Math.Round when using LINQ.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    51     52         <li>Honor the pre-existing flags for connections during the Open method. Fix for <a href="https://system.data.sqlite.org/index.html/info/964063da16">[964063da16]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    52     53         <li>Remove errant semi-colons from the SQL used by LINQ to INSERT and then SELECT rows with composite primary keys. Fix for <a href="https://system.data.sqlite.org/index.html/info/9d353b0bd8">[9d353b0bd8]</a>.</li>
    53     54         <li>Change the base type for the SQLiteConnectionFlags enumeration to long integer.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    54     55         <li>Add extended return codes to the SQLiteErrorCode enumeration. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/71bedaca19">[71bedaca19]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    55     56         <li>Improve exception handling in all native callbacks implemented in the SQLiteConnection class.</li>
    56     57         <li>Add Progress event and ProgressOps connection string property to enable raising progress events during long-running queries.</li>
    57     58         <li>Add &quot;Recursive Triggers&quot; connection string property to enable or disable the recursive trigger capability. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/3a82ee635b">[3a82ee635b]</a>.</li>

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

  2957   2957         //result.Append(" + '.') - LEN('.')");
  2958   2958   
  2959   2959         return result;
  2960   2960       }
  2961   2961   
  2962   2962       /// <summary>
  2963   2963       /// Round(numericExpression) -> Round(numericExpression, 0);
         2964  +    /// Round(numericExpression, N) -> Round(numericExpression, N);
  2964   2965       /// </summary>
  2965   2966       /// <param name="sqlgen"></param>
  2966   2967       /// <param name="e"></param>
  2967   2968       /// <returns></returns>
  2968   2969       private static ISqlFragment HandleCanonicalFunctionRound(SqlGenerator sqlgen, DbFunctionExpression e)
  2969   2970       {
  2970   2971         SqlBuilder result = new SqlBuilder();
  2971   2972   
  2972   2973         result.Append("ROUND(");
  2973   2974   
  2974         -      Debug.Assert(e.Arguments.Count == 1, "Round should have one argument");
         2975  +      Debug.Assert(e.Arguments.Count == 1 || e.Arguments.Count == 2, "Round should have one or two arguments");
  2975   2976         result.Append(e.Arguments[0].Accept(sqlgen));
  2976   2977   
  2977         -      result.Append(", 0)");
         2978  +      if (e.Arguments.Count == 2)
         2979  +      {
         2980  +        result.Append(", ");
         2981  +        result.Append(e.Arguments[1].Accept(sqlgen));
         2982  +        result.Append(")");
         2983  +      }
         2984  +      else
         2985  +      {
         2986  +        result.Append(", 0)");
         2987  +      }
  2978   2988   
  2979   2989         return result;
  2980   2990       }
  2981   2991   
  2982   2992       /// <summary>
  2983   2993       /// TRIM(string) -> LTRIM(RTRIM(string))
  2984   2994       /// </summary>

Changes to Tests/linq.eagle.

    52     52   
    53     53     set result
    54     54   } -cleanup {
    55     55     unset -nocomplain code output error result
    56     56   } -constraints {eagle monoToDo SQLite file_System.Data.SQLite.dll testExec\
    57     57   file_System.Data.SQLite.Linq.dll file_testlinq.exe file_northwindEF.db} \
    58     58   -result {0 {inserted 1 updated 1}}}
           59  +
           60  +###############################################################################
           61  +
           62  +runTest {test linq-1.2 {ROUND function with two arguments} -body {
           63  +  #
           64  +  # NOTE: Re-copy the reference database file used for this unit test to the
           65  +  #       build directory in case it has been changed by a previous test run.
           66  +  #
           67  +  file copy -force $northwindEfDbFile \
           68  +      [file join [getBuildDirectory] [file tail $northwindEfDbFile]]
           69  +
           70  +  set result [list]
           71  +  set output ""
           72  +
           73  +  set code [catch {
           74  +    testClrExec $testLinqExeFile [list -eventflags Wait -directory \
           75  +        [file dirname $testLinqExeFile] -nocarriagereturns -stdout output \
           76  +        -success 0] -round
           77  +  } error]
           78  +
           79  +  tlog "---- BEGIN STDOUT OUTPUT\n"
           80  +  tlog $output
           81  +  tlog "\n---- END STDOUT OUTPUT\n"
           82  +
           83  +  lappend result $code
           84  +
           85  +  if {$code == 0} then {
           86  +    lappend result [string trim $output]
           87  +  } else {
           88  +    lappend result [string trim $error]
           89  +  }
           90  +
           91  +  set result
           92  +} -cleanup {
           93  +  unset -nocomplain code output error result
           94  +} -constraints {eagle monoToDo SQLite file_System.Data.SQLite.dll testExec\
           95  +file_System.Data.SQLite.Linq.dll file_testlinq.exe file_northwindEF.db} \
           96  +-result {0 {{ NewUnitPrice = 21.0 } { NewUnitPrice = 21.1 } { NewUnitPrice =\
           97  +21.05 } { NewUnitPrice = 23.0 } { NewUnitPrice = 23.3 } { NewUnitPrice = 23.25\
           98  +} { NewUnitPrice = 21.0 } { NewUnitPrice = 21.4 } { NewUnitPrice = 21.35 }}}}
    59     99   
    60    100   ###############################################################################
    61    101   
    62    102   runSQLiteTestFilesEpilogue
    63    103   runSQLiteTestEpilogue
    64    104   runTestEpilogue

Changes to readme.htm.

   211    211   <p>
   212    212       <b>1.0.98.0 - August XX, 2015 <font color="red">(release scheduled)</font></b>
   213    213   </p>
   214    214   <ul>
   215    215       <li>Updated to <a href="https://www.sqlite.org/releaselog/3_8_11.html">SQLite 3.8.11</a>.</li>
   216    216       <li>Add full support for Visual Studio 2015 and the .NET Framework 4.6.</li>
   217    217       <li>Implement the Substring method for LINQ using the &quot;substr&quot; core SQL function.&nbsp;<b>** Potentially Incompatible Change **</b></li>
          218  +    <li>Honor the second argument to Math.Round when using LINQ.&nbsp;<b>** Potentially Incompatible Change **</b></li>
   218    219       <li>Honor the pre-existing flags for connections during the Open method. Fix for [964063da16].&nbsp;<b>** Potentially Incompatible Change **</b></li>
   219    220       <li>Remove errant semi-colons from the SQL used by LINQ to INSERT and then SELECT rows with composite primary keys. Fix for [9d353b0bd8].</li>
   220    221       <li>Change the base type for the SQLiteConnectionFlags enumeration to long integer.&nbsp;<b>** Potentially Incompatible Change **</b></li>
   221    222       <li>Add extended return codes to the SQLiteErrorCode enumeration. Pursuant to [71bedaca19].&nbsp;<b>** Potentially Incompatible Change **</b></li>
   222    223       <li>Improve exception handling in all native callbacks implemented in the SQLiteConnection class.</li>
   223    224       <li>Add Progress event and ProgressOps connection string property to enable raising progress events during long-running queries.</li>
   224    225       <li>Add &quot;Recursive Triggers&quot; connection string property to enable or disable the recursive trigger capability. Pursuant to [3a82ee635b].</li>

Changes to testlinq/Program.cs.

   185    185   
   186    186                                 return 1;
   187    187                             }
   188    188                         }
   189    189   
   190    190                         return BinaryGuidTest2(value);
   191    191                     }
          192  +#endif
          193  +#if NET_40 || NET_45 || NET_451 || NET_46
          194  +              case "round":
          195  +                  {
          196  +                      return RoundTest();
          197  +                  }
   192    198   #endif
   193    199                 default:
   194    200                     {
   195    201                         Console.WriteLine("unknown test \"{0}\"", arg);
   196    202                         return 1;
   197    203                     }
   198    204             }
................................................................................
   784    790                     "AppendManifestToken_SQLiteProviderManifest",
   785    791                     null);
   786    792             }
   787    793   
   788    794             Environment.SetEnvironmentVariable("SQLite_ForceLogPrepare", null);
   789    795             Trace.Listeners.Remove(listener);
   790    796         }
          797  +
          798  +#if NET_40 || NET_45 || NET_451 || NET_46
          799  +      //
          800  +      // NOTE: Used to test the ROUND fix (i.e. being able to properly handle
          801  +      //       the two argument form).
          802  +      //
          803  +      private static int RoundTest()
          804  +      {
          805  +            using (northwindEFEntities db = new northwindEFEntities())
          806  +            {
          807  +                bool once = false;
          808  +
          809  +                foreach (int[] i in new int[][] {
          810  +                        new int[] { 10503, 65 },
          811  +                        new int[] { 10503, 14 },
          812  +                        new int[] { 10635, 5 }
          813  +                    })
          814  +                {
          815  +                    for (int j = 0; j < 3; j++)
          816  +                    {
          817  +                        int oid = i[0];
          818  +                        int pid = i[1];
          819  +
          820  +                        var query = from o in db.OrderDetails
          821  +                                    where o.OrderID == oid && o.ProductID == pid
          822  +                                    select new { NewUnitPrice = Math.Round(o.UnitPrice, j) };
          823  +
          824  +                        foreach (object o in query)
          825  +                        {
          826  +                            if (once)
          827  +                                Console.Write(' ');
          828  +
          829  +                            Console.Write("{0}", o);
          830  +
          831  +                            once = true;
          832  +                        }
          833  +                    }
          834  +                }
          835  +            }
          836  +
          837  +            return 0;
          838  +      }
          839  +#endif
   791    840   
   792    841       private static int OldTests()
   793    842       {
   794    843         using (northwindEFEntities db = new northwindEFEntities())
   795    844         {
   796    845           {
   797    846             string entitySQL = "SELECT VALUE o FROM Orders AS o WHERE SQLite.DatePart('yyyy', o.OrderDate) = 1997 ORDER BY o.OrderID;";

Changes to www/news.wiki.

     5      5   <p>
     6      6       <b>1.0.98.0 - August XX, 2015 <font color="red">(release scheduled)</font></b>
     7      7   </p>
     8      8   <ul>
     9      9       <li>Updated to [https://www.sqlite.org/releaselog/3_8_11.html|SQLite 3.8.11].</li>
    10     10       <li>Add full support for Visual Studio 2015 and the .NET Framework 4.6.</li>
    11     11       <li>Implement the Substring method for LINQ using the &quot;substr&quot; core SQL function.&nbsp;<b>** Potentially Incompatible Change **</b></li>
           12  +    <li>Honor the second argument to Math.Round when using LINQ.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    12     13       <li>Honor the pre-existing flags for connections during the Open method. Fix for [964063da16].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    13     14       <li>Remove errant semi-colons from the SQL used by LINQ to INSERT and then SELECT rows with composite primary keys. Fix for [9d353b0bd8].</li>
    14     15       <li>Change the base type for the SQLiteConnectionFlags enumeration to long integer.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    15     16       <li>Add extended return codes to the SQLiteErrorCode enumeration. Pursuant to [71bedaca19].&nbsp;<b>** Potentially Incompatible Change **</b></li>
    16     17       <li>Improve exception handling in all native callbacks implemented in the SQLiteConnection class.</li>
    17     18       <li>Add Progress event and ProgressOps connection string property to enable raising progress events during long-running queries.</li>
    18     19       <li>Add &quot;Recursive Triggers&quot; connection string property to enable or disable the recursive trigger capability. Pursuant to [3a82ee635b].</li>