NAME

DBIO::Sybase::SQLMaker - Sybase ASE-specific SQL generation for DBIO

VERSION

version 0.900007

DESCRIPTION

DBIO::SQLMaker subclass for Sybase ASE (Adaptive Server Enterprise). ASE has no native LIMIT/OFFSET keyword, so this class overrides "apply_limit" to emit ASE-valid pagination.

Used automatically by DBIO::Sybase::Storage::ASE.

NULLS FIRST / NULLS LAST (the -nulls key of an order_by entry) is emulated, ASE has no such clause. The sort key is preceded by a sort on a CASE that tells the NULLs from the rest: { -asc => 'col', -nulls => 'first' } renders CASE WHEN col IS NULL THEN 0 ELSE 1 END, col ASC, and -nulls => 'last' renders CASE WHEN col IS NULL THEN 1 ELSE 0 END, col ASC -- the rows come back in the same order as on PostgreSQL, for -desc too. The column expression is rendered twice, so a bind inside it is bound twice, in order. See "_render_op_nulls".

METHODS

_order_by_chunks

The limit dialects ("_GenericSubQ" in DBIO::SQLMaker::ClassicExtensions) take the rendered chunks of an order_by apart as strings, looking for ASC|DESC [NULLS FIRST|LAST] at the end of each. The emulation is a prefix and would leave them nothing to read, so while chunks are taken the ops render as SQL::Abstract does, expr ASC NULLS FIRST; the dialect then builds its own order_by from the parts and that one is rendered, with the emulation, by "_render_op_nulls". Nothing of the standard form reaches the statement.

_render_op_nulls

Renders the nulls_first / nulls_last ops SQL::Abstract builds for -nulls as CASE WHEN expr IS NULL THEN a ELSE b END, expr [ASC|DESC]. The wrapped node is the sort entry expr ASC|DESC (or a bare expr); the leading CASE is 0 for a NULL and 1 for any other value to put the NULLs first, the other way round to put them last.

apply_limit

my $sql = $sqlmaker->apply_limit($sql, $rs_attrs, $rows, $offset);

ASE has no LIMIT/OFFSET keyword. DBIO targets the database-agnostic GenericSubQ dialect: the query is sliced by a correlated WHERE ( SELECT COUNT(*) ... ) BETWEEN ? AND ? subquery against a stable, main-table-based order. This is the same dialect DBIx::Class used for ASE, because ASE has no single windowing/TOP construct that works reliably for all query shapes across server versions. Replaces the DBIx::Class sql_limit_dialect string dispatch.

The rows-only case (no offset) never reaches this method: it is handled earlier by "_prep_for_execute" in DBIO::Sybase::Storage::ASE via SET ROWCOUNT, which strips the limit before this SQLMaker runs.

GenericSubQ requires a stable, main-table-based order_by; a resultset with an offset but no such order raises an exception (this is intentional, see "_GenericSubQ" in DBIO::SQLMaker::ClassicExtensions).

SEE ALSO

AUTHOR

DBIO & DBIx::Class Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.