FreeTDS API
odbcss.h
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_ATTACHDBFILENAME
48 #define SQL_COPT_SS_ATTACHDBFILENAME (SQL_COPT_SS_BASE+21)
49 #endif
50 
51 #ifndef SQL_COPT_SS_MARS_ENABLED
52 #define SQL_COPT_SS_MARS_ENABLED (SQL_COPT_SS_BASE+24)
53 #endif
54 
55 #ifndef SQL_COPT_SS_OLDPWD
56 #define SQL_COPT_SS_OLDPWD (SQL_COPT_SS_BASE+26)
57 #endif
58 
59 #define SQL_INFO_FREETDS_TDS_VERSION 1300
60 #define SQL_INFO_FREETDS_SOCKET 1301
61 
62 #ifndef SQL_MARS_ENABLED_NO
63 #define SQL_MARS_ENABLED_NO 0
64 #endif
65 
66 #ifndef SQL_MARS_ENABLED_YES
67 #define SQL_MARS_ENABLED_YES 1
68 #endif
69 
70 #ifndef SQL_SS_VARIANT
71 #define SQL_SS_VARIANT (-150)
72 #endif
73 
74 #ifndef SQL_SS_UDT
75 #define SQL_SS_UDT (-151)
76 #endif
77 
78 #ifndef SQL_SS_XML
79 #define SQL_SS_XML (-152)
80 #endif
81 
82 #ifndef SQL_SS_TABLE
83 #define SQL_SS_TABLE (-153)
84 #endif
85 
86 #ifndef SQL_SS_TIME2
87 #define SQL_SS_TIME2 (-154)
88 #endif
89 
90 #ifndef SQL_SS_TIMESTAMPOFFSET
91 #define SQL_SS_TIMESTAMPOFFSET (-155)
92 #endif
93 
94 /*
95  * these types are used from conversion from client to server
96  */
97 #ifndef SQL_C_SS_TIME2
98 #define SQL_C_SS_TIME2 (0x4000)
99 #endif
100 
101 #ifndef SQL_C_SS_TIMESTAMPOFFSET
102 #define SQL_C_SS_TIMESTAMPOFFSET (0x4001)
103 #endif
104 
105 #ifndef SQL_CA_SS_BASE
106 #define SQL_CA_SS_BASE 1200
107 #endif
108 
109 #ifndef SQL_CA_SS_UDT_CATALOG_NAME
110 #define SQL_CA_SS_UDT_CATALOG_NAME (SQL_CA_SS_BASE+18)
111 #endif
112 
113 #ifndef SQL_CA_SS_UDT_SCHEMA_NAME
114 #define SQL_CA_SS_UDT_SCHEMA_NAME (SQL_CA_SS_BASE+19)
115 #endif
116 
117 #ifndef SQL_CA_SS_UDT_TYPE_NAME
118 #define SQL_CA_SS_UDT_TYPE_NAME (SQL_CA_SS_BASE+20)
119 #endif
120 
121 #ifndef SQL_CA_SS_UDT_ASSEMBLY_TYPE_NAME
122 #define SQL_CA_SS_UDT_ASSEMBLY_TYPE_NAME (SQL_CA_SS_BASE+21)
123 #endif
124 
125 #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_CATALOG_NAME
126 #define SQL_CA_SS_XML_SCHEMACOLLECTION_CATALOG_NAME (SQL_CA_SS_BASE+22)
127 #endif
128 
129 #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_SCHEMA_NAME
130 #define SQL_CA_SS_XML_SCHEMACOLLECTION_SCHEMA_NAME (SQL_CA_SS_BASE+23)
131 #endif
132 
133 #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_NAME
134 #define SQL_CA_SS_XML_SCHEMACOLLECTION_NAME (SQL_CA_SS_BASE+24)
135 #endif
136 
137 typedef struct tagSS_TIME2_STRUCT {
138  SQLUSMALLINT hour;
139  SQLUSMALLINT minute;
140  SQLUSMALLINT second;
141  SQLUINTEGER fraction;
143 
145  SQLSMALLINT year;
146  SQLUSMALLINT month;
147  SQLUSMALLINT day;
148  SQLUSMALLINT hour;
149  SQLUSMALLINT minute;
150  SQLUSMALLINT second;
151  SQLUINTEGER fraction;
152  SQLSMALLINT timezone_hour;
153  SQLSMALLINT timezone_minute;
155 
156 
157 #ifdef TDSODBC_BCP
158 
159 #ifndef SUCCEED
160 #define SUCCEED 1
161 #endif
162 #ifndef FAIL
163 #define FAIL 0
164 #endif
165 
166 #ifndef BCPKEEPIDENTITY
167 #define BCPKEEPIDENTITY 8
168 #endif
169 #ifndef BCPHINTSA
170 #define BCPHINTSA 10
171 #endif
172 #ifndef BCPHINTSW
173 #define BCPHINTSW 11
174 #endif
175 
176 #define BCP_DIRECTION_IN 1
177 
178 #define SQL_COPT_SS_BCP (SQL_COPT_SS_BASE+19)
179 #define SQL_BCP_OFF 0
180 #define SQL_BCP_ON 1
181 
182 #define SQL_COPT_TDSODBC_IMPL_BASE 1500
183 #define SQL_COPT_TDSODBC_IMPL_BCP_INITA (SQL_COPT_TDSODBC_IMPL_BASE)
184 /* deprecated SQL_COPT_TDSODBC_IMPL_BCP_CONTROL */
185 #define SQL_COPT_TDSODBC_IMPL_BCP_COLPTR (SQL_COPT_TDSODBC_IMPL_BASE+2)
186 #define SQL_COPT_TDSODBC_IMPL_BCP_SENDROW (SQL_COPT_TDSODBC_IMPL_BASE+3)
187 #define SQL_COPT_TDSODBC_IMPL_BCP_BATCH (SQL_COPT_TDSODBC_IMPL_BASE+4)
188 #define SQL_COPT_TDSODBC_IMPL_BCP_DONE (SQL_COPT_TDSODBC_IMPL_BASE+5)
189 #define SQL_COPT_TDSODBC_IMPL_BCP_BIND (SQL_COPT_TDSODBC_IMPL_BASE+6)
190 #define SQL_COPT_TDSODBC_IMPL_BCP_INITW (SQL_COPT_TDSODBC_IMPL_BASE+7)
191 #define SQL_COPT_TDSODBC_IMPL_BCP_CONTROL (SQL_COPT_TDSODBC_IMPL_BASE+8)
192 
193 #define SQL_VARLEN_DATA -10
194 
195 /* copied from sybdb.h which was copied from tds.h */
196 /* TODO find a much better way... */
197 enum
198 {
199  BCP_TYPE_SQLCHAR = 47, /* 0x2F */
200 #define BCP_TYPE_SQLCHAR BCP_TYPE_SQLCHAR
201  BCP_TYPE_SQLVARCHAR = 39, /* 0x27 */
202 #define BCP_TYPE_SQLVARCHAR BCP_TYPE_SQLVARCHAR
203  BCP_TYPE_SQLINTN = 38, /* 0x26 */
204 #define BCP_TYPE_SQLINTN BCP_TYPE_SQLINTN
205  BCP_TYPE_SQLINT1 = 48, /* 0x30 */
206 #define BCP_TYPE_SQLINT1 BCP_TYPE_SQLINT1
207  BCP_TYPE_SQLINT2 = 52, /* 0x34 */
208 #define BCP_TYPE_SQLINT2 BCP_TYPE_SQLINT2
209  BCP_TYPE_SQLINT4 = 56, /* 0x38 */
210 #define BCP_TYPE_SQLINT4 BCP_TYPE_SQLINT4
211  BCP_TYPE_SQLINT8 = 127, /* 0x7F */
212 #define BCP_TYPE_SQLINT8 BCP_TYPE_SQLINT8
213  BCP_TYPE_SQLFLT8 = 62, /* 0x3E */
214 #define BCP_TYPE_SQLFLT8 BCP_TYPE_SQLFLT8
215  BCP_TYPE_SQLDATETIME = 61, /* 0x3D */
216 #define BCP_TYPE_SQLDATETIME BCP_TYPE_SQLDATETIME
217  BCP_TYPE_SQLBIT = 50, /* 0x32 */
218 #define BCP_TYPE_SQLBIT BCP_TYPE_SQLBIT
219  BCP_TYPE_SQLBITN = 104, /* 0x68 */
220 #define BCP_TYPE_SQLBITN BCP_TYPE_SQLBITN
221  BCP_TYPE_SQLTEXT = 35, /* 0x23 */
222 #define BCP_TYPE_SQLTEXT BCP_TYPE_SQLTEXT
223  BCP_TYPE_SQLNTEXT = 99, /* 0x63 */
224 #define BCP_TYPE_SQLNTEXT BCP_TYPE_SQLNTEXT
225  BCP_TYPE_SQLIMAGE = 34, /* 0x22 */
226 #define BCP_TYPE_SQLIMAGE BCP_TYPE_SQLIMAGE
227  BCP_TYPE_SQLMONEY4 = 122, /* 0x7A */
228 #define BCP_TYPE_SQLMONEY4 BCP_TYPE_SQLMONEY4
229  BCP_TYPE_SQLMONEY = 60, /* 0x3C */
230 #define BCP_TYPE_SQLMONEY BCP_TYPE_SQLMONEY
231  BCP_TYPE_SQLDATETIME4 = 58, /* 0x3A */
232 #define BCP_TYPE_SQLDATETIME4 BCP_TYPE_SQLDATETIME4
233  BCP_TYPE_SQLREAL = 59, /* 0x3B */
234  BCP_TYPE_SQLFLT4 = 59, /* 0x3B */
235 #define BCP_TYPE_SQLREAL BCP_TYPE_SQLREAL
236 #define BCP_TYPE_SQLFLT4 BCP_TYPE_SQLFLT4
237  BCP_TYPE_SQLBINARY = 45, /* 0x2D */
238 #define BCP_TYPE_SQLBINARY BCP_TYPE_SQLBINARY
239  BCP_TYPE_SQLVOID = 31, /* 0x1F */
240 #define BCP_TYPE_SQLVOID BCP_TYPE_SQLVOID
241  BCP_TYPE_SQLVARBINARY = 37, /* 0x25 */
242 #define BCP_TYPE_SQLVARBINARY BCP_TYPE_SQLVARBINARY
243  BCP_TYPE_SQLNUMERIC = 108, /* 0x6C */
244 #define BCP_TYPE_SQLNUMERIC BCP_TYPE_SQLNUMERIC
245  BCP_TYPE_SQLDECIMAL = 106, /* 0x6A */
246 #define BCP_TYPE_SQLDECIMAL BCP_TYPE_SQLDECIMAL
247  BCP_TYPE_SQLFLTN = 109, /* 0x6D */
248 #define BCP_TYPE_SQLFLTN BCP_TYPE_SQLFLTN
249  BCP_TYPE_SQLMONEYN = 110, /* 0x6E */
250 #define BCP_TYPE_SQLMONEYN BCP_TYPE_SQLMONEYN
251  BCP_TYPE_SQLDATETIMN = 111, /* 0x6F */
252 #define BCP_TYPE_SQLDATETIMN BCP_TYPE_SQLDATETIMN
253  BCP_TYPE_SQLNVARCHAR = 103, /* 0x67 */
254 #define BCP_TYPE_SQLNVARCHAR BCP_TYPE_SQLNVARCHAR
255  BCP_TYPE_SQLUNIQUEID = 36, /* 0x24 */
256 #define BCP_TYPE_SQLUNIQUEID BCP_TYPE_SQLUNIQUEID
257  BCP_TYPE_SQLDATETIME2 = 42, /* 0x2a */
258 #define BCP_TYPE_SQLDATETIME2 BCP_TYPE_SQLDATETIME2
259 };
260 
261 typedef struct
262 {
263  int dtdays;
264  int dttime;
265 } DBDATETIME;
266 
267 #if defined(__cplusplus) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
268 #define TDSODBC_INLINE inline
269 #elif defined(_MSC_VER)
270 #define TDSODBC_INLINE __inline
271 #else
272 #define TDSODBC_INLINE __inline__
273 #endif
274 
275 struct tdsodbc_impl_bcp_init_params
276 {
277  const void *tblname;
278  const void *hfile;
279  const void *errfile;
280  int direction;
281 };
282 
283 static TDSODBC_INLINE RETCODE SQL_API
284 bcp_initA(HDBC hdbc, const char *tblname, const char *hfile, const char *errfile, int direction)
285 {
286  struct tdsodbc_impl_bcp_init_params params = {tblname, hfile, errfile, direction};
287  return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_INITA, &params, SQL_IS_POINTER)) ? SUCCEED : FAIL;
288 }
289 
290 static TDSODBC_INLINE RETCODE SQL_API
291 bcp_initW(HDBC hdbc, const SQLWCHAR *tblname, const SQLWCHAR *hfile, const SQLWCHAR *errfile, int direction)
292 {
293  struct tdsodbc_impl_bcp_init_params params = {tblname, hfile, errfile, direction};
294  return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_INITW, &params, SQL_IS_POINTER)) ? SUCCEED : FAIL;
295 }
296 
297 struct tdsodbc_impl_bcp_control_params
298 {
299  int field;
300  void *value;
301 };
302 
303 static TDSODBC_INLINE RETCODE SQL_API
304 bcp_control(HDBC hdbc, int field, void *value)
305 {
306  struct tdsodbc_impl_bcp_control_params params = {field, value};
307  return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_CONTROL, &params, SQL_IS_POINTER)) ? SUCCEED : FAIL;
308 }
309 
310 struct tdsodbc_impl_bcp_colptr_params
311 {
312  const unsigned char * colptr;
313  int table_column;
314 };
315 
316 static TDSODBC_INLINE RETCODE SQL_API
317 bcp_colptr(HDBC hdbc, const unsigned char * colptr, int table_column)
318 {
319  struct tdsodbc_impl_bcp_colptr_params params = {colptr, table_column};
320  return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_COLPTR, &params, SQL_IS_POINTER)) ? SUCCEED : FAIL;
321 }
322 
323 static TDSODBC_INLINE RETCODE SQL_API
324 bcp_sendrow(HDBC hdbc)
325 {
326  return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_SENDROW, NULL, SQL_IS_POINTER)) ? SUCCEED : FAIL;
327 }
328 
329 struct tdsodbc_impl_bcp_batch_params
330 {
331  int rows;
332 };
333 
334 static TDSODBC_INLINE int SQL_API
335 bcp_batch(HDBC hdbc)
336 {
337  struct tdsodbc_impl_bcp_batch_params params = {-1};
338  return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_BATCH, &params, SQL_IS_POINTER)) ? params.rows : -1;
339 }
340 
341 struct tdsodbc_impl_bcp_done_params
342 {
343  int rows;
344 };
345 
346 static TDSODBC_INLINE int SQL_API
347 bcp_done(HDBC hdbc)
348 {
349  struct tdsodbc_impl_bcp_done_params params = {-1};
350  return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_DONE, &params, SQL_IS_POINTER)) ? params.rows : -1;
351 }
352 
353 struct tdsodbc_impl_bcp_bind_params
354 {
355  const unsigned char * varaddr;
356  int prefixlen;
357  int varlen;
358  const unsigned char * terminator;
359  int termlen;
360  int vartype;
361  int table_column;
362 };
363 
364 static TDSODBC_INLINE RETCODE SQL_API
365 bcp_bind(HDBC hdbc, const unsigned char * varaddr, int prefixlen, int varlen,
366  const unsigned char * terminator, int termlen, int vartype, int table_column)
367 {
368  struct tdsodbc_impl_bcp_bind_params params = {varaddr, prefixlen, varlen, terminator, termlen, vartype, table_column};
369  return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_BIND, &params, SQL_IS_POINTER)) ? SUCCEED : FAIL;
370 }
371 
372 #ifdef UNICODE
373 #define bcp_init bcp_initW
374 #define BCPHINTS BCPHINTSW
375 #else
376 #define bcp_init bcp_initA
377 #define BCPHINTS BCPHINTSA
378 #endif
379 
380 #endif /* TDSODBC_BCP */
381 
382 #ifdef __cplusplus
383 }
384 #endif
385 
386 #endif /* _odbcss_h_ */
RETCODE bcp_control(DBPROCESS *dbproc, int field, DBINT value)
Set BCP options for uploading a datafile.
Definition: bcp.c:542
Definition: sybdb.h:295
RETCODE bcp_sendrow(DBPROCESS *dbproc)
Write data in host variables to the table.
Definition: bcp.c:1382
DBINT bcp_done(DBPROCESS *dbproc)
Conclude the transfer of data from program variables.
Definition: bcp.c:2039
Definition: odbcss.h:137
DBINT bcp_batch(DBPROCESS *dbproc)
Commit a set of rows to the table.
Definition: bcp.c:2012
RETCODE bcp_colptr(DBPROCESS *dbproc, BYTE *colptr, int table_column)
Override bcp_bind() by pointing to a different host variable.
Definition: bcp.c:672
Definition: odbcss.h:144
RETCODE bcp_bind(DBPROCESS *dbproc, BYTE *varaddr, int prefixlen, DBINT varlen, BYTE *terminator, int termlen, int db_vartype, int table_column)
Bind a program host variable to a database column.
Definition: bcp.c:2081