System.Data.SQLite
Check-in [a9d19a3b28]
Not logged in

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

Overview
Comment:Rewrite previous fix for [0a32885109] so it retains the ORDER BY, LIMIT, and OFFSET clauses.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tkt-0a32885109
Files: files | file ages | folders
SHA1: a9d19a3b28d144df2d284a5e652ac1973f34dfba
User & Date: mistachkin 2014-11-13 23:58:15
Context
2014-11-14
00:04
Update version history docs. check-in: da73ebd20d user: mistachkin tags: tkt-0a32885109
2014-11-13
23:58
Rewrite previous fix for [0a32885109] so it retains the ORDER BY, LIMIT, and OFFSET clauses. check-in: a9d19a3b28 user: mistachkin tags: tkt-0a32885109
2014-11-08
06:45
Remove UTF-8 BOM. check-in: 33014329d6 user: mistachkin tags: tkt-0a32885109
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

2466
2467
2468
2469
2470
2471
2472

2473

2474
2475
2476
2477
2478
2479


2480
2481
2482
2483




2484
2485
2486




2487



2488
2489
2490
2491
2492
2493
2494
      return result;
    }

    ISqlFragment VisitSetOpExpression(DbExpression left, DbExpression right, string separator)
    {

      SqlSelectStatement leftSelectStatement = VisitExpressionEnsureSqlStatement(left);

      SqlSelectStatement rightSelectStatement = VisitExpressionEnsureSqlStatement(right);


      //
      // BUGFIX: [0a32885109] When using compound operators (e.g. UNION ALL),
      //         the non-rightmost SELECT statement(s) may NOT have an ORDER
      //         BY, LIMIT, or OFFSET clause.
      //


      leftSelectStatement.ClearOrderByLimitAndOffset();

      SqlBuilder setStatement = new SqlBuilder();
      setStatement.Append(leftSelectStatement);




      setStatement.AppendLine();
      setStatement.Append(separator); // e.g. UNION ALL
      setStatement.AppendLine();




      setStatement.Append(rightSelectStatement);




      return setStatement;
    }


    #endregion








>

>

<
<
|
<
<
>
>
|

<

>
>
>
>



>
>
>
>

>
>
>







2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476


2477


2478
2479
2480
2481

2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
      return result;
    }

    ISqlFragment VisitSetOpExpression(DbExpression left, DbExpression right, string separator)
    {

      SqlSelectStatement leftSelectStatement = VisitExpressionEnsureSqlStatement(left);
      bool leftOrderByLimitOrOffset = leftSelectStatement.HaveOrderByLimitOrOffset();
      SqlSelectStatement rightSelectStatement = VisitExpressionEnsureSqlStatement(right);
      bool rightOrderByLimitOrOffset = rightSelectStatement.HaveOrderByLimitOrOffset();



      SqlBuilder setStatement = new SqlBuilder();



      if (leftOrderByLimitOrOffset)
          setStatement.Append("SELECT * FROM (");


      setStatement.Append(leftSelectStatement);

      if (leftOrderByLimitOrOffset)
          setStatement.Append(") ");

      setStatement.AppendLine();
      setStatement.Append(separator); // e.g. UNION ALL
      setStatement.AppendLine();

      if (rightOrderByLimitOrOffset)
          setStatement.Append("SELECT * FROM (");

      setStatement.Append(rightSelectStatement);

      if (rightOrderByLimitOrOffset)
          setStatement.Append(") ");

      return setStatement;
    }


    #endregion

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

193
194
195
196
197
198
199
200
201
202




203
204


205


206



207
208
209
210
211
212
213
    internal bool IsTopMost
    {
      get { return this.isTopMost; }
      set { this.isTopMost = value; }
    }

    /// <summary>
    /// Clears the ORDER BY, LIMIT, and OFFSET clauses.
    /// </summary>
    public void ClearOrderByLimitAndOffset()




    {
        this.orderBy = null;


        this.top = null;


        this.skip = null;



    }

    #region ISqlFragment Members

    /// <summary>
    /// Write out a SQL select statement as a string.
    /// We have to







|

|
>
>
>
>

|
>
>
|
>
>
|
>
>
>







193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
    internal bool IsTopMost
    {
      get { return this.isTopMost; }
      set { this.isTopMost = value; }
    }

    /// <summary>
    /// Checks if the statement has an ORDER BY, LIMIT, or OFFSET clause.
    /// </summary>
    /// <returns>
    /// Non-zero if there is an ORDER BY, LIMIT, or OFFSET clause;
    /// otherwise, zero.
    /// </returns>
    public bool HaveOrderByLimitOrOffset()
    {
        if ((this.orderBy != null) && !this.orderBy.IsEmpty)
            return true;

        if (this.top != null)
            return true;

        if (this.skip != null)
            return true;

        return false;
    }

    #region ISqlFragment Members

    /// <summary>
    /// Write out a SQL select statement as a string.
    /// We have to

Changes to Tests/tkt-0a32885109.eagle.

51
52
53
54
55
56
57
58
59
60
61
62
63
64
  }

  set result
} -cleanup {
  unset -nocomplain code output error result
} -constraints {eagle monoToDo SQLite file_System.Data.SQLite.dll testExec\
file_System.Data.SQLite.Linq.dll file_testlinq.exe file_northwindEF.db} \
-result {0 {WHITC ANATR BERGS ALFKI BSBEV}}}

###############################################################################

runSQLiteTestFilesEpilogue
runSQLiteTestEpilogue
runTestEpilogue







|






51
52
53
54
55
56
57
58
59
60
61
62
63
64
  }

  set result
} -cleanup {
  unset -nocomplain code output error result
} -constraints {eagle monoToDo SQLite file_System.Data.SQLite.dll testExec\
file_System.Data.SQLite.Linq.dll file_testlinq.exe file_northwindEF.db} \
-result {0 {WHITC ANATR BERGS WHITC ANATR WHITC ANATR BERGS}}}

###############################################################################

runSQLiteTestFilesEpilogue
runSQLiteTestEpilogue
runTestEpilogue