Parse RETURN columns.
(text: &str)
| 98 | |
| 99 | /// Parse RETURN columns. |
| 100 | pub(super) fn parse_return(text: &str) -> (Vec<ReturnColumn>, bool) { |
| 101 | let trimmed = text.trim(); |
| 102 | if trimmed.is_empty() || trimmed == "*" { |
| 103 | return (Vec::new(), false); |
| 104 | } |
| 105 | |
| 106 | // Strip DISTINCT keyword. |
| 107 | let (effective, distinct) = { |
| 108 | let upper = trimmed.to_uppercase(); |
| 109 | if upper.starts_with("DISTINCT ") { |
| 110 | (&trimmed[9..], true) |
| 111 | } else { |
| 112 | (trimmed, false) |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | let columns = split_top_level_commas(effective) |
| 117 | .into_iter() |
| 118 | .map(|col| { |
| 119 | let col = col.trim(); |
| 120 | let upper = col.to_uppercase(); |
| 121 | if let Some(as_pos) = upper.rfind(" AS ") { |
| 122 | let expr = col[..as_pos].trim().to_string(); |
| 123 | let alias = col[as_pos + 4..].trim().to_string(); |
| 124 | ReturnColumn { |
| 125 | expr, |
| 126 | alias: Some(alias), |
| 127 | } |
| 128 | } else { |
| 129 | ReturnColumn { |
| 130 | expr: col.to_string(), |
| 131 | alias: None, |
| 132 | } |
| 133 | } |
| 134 | }) |
| 135 | .collect(); |
| 136 | (columns, distinct) |
| 137 | } |
| 138 | |
| 139 | /// Parse ORDER BY columns. |
| 140 | pub(super) fn parse_order_by(text: &str) -> Vec<OrderByColumn> { |
no test coverage detected