1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Common Table Expression (CTE) and SQL set operation specifications.
//!
//! `CteSpec` supports both raw-mode (pre-compiled SQL) and typed-mode
//! (compile-from-`BoolExpr`) CTEs, including recursive CTEs that emit
//! `WITH RECURSIVE ... UNION ALL SELECT ... JOIN name ON ...`.
//!
//! `SetOperator` / `SetOpSpec` represent UNION / INTERSECT / EXCEPT
//! operands appended after the main SELECT.
use crateDbValue;
use BoolExpr;
/// Specification for a Common Table Expression (CTE).
///
/// A CTE is defined by a name and either a pre-compiled SQL string (raw mode)
/// or a typed WHERE expression compiled at SQL generation time (typed mode).
/// The main query references the CTE by name (typically in its FROM clause).
/// Parameters are prepended to the main query's parameter list in CTE
/// declaration order.
///
/// ## Modes
///
/// - **Raw mode** (via `with_cte_internal`): `sql` is non-empty, `table` and
/// `where_expr` are empty. The SQL is emitted verbatim. Placeholders use
/// the `?` style and are **not** converted to provider-specific syntax —
/// suitable for SQLite/MySQL but may produce incorrect `$N` on PostgreSQL.
///
/// - **Typed mode** (via `with_cte_typed`, used by `linq!(with ...)`): `table`
/// is non-empty, `where_expr` is `Some(...)`, `sql` is empty. The CTE body
/// `SELECT * FROM <table> WHERE <expr>` is compiled at `to_sql_with` time
/// using the provider's placeholder syntax, ensuring correct `$N` numbering
/// on all providers.
///
/// `#[non_exhaustive]` prevents direct struct construction outside the crate
/// so future field additions don't break downstream code. Use
/// `with_cte_internal` (raw mode) or `with_cte_typed` (typed mode) to create
/// CTE specifications.
/// SQL set operators for combining result sets (UNION / INTERSECT / EXCEPT).
/// A set operation operand: a pre-compiled SQL string and its bound params.
///
/// Per D5, operands should not contain ORDER BY / LIMIT (caller responsibility).