PostgreSQL Source Code  git master
typename.c
Go to the documentation of this file.
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 "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 *
19 {
20  switch (typ)
21  {
22  case ECPGt_char:
23  case ECPGt_string:
24  return "char";
26  return "unsigned char";
27  case ECPGt_short:
28  return "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";
38  return "unsigned long";
39  case ECPGt_long_long:
40  return "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";
52  return "char";
53  case ECPGt_decimal:
54  return "decimal";
55  case ECPGt_numeric:
56  return "numeric";
57  case ECPGt_date:
58  return "date";
59  case ECPGt_timestamp:
60  return "timestamp";
61  case ECPGt_interval:
62  return "interval";
63  case ECPGt_const:
64  return "Const";
65  default:
66  abort();
67  }
68  return ""; /* keep MSC compiler happy */
69 }
70 
71 int
73 {
74  switch (type)
75  {
76  case BOOLOID:
77  return SQL3_BOOLEAN; /* bool */
78  case INT2OID:
79  return SQL3_SMALLINT; /* int2 */
80  case INT4OID:
81  return SQL3_INTEGER; /* int4 */
82  case TEXTOID:
83  return SQL3_CHARACTER; /* text */
84  case FLOAT4OID:
85  return SQL3_REAL; /* float4 */
86  case FLOAT8OID:
87  return SQL3_DOUBLE_PRECISION; /* float8 */
88  case BPCHAROID:
89  return SQL3_CHARACTER; /* bpchar */
90  case VARCHAROID:
91  return SQL3_CHARACTER_VARYING; /* varchar */
92  case DATEOID:
93  return SQL3_DATE_TIME_TIMESTAMP; /* date */
94  case TIMEOID:
95  return SQL3_DATE_TIME_TIMESTAMP; /* time */
96  case TIMESTAMPOID:
97  return SQL3_DATE_TIME_TIMESTAMP; /* datetime */
98  case NUMERICOID:
99  return SQL3_NUMERIC; /* numeric */
100  default:
101  return 0;
102  }
103 }
104 
105 int
107 {
108  switch (type)
109  {
110  case CHAROID:
111  case VARCHAROID:
112  case BPCHAROID:
113  case TEXTOID:
114  return ECPGt_char;
115  case INT2OID:
116  return ECPGt_short;
117  case INT4OID:
118  return ECPGt_int;
119  case FLOAT8OID:
120  return ECPGt_double;
121  case FLOAT4OID:
122  return ECPGt_float;
123  case NUMERICOID:
124  return INFORMIX_MODE(compat) ? ECPGt_decimal : ECPGt_numeric;
125  case DATEOID:
126  return ECPGt_date;
127  case TIMESTAMPOID:
128  case TIMESTAMPTZOID:
129  return ECPGt_timestamp;
130  case INTERVALOID:
131  return ECPGt_interval;
132  case INT8OID:
133 #ifdef HAVE_LONG_LONG_INT_64
134  return ECPGt_long_long;
135 #endif
136 #ifdef HAVE_LONG_INT_64
137  return ECPGt_long;
138 #endif
139  /* Unhandled types always return a string */
140  default:
141  return ECPGt_char;
142  }
143 }
#define INFORMIX_MODE(X)
Definition: extern.h:23
int ecpg_dynamic_type(Oid type)
Definition: typename.c:72
unsigned int Oid
Definition: postgres_ext.h:31
int sqlda_dynamic_type(Oid type, enum COMPAT_MODE compat)
Definition: typename.c:106
enum COMPAT_MODE compat
Definition: ecpg.c:25
COMPAT_MODE
Definition: extern.h:16
const char * ecpg_type_name(enum ECPGttype typ)
Definition: typename.c:18
ECPGttype
Definition: ecpgtype.h:41