1#include "duckdb/verification/parsed_statement_verifier.hpp"
2
3#include "duckdb/parser/parser.hpp"
4
5namespace duckdb {
6
7ParsedStatementVerifier::ParsedStatementVerifier(unique_ptr<SQLStatement> statement_p)
8 : StatementVerifier(VerificationType::PARSED, "Parsed", std::move(statement_p)) {
9}
10
11unique_ptr<StatementVerifier> ParsedStatementVerifier::Create(const SQLStatement &statement) {
12 auto query_str = statement.ToString();
13 Parser parser;
14 try {
15 parser.ParseQuery(query: query_str);
16 } catch (std::exception &ex) {
17 throw InternalException("Parsed statement verification failed. Query:\n%s\n\nError: %s", query_str, ex.what());
18 }
19 D_ASSERT(parser.statements.size() == 1);
20 D_ASSERT(parser.statements[0]->type == StatementType::SELECT_STATEMENT);
21 return make_uniq<ParsedStatementVerifier>(args: std::move(parser.statements[0]));
22}
23
24} // namespace duckdb
25