* getOperators: * read all operators in the system catalogs and return them in the * OprInfo* structure * * numOprs is set to the number of operators read in */
| 6171 | * numOprs is set to the number of operators read in |
| 6172 | */ |
| 6173 | OprInfo * |
| 6174 | getOperators(Archive *fout, int *numOprs) |
| 6175 | { |
| 6176 | PGresult *res; |
| 6177 | int ntups; |
| 6178 | int i; |
| 6179 | PQExpBuffer query = createPQExpBuffer(); |
| 6180 | OprInfo *oprinfo; |
| 6181 | int i_tableoid; |
| 6182 | int i_oid; |
| 6183 | int i_oprname; |
| 6184 | int i_oprnamespace; |
| 6185 | int i_rolname; |
| 6186 | int i_oprkind; |
| 6187 | int i_oprcode; |
| 6188 | |
| 6189 | /* |
| 6190 | * find all operators, including builtin operators; we filter out |
| 6191 | * system-defined operators at dump-out time. |
| 6192 | */ |
| 6193 | |
| 6194 | appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, " |
| 6195 | "oprnamespace, " |
| 6196 | "(%s oprowner) AS rolname, " |
| 6197 | "oprkind, " |
| 6198 | "oprcode::oid AS oprcode " |
| 6199 | "FROM pg_operator", |
| 6200 | username_subquery); |
| 6201 | |
| 6202 | res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); |
| 6203 | |
| 6204 | ntups = PQntuples(res); |
| 6205 | *numOprs = ntups; |
| 6206 | |
| 6207 | oprinfo = (OprInfo *) pg_malloc(ntups * sizeof(OprInfo)); |
| 6208 | |
| 6209 | i_tableoid = PQfnumber(res, "tableoid"); |
| 6210 | i_oid = PQfnumber(res, "oid"); |
| 6211 | i_oprname = PQfnumber(res, "oprname"); |
| 6212 | i_oprnamespace = PQfnumber(res, "oprnamespace"); |
| 6213 | i_rolname = PQfnumber(res, "rolname"); |
| 6214 | i_oprkind = PQfnumber(res, "oprkind"); |
| 6215 | i_oprcode = PQfnumber(res, "oprcode"); |
| 6216 | |
| 6217 | for (i = 0; i < ntups; i++) |
| 6218 | { |
| 6219 | oprinfo[i].dobj.objType = DO_OPERATOR; |
| 6220 | oprinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); |
| 6221 | oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); |
| 6222 | AssignDumpId(&oprinfo[i].dobj); |
| 6223 | oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname)); |
| 6224 | oprinfo[i].dobj.namespace = |
| 6225 | findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace))); |
| 6226 | oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); |
| 6227 | oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0]; |
| 6228 | oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode)); |
| 6229 | |
| 6230 | /* Decide whether we want to dump it */ |
no test coverage detected