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