Attempts to parse a query into a series of SQL statements. Returns whether or not the parsing was successful. If the parsing was successful, the parsed statements will be stored in the statements variable.
347169 {
347170 Transformer transformer(options);
347171 string parser_error;
347172 optional_idx parser_error_location;
347173 {
347174
347175 string new_query;
347176 if (StripUnicodeSpaces(query, new_query)) {
347177
347179 return;
347180 }
347181 }
347182 {
347183 if (options.extensions) {
347184 bool has_strict_extension_error = false;
347185 ErrorData last_strict_extension_error;
347186 for (auto &ext : options.extensions->ParserExtensions()) {
347187 if (!ext.parser_override) {
347188 continue;
347189 }
347190 if (options.parser_override_setting == AllowParserOverride::DEFAULT_OVERRIDE) {
347191 continue;
347192 }
347193
347194 auto result = ext.parser_override(ext.parser_info.get(), query, options);
347195 if (result.type == ParserExtensionResultType::PARSE_SUCCESSFUL) {
347197 return;
347198 }
347199 if (options.parser_override_setting == AllowParserOverride::STRICT_OVERRIDE) {
347200 if (result.type == ParserExtensionResultType::DISPLAY_EXTENSION_ERROR) {
347201 has_strict_extension_error = true;
347202 last_strict_extension_error = std::move(result.error);
347203 } else {
347204 has_strict_extension_error = false;
347205 }
347206 continue;
347207 } else if (options.parser_override_setting == AllowParserOverride::FALLBACK_OVERRIDE) {
347208 continue;
347209 }
347210 }
347211 if (options.parser_override_setting == AllowParserOverride::STRICT_OVERRIDE && has_strict_extension_error) {
347212 last_strict_extension_error.
Throw();
347213 }
347214 }
347215 PostgresParser::SetPreserveIdentifierCase(options.preserve_identifier_case);
347216 bool parsing_succeed = false;
347217
347218
347219 {
347220 PostgresParser parser;
347221 parser.Parse(query);
347222 if (parser.success) {
347223 if (!parser.parse_tree) {
347224
347225 return;
347226 }
347227
347228
347229
347230 transformer.TransformParseTree(parser.parse_tree,
statements);
347231 parsing_succeed = true;
347232 } else {
347233 parser_error = parser.error_message;
347234 if (parser.error_location > 0) {
347235 parser_error_location = NumericCast<idx_t>(parser.error_location - 1);
347236 }
347237 }
347238 }
347239
347240
347241 if (parsing_succeed) {
347242
347243
347244
347245 } else if (!options.extensions || !options.extensions->HasParserExtensions()) {
347246 throw ParserException::SyntaxError(query, parser_error, parser_error_location);
347247 } else {
347248
347249 auto queries = SplitQueries(query);
347250 idx_t stmt_loc = 0;
347251 for (auto const &query_statement : queries) {
347252 ErrorData another_parser_error;
347253
347254 {
347255 PostgresParser another_parser;
347256 another_parser.Parse(query_statement);
347257
347258
347259 if (another_parser.success) {
347260 if (!another_parser.parse_tree) {
347261
347262 continue;
347263 }
347264 transformer.TransformParseTree(another_parser.parse_tree,
statements);
347265
347266 statements.back()->stmt_length = query_statement.size() - 1;
347267 statements.back()->stmt_location = stmt_loc;
347268 stmt_loc += query_statement.size();
347269 continue;
347270 } else {
347271 another_parser_error = ErrorData(another_parser.error_message);
347272 if (another_parser.error_location > 0) {
347273 another_parser_error.AddQueryLocation(
347274 NumericCast<idx_t>(another_parser.error_location - 1));
347275 }
347276 }
347277 }
347278
347279
347280 bool parsed_single_statement = false;
347281 for (auto &ext : options.extensions->ParserExtensions()) {
347282 D_ASSERT(!parsed_single_statement);
347283 if (!ext.parse_function) {
347284 continue;
347285 }
347286 auto result = ext.parse_function(ext.parser_info.get(), query_statement);
347287 if (result.type == ParserExtensionResultType::PARSE_SUCCESSFUL) {
347288 auto statement = make_uniq<ExtensionStatement>(ext, std::move(result.parse_data));
347289 statement->stmt_length = query_statement.size() - 1;
347290 statement->stmt_location = stmt_loc;
347291 stmt_loc += query_statement.size();
347292 statements.push_back(std::move(statement));
347293 parsed_single_statement = true;
347294 break;
347295 } else if (result.type == ParserExtensionResultType::DISPLAY_EXTENSION_ERROR) {
347296 throw ParserException::SyntaxError(query, result.error, result.error_location);
347297 } else {
347298
347299 }
347300 }
347301 if (!parsed_single_statement) {
347302 throw ParserException::SyntaxError(query, parser_error, parser_error_location);
347303 }
347304 }
347305 }
347306 }
347309 last_statement->stmt_length = query.size() - last_statement->stmt_location;
347311 statement->query = query.substr(statement->stmt_location, statement->stmt_length);
347312 statement->stmt_location = 0;
347313 statement->stmt_length = statement->query.size();
347314 if (statement->type == StatementType::CREATE_STATEMENT) {
347315 auto &
create = statement->Cast<CreateStatement>();
347316 create.info->sql = statement->query;
347317 }
347318 }
347319 }
347320}
DUCKDB_API void Throw(const string &prepended_message="") const
Throw the error.
Definition duckdb.cpp:70200
vector< unique_ptr< SQLStatement > > statements
The parsed SQL statements from an invocation to ParseQuery.
Definition duckdb.cpp:23954
void ParseQuery(const string &query)
Attempts to parse a query into a series of SQL statements. Returns whether or not the parsing was suc...
Definition duckdb.cpp:347169
static cv::Ptr< QuasiDenseStereo > create(cv::Size monoImgSize, cv::String paramFilepath=cv::String())
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237