* getNamespaces: * read all namespaces in the system catalogs and return them in the * NamespaceInfo* structure * * numNamespaces is set to the number of namespaces read in */
| 5678 | * numNamespaces is set to the number of namespaces read in |
| 5679 | */ |
| 5680 | NamespaceInfo * |
| 5681 | getNamespaces(Archive *fout, int *numNamespaces) |
| 5682 | { |
| 5683 | DumpOptions *dopt = fout->dopt; |
| 5684 | PGresult *res; |
| 5685 | int ntups; |
| 5686 | int i; |
| 5687 | PQExpBuffer query; |
| 5688 | NamespaceInfo *nsinfo; |
| 5689 | int i_tableoid; |
| 5690 | int i_oid; |
| 5691 | int i_nspname; |
| 5692 | int i_rolname; |
| 5693 | int i_nspacl; |
| 5694 | int i_rnspacl; |
| 5695 | int i_initnspacl; |
| 5696 | int i_initrnspacl; |
| 5697 | |
| 5698 | query = createPQExpBuffer(); |
| 5699 | |
| 5700 | /* |
| 5701 | * we fetch all namespaces including system ones, so that every object we |
| 5702 | * read in can be linked to a containing namespace. |
| 5703 | */ |
| 5704 | if (fout->remoteVersion >= 90600) |
| 5705 | { |
| 5706 | PQExpBuffer acl_subquery = createPQExpBuffer(); |
| 5707 | PQExpBuffer racl_subquery = createPQExpBuffer(); |
| 5708 | PQExpBuffer init_acl_subquery = createPQExpBuffer(); |
| 5709 | PQExpBuffer init_racl_subquery = createPQExpBuffer(); |
| 5710 | |
| 5711 | buildACLQueries(acl_subquery, racl_subquery, init_acl_subquery, |
| 5712 | init_racl_subquery, "n.nspacl", "n.nspowner", "'n'", |
| 5713 | dopt->binary_upgrade); |
| 5714 | |
| 5715 | appendPQExpBuffer(query, "SELECT n.tableoid, n.oid, n.nspname, " |
| 5716 | "(%s nspowner) AS rolname, " |
| 5717 | "%s as nspacl, " |
| 5718 | "%s as rnspacl, " |
| 5719 | "%s as initnspacl, " |
| 5720 | "%s as initrnspacl " |
| 5721 | "FROM pg_namespace n " |
| 5722 | "LEFT JOIN pg_init_privs pip " |
| 5723 | "ON (n.oid = pip.objoid " |
| 5724 | "AND pip.classoid = 'pg_namespace'::regclass " |
| 5725 | "AND pip.objsubid = 0", |
| 5726 | username_subquery, |
| 5727 | acl_subquery->data, |
| 5728 | racl_subquery->data, |
| 5729 | init_acl_subquery->data, |
| 5730 | init_racl_subquery->data); |
| 5731 | |
| 5732 | appendPQExpBufferStr(query, ") "); |
| 5733 | |
| 5734 | destroyPQExpBuffer(acl_subquery); |
| 5735 | destroyPQExpBuffer(racl_subquery); |
| 5736 | destroyPQExpBuffer(init_acl_subquery); |
| 5737 | destroyPQExpBuffer(init_racl_subquery); |
no test coverage detected