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