|
34 | 34 | #include"nodes/plannodes.h"
|
35 | 35 | #include"nodes/readfuncs.h"
|
36 | 36 |
|
| 37 | +/* Portable-related dependencies */ |
| 38 | +#include"utils/lsyscache.h" |
| 39 | +#include"catalog/namespace.h" |
| 40 | +#include"utils/syscache.h" |
| 41 | + |
| 42 | +staticOidread_oid_field(char**token,int*length); |
| 43 | + |
| 44 | +staticboolportable_input= false; |
| 45 | +void |
| 46 | +set_portable_input(boolvalue) |
| 47 | +{ |
| 48 | +portable_input=value; |
| 49 | +} |
37 | 50 |
|
38 | 51 | /*
|
39 | 52 | * Macros to simplify reading of different kinds of fields. Use these
|
|
79 | 92 | /* Read an OID field (don't hard-wire assumption that OID is same as uint) */
|
80 | 93 | #defineREAD_OID_FIELD(fldname) \
|
81 | 94 | token = pg_strtok(&length);/* skip :fldname */ \
|
82 |
| -token=pg_strtok(&length);/* get field value */ \ |
83 |
| -local_node->fldname=atooid(token) |
| 95 | +local_node->fldname=read_oid_field(&token,&length); |
84 | 96 |
|
85 | 97 | /* Read a char field (ie, one ascii character) */
|
86 | 98 | #defineREAD_CHAR_FIELD(fldname) \
|
@@ -2719,3 +2731,80 @@ readBoolCols(int numCols)
|
2719 | 2731 |
|
2720 | 2732 | returnbool_vals;
|
2721 | 2733 | }
|
| 2734 | + |
| 2735 | +#defineatooid(x) ((Oid) strtoul((x), NULL, 10)) |
| 2736 | + |
| 2737 | +staticOid |
| 2738 | +read_oid_field(char**token,int*length) |
| 2739 | +{ |
| 2740 | +Oidoid_type, |
| 2741 | +oid; |
| 2742 | + |
| 2743 | +if (!portable_input) |
| 2744 | +{ |
| 2745 | +*token=pg_strtok(length); |
| 2746 | +returnatooid(*token); |
| 2747 | +} |
| 2748 | + |
| 2749 | +*token=pg_strtok(length); |
| 2750 | +Assert((*token)[0]='('); |
| 2751 | +*token=pg_strtok(length); |
| 2752 | +oid_type=atooid(*token); |
| 2753 | + |
| 2754 | +if (!OidIsValid(oid_type)) |
| 2755 | +{ |
| 2756 | +Oidoid; |
| 2757 | +*token=pg_strtok(length); |
| 2758 | +oid=atooid(*token); |
| 2759 | +*token=pg_strtok(length); |
| 2760 | +Assert((*token)[0]=')'); |
| 2761 | +returnoid; |
| 2762 | +} |
| 2763 | + |
| 2764 | +switch (oid_type) |
| 2765 | +{ |
| 2766 | +caseRELOID: |
| 2767 | +{ |
| 2768 | +char*relname, |
| 2769 | +*nspname; |
| 2770 | +Oidrel_nsp_oid; |
| 2771 | + |
| 2772 | +*token=pg_strtok(length);/* Switch to namespace name */ |
| 2773 | +nspname=nullable_string(*token,*length); |
| 2774 | +rel_nsp_oid=LookupNamespaceNoError(nspname); |
| 2775 | +*token=pg_strtok(length);/* Switch to relname */ |
| 2776 | +relname=nullable_string(*token,*length); |
| 2777 | +oid=get_relname_relid(relname,rel_nsp_oid); |
| 2778 | +elog(INFO,"reloid=%d",oid); |
| 2779 | +break; |
| 2780 | +} |
| 2781 | +caseTYPEOID: |
| 2782 | +{ |
| 2783 | +char*nspname;/* namespace name */ |
| 2784 | +char*typname;/* data type name */ |
| 2785 | + |
| 2786 | +*token=pg_strtok(length);/* get nspname */ |
| 2787 | +nspname=nullable_string(*token,*length); |
| 2788 | +*token=pg_strtok(length);/* get typname */ |
| 2789 | +typname=nullable_string(*token,*length); |
| 2790 | +if (typname) |
| 2791 | +{ |
| 2792 | +oid=get_typname_typid(typname,LookupNamespaceNoError((nspname))); |
| 2793 | +if (!OidIsValid((oid))) |
| 2794 | +elog(WARNING,"could not find OID for type %s.%s", |
| 2795 | +nspname,typname); |
| 2796 | +} |
| 2797 | +else |
| 2798 | +oid=InvalidOid; |
| 2799 | +elog(INFO,"typeoid=%d",oid); |
| 2800 | +} |
| 2801 | +break; |
| 2802 | + |
| 2803 | +default: |
| 2804 | +Assert(0); |
| 2805 | +break; |
| 2806 | +} |
| 2807 | +*token=pg_strtok(length); |
| 2808 | +Assert((*token)[0]=')'); |
| 2809 | +returnoid; |
| 2810 | +} |