Line data Source code
1 : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 : * Copyright (C) 2008 Frediano Ziglio
3 : *
4 : * This library is free software; you can redistribute it and/or
5 : * modify it under the terms of the GNU Library General Public
6 : * License as published by the Free Software Foundation; either
7 : * version 2 of the License, or (at your option) any later version.
8 : *
9 : * This library is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : * Library General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU Library General Public
15 : * License along with this library; if not, write to the
16 : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 : * Boston, MA 02111-1307, USA.
18 : */
19 :
20 : #ifndef _odbcss_h_
21 : #define _odbcss_h_
22 :
23 : #ifdef TDSODBC_BCP
24 : #include <sql.h>
25 : #endif
26 :
27 : #ifdef __cplusplus
28 : extern "C" {
29 : #endif
30 :
31 : #define SQL_DIAG_SS_MSGSTATE (-1150)
32 : #define SQL_DIAG_SS_LINE (-1154)
33 :
34 : #define SQL_SOPT_SS_QUERYNOTIFICATION_TIMEOUT 1233
35 : #define SQL_SOPT_SS_QUERYNOTIFICATION_MSGTEXT 1234
36 : #define SQL_SOPT_SS_QUERYNOTIFICATION_OPTIONS 1235
37 : #define SQL_SOPT_SS_PARAM_FOCUS 1236
38 :
39 : #ifndef SQL_SS_LENGTH_UNLIMITED
40 : #define SQL_SS_LENGTH_UNLIMITED 0
41 : #endif
42 :
43 : #ifndef SQL_COPT_SS_BASE
44 : #define SQL_COPT_SS_BASE 1200
45 : #endif
46 :
47 : #ifndef SQL_COPT_SS_MARS_ENABLED
48 : #define SQL_COPT_SS_MARS_ENABLED (SQL_COPT_SS_BASE+24)
49 : #endif
50 :
51 : #ifndef SQL_COPT_SS_OLDPWD
52 : #define SQL_COPT_SS_OLDPWD (SQL_COPT_SS_BASE+26)
53 : #endif
54 :
55 : #define SQL_INFO_FREETDS_TDS_VERSION 1300
56 : #define SQL_INFO_FREETDS_SOCKET 1301
57 :
58 : #ifndef SQL_MARS_ENABLED_NO
59 : #define SQL_MARS_ENABLED_NO 0
60 : #endif
61 :
62 : #ifndef SQL_MARS_ENABLED_YES
63 : #define SQL_MARS_ENABLED_YES 1
64 : #endif
65 :
66 : #ifndef SQL_SS_VARIANT
67 : #define SQL_SS_VARIANT (-150)
68 : #endif
69 :
70 : #ifndef SQL_SS_UDT
71 : #define SQL_SS_UDT (-151)
72 : #endif
73 :
74 : #ifndef SQL_SS_XML
75 : #define SQL_SS_XML (-152)
76 : #endif
77 :
78 : #ifndef SQL_SS_TABLE
79 : #define SQL_SS_TABLE (-153)
80 : #endif
81 :
82 : #ifndef SQL_SS_TIME2
83 : #define SQL_SS_TIME2 (-154)
84 : #endif
85 :
86 : #ifndef SQL_SS_TIMESTAMPOFFSET
87 : #define SQL_SS_TIMESTAMPOFFSET (-155)
88 : #endif
89 :
90 : /*
91 : * these types are used from conversion from client to server
92 : */
93 : #ifndef SQL_C_SS_TIME2
94 : #define SQL_C_SS_TIME2 (0x4000)
95 : #endif
96 :
97 : #ifndef SQL_C_SS_TIMESTAMPOFFSET
98 : #define SQL_C_SS_TIMESTAMPOFFSET (0x4001)
99 : #endif
100 :
101 : #ifndef SQL_CA_SS_BASE
102 : #define SQL_CA_SS_BASE 1200
103 : #endif
104 :
105 : #ifndef SQL_CA_SS_UDT_CATALOG_NAME
106 : #define SQL_CA_SS_UDT_CATALOG_NAME (SQL_CA_SS_BASE+18)
107 : #endif
108 :
109 : #ifndef SQL_CA_SS_UDT_SCHEMA_NAME
110 : #define SQL_CA_SS_UDT_SCHEMA_NAME (SQL_CA_SS_BASE+19)
111 : #endif
112 :
113 : #ifndef SQL_CA_SS_UDT_TYPE_NAME
114 : #define SQL_CA_SS_UDT_TYPE_NAME (SQL_CA_SS_BASE+20)
115 : #endif
116 :
117 : #ifndef SQL_CA_SS_UDT_ASSEMBLY_TYPE_NAME
118 : #define SQL_CA_SS_UDT_ASSEMBLY_TYPE_NAME (SQL_CA_SS_BASE+21)
119 : #endif
120 :
121 : #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_CATALOG_NAME
122 : #define SQL_CA_SS_XML_SCHEMACOLLECTION_CATALOG_NAME (SQL_CA_SS_BASE+22)
123 : #endif
124 :
125 : #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_SCHEMA_NAME
126 : #define SQL_CA_SS_XML_SCHEMACOLLECTION_SCHEMA_NAME (SQL_CA_SS_BASE+23)
127 : #endif
128 :
129 : #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_NAME
130 : #define SQL_CA_SS_XML_SCHEMACOLLECTION_NAME (SQL_CA_SS_BASE+24)
131 : #endif
132 :
133 : typedef struct tagSS_TIME2_STRUCT {
134 : SQLUSMALLINT hour;
135 : SQLUSMALLINT minute;
136 : SQLUSMALLINT second;
137 : SQLUINTEGER fraction;
138 : } SQL_SS_TIME2_STRUCT;
139 :
140 : typedef struct tagSS_TIMESTAMPOFFSET_STRUCT {
141 : SQLSMALLINT year;
142 : SQLUSMALLINT month;
143 : SQLUSMALLINT day;
144 : SQLUSMALLINT hour;
145 : SQLUSMALLINT minute;
146 : SQLUSMALLINT second;
147 : SQLUINTEGER fraction;
148 : SQLSMALLINT timezone_hour;
149 : SQLSMALLINT timezone_minute;
150 : } SQL_SS_TIMESTAMPOFFSET_STRUCT;
151 :
152 :
153 : #ifdef TDSODBC_BCP
154 :
155 : #ifndef SUCCEED
156 : #define SUCCEED 1
157 : #endif
158 : #ifndef FAIL
159 : #define FAIL 0
160 : #endif
161 :
162 : #ifndef BCPKEEPIDENTITY
163 : #define BCPKEEPIDENTITY 8
164 : #endif
165 : #ifndef BCPHINTS
166 : #define BCPHINTS 6
167 : #endif
168 :
169 : #define BCP_DIRECTION_IN 1
170 :
171 : #define SQL_COPT_SS_BCP (SQL_COPT_SS_BASE+19)
172 : #define SQL_BCP_OFF 0
173 : #define SQL_BCP_ON 1
174 :
175 : #define SQL_COPT_TDSODBC_IMPL_BASE 1500
176 : #define SQL_COPT_TDSODBC_IMPL_BCP_INITA (SQL_COPT_TDSODBC_IMPL_BASE)
177 : #define SQL_COPT_TDSODBC_IMPL_BCP_CONTROL (SQL_COPT_TDSODBC_IMPL_BASE+1)
178 : #define SQL_COPT_TDSODBC_IMPL_BCP_COLPTR (SQL_COPT_TDSODBC_IMPL_BASE+2)
179 : #define SQL_COPT_TDSODBC_IMPL_BCP_SENDROW (SQL_COPT_TDSODBC_IMPL_BASE+3)
180 : #define SQL_COPT_TDSODBC_IMPL_BCP_BATCH (SQL_COPT_TDSODBC_IMPL_BASE+4)
181 : #define SQL_COPT_TDSODBC_IMPL_BCP_DONE (SQL_COPT_TDSODBC_IMPL_BASE+5)
182 : #define SQL_COPT_TDSODBC_IMPL_BCP_BIND (SQL_COPT_TDSODBC_IMPL_BASE+6)
183 : #define SQL_COPT_TDSODBC_IMPL_BCP_INITW (SQL_COPT_TDSODBC_IMPL_BASE+7)
184 :
185 : #define SQL_VARLEN_DATA -10
186 :
187 : /* copied from sybdb.h which was copied from tds.h */
188 : /* TODO find a much better way... */
189 : enum
190 : {
191 : BCP_TYPE_SQLCHAR = 47, /* 0x2F */
192 : #define BCP_TYPE_SQLCHAR BCP_TYPE_SQLCHAR
193 : BCP_TYPE_SQLVARCHAR = 39, /* 0x27 */
194 : #define BCP_TYPE_SQLVARCHAR BCP_TYPE_SQLVARCHAR
195 : BCP_TYPE_SQLINTN = 38, /* 0x26 */
196 : #define BCP_TYPE_SQLINTN BCP_TYPE_SQLINTN
197 : BCP_TYPE_SQLINT1 = 48, /* 0x30 */
198 : #define BCP_TYPE_SQLINT1 BCP_TYPE_SQLINT1
199 : BCP_TYPE_SQLINT2 = 52, /* 0x34 */
200 : #define BCP_TYPE_SQLINT2 BCP_TYPE_SQLINT2
201 : BCP_TYPE_SQLINT4 = 56, /* 0x38 */
202 : #define BCP_TYPE_SQLINT4 BCP_TYPE_SQLINT4
203 : BCP_TYPE_SQLINT8 = 127, /* 0x7F */
204 : #define BCP_TYPE_SQLINT8 BCP_TYPE_SQLINT8
205 : BCP_TYPE_SQLFLT8 = 62, /* 0x3E */
206 : #define BCP_TYPE_SQLFLT8 BCP_TYPE_SQLFLT8
207 : BCP_TYPE_SQLDATETIME = 61, /* 0x3D */
208 : #define BCP_TYPE_SQLDATETIME BCP_TYPE_SQLDATETIME
209 : BCP_TYPE_SQLBIT = 50, /* 0x32 */
210 : #define BCP_TYPE_SQLBIT BCP_TYPE_SQLBIT
211 : BCP_TYPE_SQLBITN = 104, /* 0x68 */
212 : #define BCP_TYPE_SQLBITN BCP_TYPE_SQLBITN
213 : BCP_TYPE_SQLTEXT = 35, /* 0x23 */
214 : #define BCP_TYPE_SQLTEXT BCP_TYPE_SQLTEXT
215 : BCP_TYPE_SQLNTEXT = 99, /* 0x63 */
216 : #define BCP_TYPE_SQLNTEXT BCP_TYPE_SQLNTEXT
217 : BCP_TYPE_SQLIMAGE = 34, /* 0x22 */
218 : #define BCP_TYPE_SQLIMAGE BCP_TYPE_SQLIMAGE
219 : BCP_TYPE_SQLMONEY4 = 122, /* 0x7A */
220 : #define BCP_TYPE_SQLMONEY4 BCP_TYPE_SQLMONEY4
221 : BCP_TYPE_SQLMONEY = 60, /* 0x3C */
222 : #define BCP_TYPE_SQLMONEY BCP_TYPE_SQLMONEY
223 : BCP_TYPE_SQLDATETIME4 = 58, /* 0x3A */
224 : #define BCP_TYPE_SQLDATETIME4 BCP_TYPE_SQLDATETIME4
225 : BCP_TYPE_SQLREAL = 59, /* 0x3B */
226 : BCP_TYPE_SQLFLT4 = 59, /* 0x3B */
227 : #define BCP_TYPE_SQLREAL BCP_TYPE_SQLREAL
228 : #define BCP_TYPE_SQLFLT4 BCP_TYPE_SQLFLT4
229 : BCP_TYPE_SQLBINARY = 45, /* 0x2D */
230 : #define BCP_TYPE_SQLBINARY BCP_TYPE_SQLBINARY
231 : BCP_TYPE_SQLVOID = 31, /* 0x1F */
232 : #define BCP_TYPE_SQLVOID BCP_TYPE_SQLVOID
233 : BCP_TYPE_SQLVARBINARY = 37, /* 0x25 */
234 : #define BCP_TYPE_SQLVARBINARY BCP_TYPE_SQLVARBINARY
235 : BCP_TYPE_SQLNUMERIC = 108, /* 0x6C */
236 : #define BCP_TYPE_SQLNUMERIC BCP_TYPE_SQLNUMERIC
237 : BCP_TYPE_SQLDECIMAL = 106, /* 0x6A */
238 : #define BCP_TYPE_SQLDECIMAL BCP_TYPE_SQLDECIMAL
239 : BCP_TYPE_SQLFLTN = 109, /* 0x6D */
240 : #define BCP_TYPE_SQLFLTN BCP_TYPE_SQLFLTN
241 : BCP_TYPE_SQLMONEYN = 110, /* 0x6E */
242 : #define BCP_TYPE_SQLMONEYN BCP_TYPE_SQLMONEYN
243 : BCP_TYPE_SQLDATETIMN = 111, /* 0x6F */
244 : #define BCP_TYPE_SQLDATETIMN BCP_TYPE_SQLDATETIMN
245 : BCP_TYPE_SQLNVARCHAR = 103, /* 0x67 */
246 : #define BCP_TYPE_SQLNVARCHAR BCP_TYPE_SQLNVARCHAR
247 : BCP_TYPE_SQLUNIQUEID = 36, /* 0x24 */
248 : #define BCP_TYPE_SQLUNIQUEID BCP_TYPE_SQLUNIQUEID
249 : BCP_TYPE_SQLDATETIME2 = 42, /* 0x2a */
250 : #define BCP_TYPE_SQLDATETIME2 BCP_TYPE_SQLDATETIME2
251 : };
252 :
253 : typedef struct
254 : {
255 : int dtdays;
256 : int dttime;
257 : } DBDATETIME;
258 :
259 : #ifdef _MSC_VER
260 : #define TDSODBC_INLINE __inline
261 : #else
262 : #define TDSODBC_INLINE __inline__
263 : #endif
264 :
265 : struct tdsodbc_impl_bcp_init_params
266 : {
267 : const void *tblname;
268 : const void *hfile;
269 : const void *errfile;
270 : int direction;
271 : };
272 :
273 : static TDSODBC_INLINE RETCODE SQL_API
274 : bcp_initA(HDBC hdbc, const char *tblname, const char *hfile, const char *errfile, int direction)
275 : {
276 9 : struct tdsodbc_impl_bcp_init_params params = {tblname, hfile, errfile, direction};
277 9 : return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_INITA, ¶ms, SQL_IS_POINTER)) ? SUCCEED : FAIL;
278 : }
279 :
280 : static TDSODBC_INLINE RETCODE SQL_API
281 : bcp_initW(HDBC hdbc, const SQLWCHAR *tblname, const SQLWCHAR *hfile, const SQLWCHAR *errfile, int direction)
282 : {
283 9 : struct tdsodbc_impl_bcp_init_params params = {tblname, hfile, errfile, direction};
284 9 : return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_INITW, ¶ms, SQL_IS_POINTER)) ? SUCCEED : FAIL;
285 : }
286 :
287 : struct tdsodbc_impl_bcp_control_params
288 : {
289 : int field;
290 : void *value;
291 : };
292 :
293 : static TDSODBC_INLINE RETCODE SQL_API
294 : bcp_control(HDBC hdbc, int field, void *value)
295 : {
296 : struct tdsodbc_impl_bcp_control_params params = {field, value};
297 : return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_CONTROL, ¶ms, SQL_IS_POINTER)) ? SUCCEED : FAIL;
298 : }
299 :
300 : struct tdsodbc_impl_bcp_colptr_params
301 : {
302 : const unsigned char * colptr;
303 : int table_column;
304 : };
305 :
306 : static TDSODBC_INLINE RETCODE SQL_API
307 : bcp_colptr(HDBC hdbc, const unsigned char * colptr, int table_column)
308 : {
309 : struct tdsodbc_impl_bcp_colptr_params params = {colptr, table_column};
310 : return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_COLPTR, ¶ms, SQL_IS_POINTER)) ? SUCCEED : FAIL;
311 : }
312 :
313 : static TDSODBC_INLINE RETCODE SQL_API
314 : bcp_sendrow(HDBC hdbc)
315 : {
316 162 : return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_SENDROW, NULL, SQL_IS_POINTER)) ? SUCCEED : FAIL;
317 : }
318 :
319 : struct tdsodbc_impl_bcp_batch_params
320 : {
321 : int rows;
322 : };
323 :
324 : static TDSODBC_INLINE int SQL_API
325 18 : bcp_batch(HDBC hdbc)
326 : {
327 18 : struct tdsodbc_impl_bcp_batch_params params = {-1};
328 18 : return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_BATCH, ¶ms, SQL_IS_POINTER)) ? params.rows : -1;
329 : }
330 :
331 : struct tdsodbc_impl_bcp_done_params
332 : {
333 : int rows;
334 : };
335 :
336 : static TDSODBC_INLINE int SQL_API
337 18 : bcp_done(HDBC hdbc)
338 : {
339 18 : struct tdsodbc_impl_bcp_done_params params = {-1};
340 18 : return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_DONE, ¶ms, SQL_IS_POINTER)) ? params.rows : -1;
341 : }
342 :
343 : struct tdsodbc_impl_bcp_bind_params
344 : {
345 : const unsigned char * varaddr;
346 : int prefixlen;
347 : int varlen;
348 : const unsigned char * terminator;
349 : int termlen;
350 : int vartype;
351 : int table_column;
352 : };
353 :
354 : static TDSODBC_INLINE RETCODE SQL_API
355 : bcp_bind(HDBC hdbc, const unsigned char * varaddr, int prefixlen, int varlen,
356 : const unsigned char * terminator, int termlen, int vartype, int table_column)
357 : {
358 476 : struct tdsodbc_impl_bcp_bind_params params = {varaddr, prefixlen, varlen, terminator, termlen, vartype, table_column};
359 476 : return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_BIND, ¶ms, SQL_IS_POINTER)) ? SUCCEED : FAIL;
360 : }
361 :
362 : #ifdef UNICODE
363 : #define bcp_init bcp_initW
364 : #else
365 : #define bcp_init bcp_initA
366 : #endif
367 :
368 : #endif /* TDSODBC_BCP */
369 :
370 : #ifdef __cplusplus
371 : }
372 : #endif
373 :
374 : #endif /* _odbcss_h_ */
|