* validateSQLNamePattern * * Wrapper around string_utils's processSQLNamePattern which also checks the * pattern's validity. In addition to that function's parameters, takes a * 'maxparts' parameter specifying the maximum number of dotted names the * pattern is allowed to have, and a 'added_clause' parameter that returns by * reference whether a clause was added to 'buf'. Returns whether t
| 7366 | * passed validation, after logging any errors. |
| 7367 | */ |
| 7368 | static bool |
| 7369 | validateSQLNamePattern(PQExpBuffer buf, const char *pattern, bool have_where, |
| 7370 | bool force_escape, const char *schemavar, |
| 7371 | const char *namevar, const char *altnamevar, |
| 7372 | const char *visibilityrule, bool *added_clause, |
| 7373 | int maxparts) |
| 7374 | { |
| 7375 | PQExpBufferData dbbuf; |
| 7376 | int dotcnt; |
| 7377 | bool added; |
| 7378 | |
| 7379 | initPQExpBuffer(&dbbuf); |
| 7380 | added = processSQLNamePattern(pset.db, buf, pattern, have_where, force_escape, |
| 7381 | schemavar, namevar, altnamevar, |
| 7382 | visibilityrule, &dbbuf, &dotcnt); |
| 7383 | if (added_clause != NULL) |
| 7384 | *added_clause = added; |
| 7385 | |
| 7386 | if (dotcnt >= maxparts) |
| 7387 | { |
| 7388 | pg_log_error("improper qualified name (too many dotted names): %s", |
| 7389 | pattern); |
| 7390 | termPQExpBuffer(&dbbuf); |
| 7391 | return false; |
| 7392 | } |
| 7393 | |
| 7394 | if (maxparts > 1 && dotcnt == maxparts-1) |
| 7395 | { |
| 7396 | if (PQdb(pset.db) == NULL) |
| 7397 | { |
| 7398 | pg_log_error("You are currently not connected to a database."); |
| 7399 | return false; |
| 7400 | } |
| 7401 | if (strcmp(PQdb(pset.db), dbbuf.data) != 0) |
| 7402 | { |
| 7403 | pg_log_error("cross-database references are not implemented: %s", |
| 7404 | pattern); |
| 7405 | return false; |
| 7406 | } |
| 7407 | } |
| 7408 | return true; |
| 7409 | } |
| 7410 | |
| 7411 | /* |
| 7412 | * \dRp |
no test coverage detected