* Look up the object identified by obj_type and desc. If successful, * store its OID in *obj_oid and return true, else return false. * * Note that we'll fail if the object doesn't exist OR if there are multiple * matching candidates OR if there's something syntactically wrong with the * object description; unfortunately it can be hard to tell the difference. */
| 5045 | * object description; unfortunately it can be hard to tell the difference. |
| 5046 | */ |
| 5047 | static bool |
| 5048 | lookup_object_oid(EditableObjectType obj_type, const char *desc, |
| 5049 | Oid *obj_oid) |
| 5050 | { |
| 5051 | bool result = true; |
| 5052 | PQExpBuffer query = createPQExpBuffer(); |
| 5053 | PGresult *res; |
| 5054 | |
| 5055 | switch (obj_type) |
| 5056 | { |
| 5057 | case EditableFunction: |
| 5058 | |
| 5059 | /* |
| 5060 | * We have a function description, e.g. "x" or "x(int)". Issue a |
| 5061 | * query to retrieve the function's OID using a cast to regproc or |
| 5062 | * regprocedure (as appropriate). |
| 5063 | */ |
| 5064 | appendPQExpBufferStr(query, "SELECT "); |
| 5065 | appendStringLiteralConn(query, desc, pset.db); |
| 5066 | appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid", |
| 5067 | strchr(desc, '(') ? "regprocedure" : "regproc"); |
| 5068 | break; |
| 5069 | |
| 5070 | case EditableView: |
| 5071 | |
| 5072 | /* |
| 5073 | * Convert view name (possibly schema-qualified) to OID. Note: |
| 5074 | * this code doesn't check if the relation is actually a view. |
| 5075 | * We'll detect that in get_create_object_cmd(). |
| 5076 | */ |
| 5077 | appendPQExpBufferStr(query, "SELECT "); |
| 5078 | appendStringLiteralConn(query, desc, pset.db); |
| 5079 | appendPQExpBufferStr(query, "::pg_catalog.regclass::pg_catalog.oid"); |
| 5080 | break; |
| 5081 | } |
| 5082 | |
| 5083 | if (!echo_hidden_command(query->data)) |
| 5084 | { |
| 5085 | destroyPQExpBuffer(query); |
| 5086 | return false; |
| 5087 | } |
| 5088 | res = PQexec(pset.db, query->data); |
| 5089 | if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1) |
| 5090 | *obj_oid = atooid(PQgetvalue(res, 0, 0)); |
| 5091 | else |
| 5092 | { |
| 5093 | minimal_error_message(res); |
| 5094 | result = false; |
| 5095 | } |
| 5096 | |
| 5097 | PQclear(res); |
| 5098 | destroyPQExpBuffer(query); |
| 5099 | |
| 5100 | return result; |
| 5101 | } |
| 5102 | |
| 5103 | /* |
| 5104 | * Construct a "CREATE OR REPLACE ..." command that describes the specified |
no test coverage detected