1 | /* src/interfaces/ecpg/ecpglib/typename.c */ |
---|---|
2 | |
3 | #define POSTGRES_ECPG_INTERNAL |
4 | #include "postgres_fe.h" |
5 | |
6 | #include "catalog/pg_type_d.h" |
7 | |
8 | #include "ecpgtype.h" |
9 | #include "ecpglib.h" |
10 | #include "ecpglib_extern.h" |
11 | #include "sqltypes.h" |
12 | #include "sql3types.h" |
13 | |
14 | /* |
15 | * This function is used to generate the correct type names. |
16 | */ |
17 | const char * |
18 | ecpg_type_name(enum ECPGttype typ) |
19 | { |
20 | switch (typ) |
21 | { |
22 | case ECPGt_char: |
23 | case ECPGt_string: |
24 | return "char"; |
25 | case ECPGt_unsigned_char: |
26 | return "unsigned char"; |
27 | case ECPGt_short: |
28 | return "short"; |
29 | case ECPGt_unsigned_short: |
30 | return "unsigned short"; |
31 | case ECPGt_int: |
32 | return "int"; |
33 | case ECPGt_unsigned_int: |
34 | return "unsigned int"; |
35 | case ECPGt_long: |
36 | return "long"; |
37 | case ECPGt_unsigned_long: |
38 | return "unsigned long"; |
39 | case ECPGt_long_long: |
40 | return "long long"; |
41 | case ECPGt_unsigned_long_long: |
42 | return "unsigned long long"; |
43 | case ECPGt_float: |
44 | return "float"; |
45 | case ECPGt_double: |
46 | return "double"; |
47 | case ECPGt_bool: |
48 | return "bool"; |
49 | case ECPGt_varchar: |
50 | return "varchar"; |
51 | case ECPGt_bytea: |
52 | return "bytea"; |
53 | case ECPGt_char_variable: |
54 | return "char"; |
55 | case ECPGt_decimal: |
56 | return "decimal"; |
57 | case ECPGt_numeric: |
58 | return "numeric"; |
59 | case ECPGt_date: |
60 | return "date"; |
61 | case ECPGt_timestamp: |
62 | return "timestamp"; |
63 | case ECPGt_interval: |
64 | return "interval"; |
65 | case ECPGt_const: |
66 | return "Const"; |
67 | default: |
68 | abort(); |
69 | } |
70 | return ""; /* keep MSC compiler happy */ |
71 | } |
72 | |
73 | int |
74 | ecpg_dynamic_type(Oid type) |
75 | { |
76 | switch (type) |
77 | { |
78 | case BOOLOID: |
79 | return SQL3_BOOLEAN; /* bool */ |
80 | case INT2OID: |
81 | return SQL3_SMALLINT; /* int2 */ |
82 | case INT4OID: |
83 | return SQL3_INTEGER; /* int4 */ |
84 | case TEXTOID: |
85 | return SQL3_CHARACTER; /* text */ |
86 | case FLOAT4OID: |
87 | return SQL3_REAL; /* float4 */ |
88 | case FLOAT8OID: |
89 | return SQL3_DOUBLE_PRECISION; /* float8 */ |
90 | case BPCHAROID: |
91 | return SQL3_CHARACTER; /* bpchar */ |
92 | case VARCHAROID: |
93 | return SQL3_CHARACTER_VARYING; /* varchar */ |
94 | case DATEOID: |
95 | return SQL3_DATE_TIME_TIMESTAMP; /* date */ |
96 | case TIMEOID: |
97 | return SQL3_DATE_TIME_TIMESTAMP; /* time */ |
98 | case TIMESTAMPOID: |
99 | return SQL3_DATE_TIME_TIMESTAMP; /* datetime */ |
100 | case NUMERICOID: |
101 | return SQL3_NUMERIC; /* numeric */ |
102 | default: |
103 | return 0; |
104 | } |
105 | } |
106 | |
107 | int |
108 | sqlda_dynamic_type(Oid type, enum COMPAT_MODE compat) |
109 | { |
110 | switch (type) |
111 | { |
112 | case CHAROID: |
113 | case VARCHAROID: |
114 | case BPCHAROID: |
115 | case TEXTOID: |
116 | return ECPGt_char; |
117 | case INT2OID: |
118 | return ECPGt_short; |
119 | case INT4OID: |
120 | return ECPGt_int; |
121 | case FLOAT8OID: |
122 | return ECPGt_double; |
123 | case FLOAT4OID: |
124 | return ECPGt_float; |
125 | case NUMERICOID: |
126 | return INFORMIX_MODE(compat) ? ECPGt_decimal : ECPGt_numeric; |
127 | case DATEOID: |
128 | return ECPGt_date; |
129 | case TIMESTAMPOID: |
130 | case TIMESTAMPTZOID: |
131 | return ECPGt_timestamp; |
132 | case INTERVALOID: |
133 | return ECPGt_interval; |
134 | case INT8OID: |
135 | #ifdef HAVE_LONG_LONG_INT_64 |
136 | return ECPGt_long_long; |
137 | #endif |
138 | #ifdef HAVE_LONG_INT_64 |
139 | return ECPGt_long; |
140 | #endif |
141 | /* Unhandled types always return a string */ |
142 | default: |
143 | return ECPGt_char; |
144 | } |
145 | } |
146 |