Validate SELECT statement
(
select_stmt: &SelectStatement,
ctx: &mut ValidationContext,
errors: &mut Vec<ValidationError>,
)
| 2330 | |
| 2331 | /// Validate SELECT statement |
| 2332 | fn validate_select_statement( |
| 2333 | select_stmt: &SelectStatement, |
| 2334 | ctx: &mut ValidationContext, |
| 2335 | errors: &mut Vec<ValidationError>, |
| 2336 | ) { |
| 2337 | // Validate return items structure |
| 2338 | match &select_stmt.return_items { |
| 2339 | SelectItems::Wildcard { .. } => { |
| 2340 | // Wildcard (*) is always valid |
| 2341 | } |
| 2342 | SelectItems::Explicit { items, .. } => { |
| 2343 | if items.is_empty() { |
| 2344 | errors.push(ValidationError { |
| 2345 | message: "SELECT statement must have at least one return item".to_string(), |
| 2346 | location: Some(select_stmt.location.clone()), |
| 2347 | error_type: ValidationErrorType::Structural, |
| 2348 | }); |
| 2349 | } |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | // Validate FROM clause FIRST to declare variables |
| 2354 | if let Some(from_clause) = &select_stmt.from_clause { |
| 2355 | validate_from_clause(from_clause, ctx, errors); |
| 2356 | } |
| 2357 | |
| 2358 | // Validate return item expressions AFTER variables are declared |
| 2359 | match &select_stmt.return_items { |
| 2360 | SelectItems::Wildcard { .. } => { |
| 2361 | // Wildcard is always valid, no expressions to validate |
| 2362 | } |
| 2363 | SelectItems::Explicit { items, .. } => { |
| 2364 | for item in items { |
| 2365 | validate_expression(&item.expression, ctx, errors); |
| 2366 | } |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | // Validate WHERE clause if present |
| 2371 | if let Some(where_clause) = &select_stmt.where_clause { |
| 2372 | validate_expression(&where_clause.condition, ctx, errors); |
| 2373 | } |
| 2374 | |
| 2375 | // Validate GROUP BY clause if present |
| 2376 | if let Some(group_clause) = &select_stmt.group_clause { |
| 2377 | for expr in &group_clause.expressions { |
| 2378 | validate_expression(expr, ctx, errors); |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | // Validate HAVING clause if present |
| 2383 | if let Some(having_clause) = &select_stmt.having_clause { |
| 2384 | validate_expression(&having_clause.condition, ctx, errors); |
| 2385 | } |
| 2386 | |
| 2387 | // Validate ORDER BY clause if present |
| 2388 | if let Some(order_clause) = &select_stmt.order_clause { |
| 2389 | for item in &order_clause.items { |
no test coverage detected