1 /* File:			pgtypes.h
2  *
3  * Description:		See "pgtypes.c"
4  *
5  * Comments:		See "readme.txt" for copyright and license information.
6  *
7  */
8 
9 #ifndef __PGTYPES_H__
10 #define __PGTYPES_H__
11 
12 #include "psqlodbc.h"
13 
14 /* the type numbers are defined by the OID's of the types' rows */
15 /* in table pg_type */
16 
17 
18 #ifdef NOT_USED
19 #define PG_TYPE_LO				????	/* waiting for permanent type */
20 #endif
21 
22 #define	MS_ACCESS_SERIAL		"int identity"
23 #define PG_TYPE_BOOL			16
24 #define PG_TYPE_BYTEA			17
25 #define PG_TYPE_CHAR			18
26 #define PG_TYPE_NAME			19
27 #define PG_TYPE_INT8			20
28 #define PG_TYPE_INT2			21
29 #define PG_TYPE_INT2VECTOR		22
30 #define PG_TYPE_INT4			23
31 #define PG_TYPE_REGPROC			24
32 #define PG_TYPE_TEXT			25
33 #define PG_TYPE_OID				26
34 #define PG_TYPE_TID				27
35 #define PG_TYPE_XID				28
36 #define PG_TYPE_CID				29
37 #define PG_TYPE_OIDVECTOR		30
38 #define PG_TYPE_XML			142
39 #define PG_TYPE_XMLARRAY		143
40 #define PG_TYPE_CIDR			650
41 #define PG_TYPE_FLOAT4			700
42 #define PG_TYPE_FLOAT8			701
43 #define PG_TYPE_ABSTIME			702
44 #define PG_TYPE_UNKNOWN			705
45 #define PG_TYPE_MONEY			790
46 #define PG_TYPE_MACADDR			829
47 #define PG_TYPE_INET			869
48 #define PG_TYPE_TEXTARRAY		1009
49 #define PG_TYPE_BPCHARARRAY		1014
50 #define PG_TYPE_VARCHARARRAY		1015
51 #define PG_TYPE_BPCHAR			1042
52 #define PG_TYPE_VARCHAR			1043
53 #define PG_TYPE_DATE			1082
54 #define PG_TYPE_TIME			1083
55 #define PG_TYPE_TIMESTAMP_NO_TMZONE	1114		/* since 7.2 */
56 #define PG_TYPE_DATETIME		1184	/* timestamptz */
57 #define PG_TYPE_INTERVAL		1186
58 #define PG_TYPE_TIME_WITH_TMZONE	1266		/* since 7.1 */
59 #define PG_TYPE_TIMESTAMP		1296	/* deprecated since 7.0 */
60 #define PG_TYPE_BIT			1560
61 #define PG_TYPE_NUMERIC			1700
62 #define PG_TYPE_REFCURSOR		1790
63 #define PG_TYPE_RECORD			2249
64 #define PG_TYPE_ANY			2276
65 #define PG_TYPE_VOID			2278
66 #define PG_TYPE_UUID			2950
67 #define INTERNAL_ASIS_TYPE		(-9999)
68 
69 #define TYPE_MAY_BE_ARRAY(type) ((type) == PG_TYPE_XMLARRAY || ((type) >= 1000 && (type) <= 1041))
70 /* extern Int4 pgtypes_defined[]; */
71 extern SQLSMALLINT sqlTypes[];
72 
73 /*	Defines for pgtype_precision */
74 #define PG_ATP_UNSET				(-3)	/* atttypmod */
75 #define PG_ADT_UNSET				(-3)	/* adtsize_or_longestlen */
76 #define PG_UNKNOWNS_UNSET			0 /* UNKNOWNS_AS_MAX */
77 #define PG_WIDTH_OF_BOOLS_AS_CHAR		5
78 
79 /*
80  *	SQL_INTERVAL support is disabled because I found
81  *	some applications which are unhappy with it.
82  *
83 #define	PG_INTERVAL_AS_SQL_INTERVAL
84  */
85 
86 OID		pg_true_type(const ConnectionClass *, OID, OID);
87 OID		sqltype_to_pgtype(const ConnectionClass *conn, SQLSMALLINT fSqlType);
88 OID		sqltype_to_bind_pgtype(const ConnectionClass *conn, SQLSMALLINT fSqlType);
89 const char	*sqltype_to_pgcast(const ConnectionClass *conn, SQLSMALLINT fSqlType);
90 
91 SQLSMALLINT	pgtype_to_concise_type(const StatementClass *stmt, OID type, int col, int handle_unknown_size_as);
92 SQLSMALLINT	pgtype_to_sqldesctype(const StatementClass *stmt, OID type, int col, int handle_unknown_size_as);
93 SQLSMALLINT	pgtype_to_datetime_sub(const StatementClass *stmt, OID type, int col);
94 const char	*pgtype_to_name(const StatementClass *stmt, OID type, int col, BOOL auto_increment);
95 
96 SQLSMALLINT	pgtype_attr_to_concise_type(const ConnectionClass *conn, OID type, int typmod, int adtsize_or_longestlen,int handle_unknown_size_as);
97 SQLSMALLINT	pgtype_attr_to_sqldesctype(const ConnectionClass *conn, OID type, int typmod, int adtsize_or_longestlen, int handle_unknown_size_as);
98 SQLSMALLINT	pgtype_attr_to_datetime_sub(const ConnectionClass *conn, OID type, int typmod);
99 SQLSMALLINT	pgtype_attr_to_ctype(const ConnectionClass *conn, OID type, int typmod);
100 const char	*pgtype_attr_to_name(const ConnectionClass *conn, OID type, int typmod, BOOL auto_increment);
101 Int4		pgtype_attr_column_size(const ConnectionClass *conn, OID type, int atttypmod, int adtsize_or_longest, int handle_unknown_size_as);
102 Int4		pgtype_attr_buffer_length(const ConnectionClass *conn, OID type, int atttypmod, int adtsize_or_longestlen, int handle_unknown_size_as);
103 Int4		pgtype_attr_display_size(const ConnectionClass *conn, OID type, int atttypmod, int adtsize_or_longestlen, int handle_unknown_size_as);
104 Int2		pgtype_attr_decimal_digits(const ConnectionClass *conn, OID type, int atttypmod, int adtsize_or_longestlen, int handle_unknown_size_as);
105 Int4		pgtype_attr_transfer_octet_length(const ConnectionClass *conn, OID type, int atttypmod, int handle_unknown_size_as);
106 SQLSMALLINT	pgtype_attr_precision(const ConnectionClass *conn, OID type, int atttypmod, int adtsize_or_longest, int handle_unknown_size_as);
107 Int4		pgtype_attr_desclength(const ConnectionClass *conn, OID type, int atttypmod, int adtsize_or_longestlen, int handle_unknown_size_as);
108 Int2		pgtype_attr_scale(const ConnectionClass *conn, OID type, int atttypmod, int adtsize_or_longestlen, int handle_unknown_size_as);
109 
110 /*	These functions can use static numbers or result sets(col parameter) */
111 Int4		pgtype_column_size(const StatementClass *stmt, OID type, int col, int handle_unknown_size_as); /* corresponds to "precision" in ODBC 2.x */
112 SQLSMALLINT	pgtype_precision(const StatementClass *stmt, OID type, int col, int handle_unknown_size_as); /* "precsion in ODBC 3.x */
113 /* the following size/length are of Int4 due to PG restriction */
114 Int4		pgtype_display_size(const StatementClass *stmt, OID type, int col, int handle_unknown_size_as);
115 Int4		pgtype_buffer_length(const StatementClass *stmt, OID type, int col, int handle_unknown_size_as);
116 Int4		pgtype_desclength(const StatementClass *stmt, OID type, int col, int handle_unknown_size_as);
117 // Int4		pgtype_transfer_octet_length(const ConnectionClass *conn, OID type, int column_size);
118 
119 SQLSMALLINT	pgtype_decimal_digits(const StatementClass *stmt, OID type, int col); /* corresponds to "scale" in ODBC 2.x */
120 SQLSMALLINT	pgtype_min_decimal_digits(const ConnectionClass *conn, OID type); /* corresponds to "min_scale" in ODBC 2.x */
121 SQLSMALLINT	pgtype_max_decimal_digits(const ConnectionClass *conn, OID type); /* corresponds to "max_scale" in ODBC 2.x */
122 SQLSMALLINT	pgtype_scale(const StatementClass *stmt, OID type, int col); /* ODBC 3.x " */
123 Int2		pgtype_radix(const ConnectionClass *conn, OID type);
124 Int2		pgtype_nullable(const ConnectionClass *conn, OID type);
125 Int2		pgtype_auto_increment(const ConnectionClass *conn, OID type);
126 Int2		pgtype_case_sensitive(const ConnectionClass *conn, OID type);
127 Int2		pgtype_money(const ConnectionClass *conn, OID type);
128 Int2		pgtype_searchable(const ConnectionClass *conn, OID type);
129 Int2		pgtype_unsigned(const ConnectionClass *conn, OID type);
130 const char	*pgtype_literal_prefix(const ConnectionClass *conn, OID type);
131 const char	*pgtype_literal_suffix(const ConnectionClass *conn, OID type);
132 const char	*pgtype_create_params(const ConnectionClass *conn, OID type);
133 
134 SQLSMALLINT	sqltype_to_default_ctype(const ConnectionClass *stmt, SQLSMALLINT sqltype);
135 Int4		ctype_length(SQLSMALLINT ctype);
136 
137 SQLSMALLINT	ansi_to_wtype(const ConnectionClass *self, SQLSMALLINT ansitype);
138 
139 #define	USE_ZONE	FALSE
140 #endif
141