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