MCPcopy Create free account
hub / github.com/duckdb/duckdb / ParseQuery

Method ParseQuery

src/parser/parser.cpp:221–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221void Parser::ParseQuery(const string &query) {
222 Transformer transformer(options);
223 string parser_error;
224 optional_idx parser_error_location;
225 {
226 // check if there are any unicode spaces in the string
227 string new_query;
228 if (StripUnicodeSpaces(query, new_query)) {
229 // there are - strip the unicode spaces and re-run the query
230 ParseQuery(new_query);
231 return;
232 }
233 }
234 {
235 if (options.extensions) {
236 bool has_strict_extension_error = false;
237 ErrorData last_strict_extension_error;
238 for (auto &ext : options.extensions->ParserExtensions()) {
239 if (!ext.parser_override) {
240 continue;
241 }
242 if (options.parser_override_setting == AllowParserOverride::DEFAULT_OVERRIDE) {
243 continue;
244 }
245
246 auto result = ext.parser_override(ext.parser_info.get(), query, options);
247 if (result.type == ParserExtensionResultType::PARSE_SUCCESSFUL) {
248 statements = std::move(result.statements);
249 return;
250 }
251 if (options.parser_override_setting == AllowParserOverride::STRICT_OVERRIDE) {
252 if (result.type == ParserExtensionResultType::DISPLAY_EXTENSION_ERROR) {
253 has_strict_extension_error = true;
254 last_strict_extension_error = std::move(result.error);
255 } else {
256 has_strict_extension_error = false;
257 }
258 continue;
259 } else if (options.parser_override_setting == AllowParserOverride::FALLBACK_OVERRIDE) {
260 continue;
261 }
262 }
263 if (options.parser_override_setting == AllowParserOverride::STRICT_OVERRIDE && has_strict_extension_error) {
264 last_strict_extension_error.Throw();
265 }
266 }
267 PostgresParser::SetPreserveIdentifierCase(options.preserve_identifier_case);
268 bool parsing_succeed = false;
269 // Creating a new scope to prevent multiple PostgresParser destructors being called
270 // which led to some memory issues
271 {
272 PostgresParser parser;
273 parser.Parse(query);
274 if (parser.success) {
275 if (!parser.parse_tree) {
276 // empty statement
277 return;
278 }

Callers 15

mainFunction · 0.80
test_helperFunction · 0.80
test_helper_multi_dbFunction · 0.80
test_deserializationFunction · 0.80
TryReparsePragmaMethod · 0.80
ParseSubqueryFunction · 0.80
DuckDBLogBindReplaceFunction · 0.80
PragmaImportDatabaseFunction · 0.80
BindReplaceInternalMethod · 0.80
ParseExpressionListMethod · 0.80
ParseGroupByListMethod · 0.80

Calls 14

StripUnicodeSpacesFunction · 0.85
SplitQueriesFunction · 0.85
ParserExtensionsMethod · 0.80
TransformParseTreeMethod · 0.80
HasParserExtensionsMethod · 0.80
AddQueryLocationMethod · 0.80
ErrorDataClass · 0.50
getMethod · 0.45
ThrowMethod · 0.45
ParseMethod · 0.45
backMethod · 0.45
sizeMethod · 0.45

Tested by 3

test_helperFunction · 0.64
test_helper_multi_dbFunction · 0.64
test_deserializationFunction · 0.64