Diff of /System.Data.SQLite.Linq/SQL Generation/SqlGenerator.cs [ac1c15] .. [cae66b]  Maximize  Restore

  Switch to side-by-side view

--- a/System.Data.SQLite.Linq/SQL Generation/SqlGenerator.cs
+++ b/System.Data.SQLite.Linq/SQL Generation/SqlGenerator.cs
@@ -1365,19 +1365,8 @@
       Debug.Assert(e.Limit is DbConstantExpression || e.Limit is DbParameterReferenceExpression, "DbLimitExpression.Limit is of invalid expression type");
 
       SqlSelectStatement result = VisitExpressionEnsureSqlStatement(e.Argument, false);
-      Symbol fromSymbol;
-
-      if (!IsCompatible(result, e.ExpressionKind))
-      {
-        TypeUsage inputType = MetadataHelpers.GetElementTypeUsage(e.Argument.ResultType);
-
-        result = CreateNewSelectStatement(result, "top", inputType, out fromSymbol);
-        AddFromSymbol(result, "top", fromSymbol, false);
-      }
-
-      ISqlFragment topCount = HandleCountExpression(e.Limit);
-
-      result.Top = new TopClause(topCount, e.WithTies);
+      
+      result.Limit = ((DbConstantExpression)e.Limit).Value.ToString(); 
       return result;
     }
 
@@ -1694,13 +1683,35 @@
     ///     ) as Y
     /// WHERE Y.[row_number] > count 
     /// ORDER BY sk1, sk2, ...
+    /// OFFSET [row_number]
     /// </summary>
     /// <param name="e"></param>
     /// <returns>A <see cref="SqlBuilder"/></returns>
     public override ISqlFragment Visit(DbSkipExpression e)
     {
-      // Should never get here.  The Sql2000 rewriter would've rewritten the command tree not to use this
-      throw new NotSupportedException();
+      Symbol fromSymbol;
+      //order by is included in the skip expression when this is in the tree
+      SqlSelectStatement result = VisitInputExpression(e.Input.Expression, e.Input.VariableName, e.Input.VariableType, out fromSymbol);
+        
+      // OrderBy is compatible with Filter
+      // and nothing else
+      if (!IsCompatible(result, e.ExpressionKind))
+      {
+          result = CreateNewSelectStatement(result, e.Input.VariableName, e.Input.VariableType, out fromSymbol);
+      }
+
+      selectStatementStack.Push(result);
+      symbolTable.EnterScope();
+
+      AddFromSymbol(result, e.Input.VariableName, fromSymbol);
+
+      AddSortKeys(result.OrderBy, e.SortOrder);
+
+      symbolTable.ExitScope();
+      selectStatementStack.Pop();
+      result.OffSet = ((DbConstantExpression)e.Count).Value.ToString();
+      return result;
+
     }
 
     /// <summary>