aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/typename.c
blob: 1fb9860371bf89ad4eb309c064f518e772fc31f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* src/interfaces/ecpg/ecpglib/typename.c */

#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"

#include "catalog/pg_type_d.h"
#include "ecpglib.h"
#include "ecpglib_extern.h"
#include "ecpgtype.h"
#include "sql3types.h"
#include "sqltypes.h"

/*
 * This function is used to generate the correct type names.
 */
const char *
ecpg_type_name(enum ECPGttype typ)
{
	switch (typ)
	{
		case ECPGt_char:
		case ECPGt_string:
			return "char";
		case ECPGt_unsigned_char:
			return "unsigned char";
		case ECPGt_short:
			return "short";
		case ECPGt_unsigned_short:
			return "unsigned short";
		case ECPGt_int:
			return "int";
		case ECPGt_unsigned_int:
			return "unsigned int";
		case ECPGt_long:
			return "long";
		case ECPGt_unsigned_long:
			return "unsigned long";
		case ECPGt_long_long:
			return "long long";
		case ECPGt_unsigned_long_long:
			return "unsigned long long";
		case ECPGt_float:
			return "float";
		case ECPGt_double:
			return "double";
		case ECPGt_bool:
			return "bool";
		case ECPGt_varchar:
			return "varchar";
		case ECPGt_bytea:
			return "bytea";
		case ECPGt_char_variable:
			return "char";
		case ECPGt_decimal:
			return "decimal";
		case ECPGt_numeric:
			return "numeric";
		case ECPGt_date:
			return "date";
		case ECPGt_timestamp:
			return "timestamp";
		case ECPGt_interval:
			return "interval";
		case ECPGt_const:
			return "Const";
		default:
			abort();
	}
	return "";					/* keep MSC compiler happy */
}

int
ecpg_dynamic_type(Oid type)
{
	switch (type)
	{
		case BOOLOID:
			return SQL3_BOOLEAN;	/* bool */
		case INT2OID:
			return SQL3_SMALLINT;	/* int2 */
		case INT4OID:
			return SQL3_INTEGER;	/* int4 */
		case TEXTOID:
			return SQL3_CHARACTER;	/* text */
		case FLOAT4OID:
			return SQL3_REAL;	/* float4 */
		case FLOAT8OID:
			return SQL3_DOUBLE_PRECISION;	/* float8 */
		case BPCHAROID:
			return SQL3_CHARACTER;	/* bpchar */
		case VARCHAROID:
			return SQL3_CHARACTER_VARYING;	/* varchar */
		case DATEOID:
			return SQL3_DATE_TIME_TIMESTAMP;	/* date */
		case TIMEOID:
			return SQL3_DATE_TIME_TIMESTAMP;	/* time */
		case TIMESTAMPOID:
			return SQL3_DATE_TIME_TIMESTAMP;	/* datetime */
		case NUMERICOID:
			return SQL3_NUMERIC;	/* numeric */
		default:
			return 0;
	}
}

int
sqlda_dynamic_type(Oid type, enum COMPAT_MODE compat)
{
	switch (type)
	{
		case CHAROID:
		case VARCHAROID:
		case BPCHAROID:
		case TEXTOID:
			return ECPGt_char;
		case INT2OID:
			return ECPGt_short;
		case INT4OID:
			return ECPGt_int;
		case FLOAT8OID:
			return ECPGt_double;
		case FLOAT4OID:
			return ECPGt_float;
		case NUMERICOID:
			return INFORMIX_MODE(compat) ? ECPGt_decimal : ECPGt_numeric;
		case DATEOID:
			return ECPGt_date;
		case TIMESTAMPOID:
		case TIMESTAMPTZOID:
			return ECPGt_timestamp;
		case INTERVALOID:
			return ECPGt_interval;
		case INT8OID:
#if SIZEOF_LONG == 8
			return ECPGt_long;
#elif SIZEOF_LONG_LONG == 8
			return ECPGt_long_long;
#else
#error "cannot find integer type of the same size as INT8OID"
#endif
			/* Unhandled types always return a string */
		default:
			return ECPGt_char;
	}
}