* dumpDomain * writes out to fout the queries to recreate a user-defined domain */
| 12438 | * writes out to fout the queries to recreate a user-defined domain |
| 12439 | */ |
| 12440 | static void |
| 12441 | dumpDomain(Archive *fout, const TypeInfo *tyinfo) |
| 12442 | { |
| 12443 | DumpOptions *dopt = fout->dopt; |
| 12444 | PQExpBuffer q = createPQExpBuffer(); |
| 12445 | PQExpBuffer delq = createPQExpBuffer(); |
| 12446 | PQExpBuffer query = createPQExpBuffer(); |
| 12447 | PGresult *res; |
| 12448 | int i; |
| 12449 | char *qtypname; |
| 12450 | char *qualtypname; |
| 12451 | char *typnotnull; |
| 12452 | char *typdefn; |
| 12453 | char *typdefault; |
| 12454 | Oid typcollation; |
| 12455 | bool typdefault_is_literal = false; |
| 12456 | |
| 12457 | /* Fetch domain specific details */ |
| 12458 | if (fout->remoteVersion >= 90100) |
| 12459 | { |
| 12460 | /* typcollation is new in 9.1 */ |
| 12461 | appendPQExpBuffer(query, "SELECT t.typnotnull, " |
| 12462 | "pg_catalog.format_type(t.typbasetype, t.typtypmod) AS typdefn, " |
| 12463 | "pg_catalog.pg_get_expr(t.typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, " |
| 12464 | "t.typdefault, " |
| 12465 | "CASE WHEN t.typcollation <> u.typcollation " |
| 12466 | "THEN t.typcollation ELSE 0 END AS typcollation " |
| 12467 | "FROM pg_catalog.pg_type t " |
| 12468 | "LEFT JOIN pg_catalog.pg_type u ON (t.typbasetype = u.oid) " |
| 12469 | "WHERE t.oid = '%u'::pg_catalog.oid", |
| 12470 | tyinfo->dobj.catId.oid); |
| 12471 | } |
| 12472 | else |
| 12473 | { |
| 12474 | appendPQExpBuffer(query, "SELECT typnotnull, " |
| 12475 | "pg_catalog.format_type(typbasetype, typtypmod) AS typdefn, " |
| 12476 | "pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, " |
| 12477 | "typdefault, 0 AS typcollation " |
| 12478 | "FROM pg_catalog.pg_type " |
| 12479 | "WHERE oid = '%u'::pg_catalog.oid", |
| 12480 | tyinfo->dobj.catId.oid); |
| 12481 | } |
| 12482 | |
| 12483 | res = ExecuteSqlQueryForSingleRow(fout, query->data); |
| 12484 | |
| 12485 | typnotnull = PQgetvalue(res, 0, PQfnumber(res, "typnotnull")); |
| 12486 | typdefn = PQgetvalue(res, 0, PQfnumber(res, "typdefn")); |
| 12487 | if (!PQgetisnull(res, 0, PQfnumber(res, "typdefaultbin"))) |
| 12488 | typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefaultbin")); |
| 12489 | else if (!PQgetisnull(res, 0, PQfnumber(res, "typdefault"))) |
| 12490 | { |
| 12491 | typdefault = PQgetvalue(res, 0, PQfnumber(res, "typdefault")); |
| 12492 | typdefault_is_literal = true; /* it needs quotes */ |
| 12493 | } |
| 12494 | else |
| 12495 | typdefault = NULL; |
| 12496 | typcollation = atooid(PQgetvalue(res, 0, PQfnumber(res, "typcollation"))); |
| 12497 |
no test coverage detected