(&self, input: &str)
| 74 | } |
| 75 | |
| 76 | fn validate_input(&self, input: &str) -> Result<ValidationResult> { |
| 77 | if let Some(sql) = input.strip_suffix(';') { |
| 78 | let dialect = match dialect_from_str(self.dialect) { |
| 79 | Some(dialect) => dialect, |
| 80 | None => { |
| 81 | return Ok(ValidationResult::Invalid(Some(format!( |
| 82 | " 🤔 Invalid dialect: {}", |
| 83 | self.dialect |
| 84 | )))); |
| 85 | } |
| 86 | }; |
| 87 | let lines = split_from_semicolon(sql); |
| 88 | for line in lines { |
| 89 | match DFParser::parse_sql_with_dialect(&line, dialect.as_ref()) { |
| 90 | Ok(statements) if statements.is_empty() => { |
| 91 | return Ok(ValidationResult::Invalid(Some( |
| 92 | " 🤔 You entered an empty statement".to_string(), |
| 93 | ))); |
| 94 | } |
| 95 | Ok(_statements) => {} |
| 96 | Err(err) => { |
| 97 | return Ok(ValidationResult::Invalid(Some(format!( |
| 98 | " 🤔 Invalid statement: {err}", |
| 99 | )))); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | Ok(ValidationResult::Valid(None)) |
| 104 | } else if input.starts_with('\\') { |
| 105 | // command |
| 106 | Ok(ValidationResult::Valid(None)) |
| 107 | } else { |
| 108 | Ok(ValidationResult::Incomplete) |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | impl Default for CliHelper { |
no test coverage detected