1 /**
2 Declarations for interfacing with the ODBC library.
3 
4 Adapted with minimal changes from the work of David L. Davis
5 (refer to the $(HTTP
6 forum.dlang.org/post/cfk7ql$(DOLLAR)1p4n$(DOLLAR)1@digitaldaemon.com,
7 original announcement)).
8 
9 `odbc.sqlext.d` corresponds to the `sqlext.h` C header file.
10 
11 See_Also: $(LINK2 https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/odbc-api-reference,
12           ODBC API Reference on MSN Online)
13 */
14 module odbc.sqltypes;
15 
16 extern (Windows):
17 
18 // * API declaration data types *
19 //alias void *HANDLE;
20 
21 //alias ubyte   SQLCHAR;
22 alias SQLCHAR      = char;
23 alias SQLSCHAR     = byte;
24 alias SQLDATE      = ubyte;
25 alias SQLDECIMAL   = ubyte;
26 alias SQLDOUBLE    = double;
27 alias SQLFLOAT     = double;
28 alias SQLINTEGER   = int;
29 alias SQLUINTEGER  = ushort;
30 alias SQLNUMERIC   = ubyte;
31 alias SQLREAL      = float;
32 alias SQLTIME      = ubyte;
33 alias SQLTIMESTAMP = ubyte;
34 alias SQLVARCHAR   = ubyte;
35 alias SQLPOINTER   = void*;
36 alias SQLSMALLINT   = short;
37 alias SQLUSMALLINT = ushort;
38 
39 // * function return type *
40 alias SQLRETURN = SQLSMALLINT;
41 
42 // * generic data structures *
43 alias SQLHANDLE = void*;
44 alias SQLHENV   = SQLHANDLE;
45 alias SQLHDBC   = SQLHANDLE;
46 alias SQLHSTMT  = SQLHANDLE;
47 alias SQLHDESC  = SQLHANDLE;
48 
49 // * SQL portable types for C *
50 //alias ubyte  UCHAR;  // std.c.windows.windows has this alias
51 //alias char   UCHAR;
52 alias SCHAR   = byte;
53 //alias SCHAR  SQLSCHAR;
54 alias DWORD   = uint;
55 alias SDWORD  = int;
56 alias SWORD   = short;
57 alias UDWORD  = uint ;
58 alias UWORD   = ushort;
59 alias WORD    = short;
60 //alias UDWORD SQLUINTEGER;
61 alias SLONG   = long;
62 alias SSHORT  = short;
63 alias ULONG   = ulong;
64 alias USHORT  = ushort;
65 alias SDOUBLE = double;
66 alias LDOUBLE = double;
67 alias SFLOAT  = float;
68 alias PTR     = void*;
69 alias HENV    = void*;
70 alias HDBC    = void*;
71 alias HSTMT   = void*;
72 alias RETCODE = short;
73 alias HWND    = SQLPOINTER;
74 alias SQLHWND = HWND;
75 
76 // * transfer types for DATE, TIME, TIMESTAMP *
77 struct DATE_STRUCT
78 {
79     SQLSMALLINT    year;
80     SQLUSMALLINT   month;
81     SQLUSMALLINT   day;
82 }
83 
84 alias SQL_DATE_STRUCT = DATE_STRUCT;
85 
86 struct TIME_STRUCT
87 {
88     SQLUSMALLINT hour;
89     SQLUSMALLINT minute;
90     SQLUSMALLINT second;
91 }
92 
93 alias SQL_TIME_STRUCT = TIME_STRUCT;
94 
95 struct TIMESTAMP_STRUCT
96 {
97     SQLSMALLINT    year;
98     SQLUSMALLINT   month;
99     SQLUSMALLINT   day;
100     SQLUSMALLINT   hour;
101     SQLUSMALLINT   minute;
102     SQLUSMALLINT   second;
103     SQLUINTEGER    fraction;
104 }
105 
106 alias SQL_TIMESTAMP_STRUCT = TIMESTAMP_STRUCT;
107 
108 /+
109  ' enumerations for DATETIME_INTERVAL_SUBCODE values for interval data types
110  ' these values are from SQL-92
111  +/
112 enum SQLINTERVAL
113 {
114     SQL_IS_YEAR             = 1,
115     SQL_IS_MONTH            = 2,
116     SQL_IS_DAY              = 3,
117     SQL_IS_HOUR             = 4,
118     SQL_IS_MINUTE           = 5,
119     SQL_IS_SECOND           = 6,
120     SQL_IS_YEAR_TO_MONTH    = 7,
121     SQL_IS_DAY_TO_HOUR      = 8,
122     SQL_IS_DAY_TO_MINUTE    = 9,
123     SQL_IS_DAY_TO_SECOND    = 10,
124     SQL_IS_HOUR_TO_MINUTE   = 11,
125     SQL_IS_HOUR_TO_SECOND   = 12,
126     SQL_IS_MINUTE_TO_SECOND = 13
127 }
128 
129 struct SQL_YEAR_MONTH_STRUCT
130 {
131     SQLUINTEGER year;
132     SQLUINTEGER month;
133 }
134 
135 struct SQL_DAY_SECOND_STRUCT
136 {
137     SQLUINTEGER day;
138     SQLUINTEGER hour;
139     SQLUINTEGER minute;
140     SQLUINTEGER second;
141     SQLUINTEGER fraction;
142 }
143 
144 struct SQL_INTERVAL_STRUCT
145 {
146     SQLINTERVAL interval_type;
147     SQLSMALLINT interval_sign;
148 
149     union  intval {
150         SQL_YEAR_MONTH_STRUCT year_month;
151         SQL_DAY_SECOND_STRUCT day_second;
152     }
153 }
154 
155 // * internal representation of numeric data type *
156 const int SQL_MAX_NUMERIC_LEN = 16;
157 struct SQL_NUMERIC_STRUCT
158 {
159     SQLCHAR  precision;
160     SQLSCHAR scale;
161     SQLCHAR  sign;    /* 1 if positive, 0 if negative */
162     SQLCHAR[ SQL_MAX_NUMERIC_LEN ]  val;
163 }
164 
165 /* size is 16 */
166 struct SQLGUID
167 {
168     DWORD Data1;
169     WORD Data2;
170     WORD Data3;
171     ubyte[ 8 ] Data4;
172 }
173 
174 alias GUID     = SQLGUID;
175 alias BOOKMARK = uint;
176 alias SQLWCHAR = ushort;
177 
178 version( UNICODE )
179 {
180 alias SQLTCHAR = SQLWCHAR;
181 }
182 else
183 {
184 alias SQLTCHAR = SQLCHAR;
185 } // end version( UNICODE )