From fa049cf423ea56e4b7e1b732b8fd6aee60ea2367 Mon Sep 17 00:00:00 2001 From: Kyrylo Simonov Date: Sat, 31 Aug 2024 11:42:37 -0500 Subject: [PATCH] Add LIMIT_STYLE.ADQL --- src/dialects.jl | 5 ++++- src/serialize.jl | 15 +++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/dialects.jl b/src/dialects.jl index 6bc22ac5..6c853933 100644 --- a/src/dialects.jl +++ b/src/dialects.jl @@ -25,6 +25,7 @@ import .VARIABLE_STYLE.VariableStyle module LIMIT_STYLE @enum LimitStyle::UInt8 begin + ADQL ANSI MYSQL POSTGRESQL @@ -33,6 +34,8 @@ module LIMIT_STYLE end Base.convert(::Type{LimitStyle}, s::Symbol) = + s in (:adql, :ADQL) ? + ADQL : s in (:ansi, :ANSI) ? ANSI : s in (:mysql, :MYSQL) ? @@ -44,7 +47,7 @@ Base.convert(::Type{LimitStyle}, s::Symbol) = s in (:sqlserver, :SQLSERVER) ? SQLSERVER : throw(DomainError(QuoteNode(s), - "expected :ansi, :mysql, :postgresql, :sqlite, or :sqlserver")) + "expected :adql, :ansi, :mysql, :postgresql, :sqlite, or :sqlserver")) end diff --git a/src/serialize.jl b/src/serialize.jl index bebb4dda..b0e5a4f3 100644 --- a/src/serialize.jl +++ b/src/serialize.jl @@ -632,14 +632,14 @@ function serialize!(c::LimitClause, ctx) start = c.offset count = c.limit start !== nothing || count !== nothing || return - if ctx.dialect.limit_style === LIMIT_STYLE.MYSQL + if ctx.dialect.limit_style == LIMIT_STYLE.MYSQL newline(ctx) print(ctx, "LIMIT ") if start !== nothing print(ctx, start, ", ") end print(ctx, count !== nothing ? count : "18446744073709551615") - elseif ctx.dialect.limit_style == LIMIT_STYLE.POSTGRESQL + elseif ctx.dialect.limit_style in (LIMIT_STYLE.POSTGRESQL, LIMIT_STYLE.ADQL) if count !== nothing newline(ctx) print(ctx, "LIMIT ", count) @@ -648,7 +648,7 @@ function serialize!(c::LimitClause, ctx) newline(ctx) print(ctx, "OFFSET ", start) end - elseif ctx.dialect.limit_style === LIMIT_STYLE.SQLITE + elseif ctx.dialect.limit_style == LIMIT_STYLE.SQLITE newline(ctx) print(ctx, "LIMIT ", count !== nothing ? count : -1) if start !== nothing @@ -806,12 +806,19 @@ function serialize!(c::SelectClause, ctx) if top !== nothing limit = top.limit with_ties = top.with_ties - elseif ctx.dialect.limit_style === LIMIT_STYLE.SQLSERVER + elseif ctx.dialect.limit_style == LIMIT_STYLE.SQLSERVER if @dissect(over, limit_over |> LIMIT(offset = nothing, limit = limit, with_ties = with_ties)) over = limit_over elseif nested && @dissect(over, ORDER()) offset_0_rows = true end + elseif ctx.dialect.limit_style == LIMIT_STYLE.ADQL + if @dissect(over, limit_over |> LIMIT(offset = offset, limit = limit, with_ties = with_ties)) + over = limit_over + if offset !== nothing + over = LIMIT(over = over, offset = offset) + end + end end print(ctx, "SELECT") if limit !== nothing