private void CorrectSkip(SelectQuery selectQuery) { ((ISqlExpressionWalkable)selectQuery).Walk(new WalkOptions(), e => { if (e is SelectQuery q && q.Select.SkipValue != null && SqlProviderFlags.GetIsSkipSupportedFlag(q) && q.OrderBy.IsEmpty) { if (q.Select.Columns.Count == 0) { var source = q.Select.From.Tables[0].Source; var keys = source.GetKeys(true); foreach (var key in keys) { q.Select.AddNew(key); } } for (var i = 0; i < q.Select.Columns.Count; i++) { q.OrderBy.ExprAsc(new SqlValue(i + 1)); } if (q.OrderBy.IsEmpty) { throw new LinqToDBException("Order by required for Skip operation."); } } return(e); }
protected void CorrectRootSkip(SelectQuery selectQuery) { if (selectQuery != null && selectQuery.Select.SkipValue != null && SqlProviderFlags.GetIsSkipSupportedFlag(selectQuery) && selectQuery.OrderBy.IsEmpty) { if (selectQuery.Select.Columns.Count == 0) { var source = selectQuery.Select.From.Tables[0].Source; var keys = source.GetKeys(true); foreach (var key in keys) { selectQuery.Select.AddNew(key); } } for (var i = 0; i < selectQuery.Select.Columns.Count; i++) { selectQuery.OrderBy.ExprAsc(new SqlValue(i + 1)); } if (selectQuery.OrderBy.IsEmpty) { throw new LinqToDBException("Order by required for Skip operation."); } } }
public override SqlStatement TransformStatement(SqlStatement statement) { statement = SeparateDistinctFromPagination(statement, q => q.Select.SkipValue != null); statement = ReplaceDistinctOrderByWithRowNumber(statement, q => q.Select.SkipValue != null); statement = ReplaceTakeSkipWithRowNumber(statement, query => query.Select.SkipValue != null && SqlProviderFlags.GetIsSkipSupportedFlag(query.Select.TakeValue, query.Select.SkipValue), true); return(statement.QueryType switch { QueryType.Delete => GetAlternativeDelete((SqlDeleteStatement)statement), QueryType.Update => GetAlternativeUpdate((SqlUpdateStatement)statement), _ => statement, });
public override SqlStatement TransformStatement(SqlStatement statement) { // DB2 LUW 9/10 supports only FETCH, v11 adds OFFSET, but for that we need to introduce versions into DB2 provider first statement = SeparateDistinctFromPagination(statement, q => q.Select.SkipValue != null); statement = ReplaceDistinctOrderByWithRowNumber(statement, q => q.Select.SkipValue != null); statement = ReplaceTakeSkipWithRowNumber(statement, query => query.Select.SkipValue != null && SqlProviderFlags.GetIsSkipSupportedFlag(query), true); return(statement.QueryType switch { QueryType.Delete => GetAlternativeDelete((SqlDeleteStatement)statement), QueryType.Update => GetAlternativeUpdate((SqlUpdateStatement)statement), _ => statement, });