| 219 | } |
| 220 | |
| 221 | void 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 | } |