FreeTDS API

Loading...
Searching...
No Matches
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_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 BCPHINTSA
166#define BCPHINTSA 10
167#endif
168#ifndef BCPHINTSW
169#define BCPHINTSW 11
170#endif
171
172#define BCP_DIRECTION_IN 1
173
174#define SQL_COPT_SS_BCP (SQL_COPT_SS_BASE+19)
175#define SQL_BCP_OFF 0
176#define SQL_BCP_ON 1
177
178#define SQL_COPT_TDSODBC_IMPL_BASE 1500
179#define SQL_COPT_TDSODBC_IMPL_BCP_INITA (SQL_COPT_TDSODBC_IMPL_BASE)
180/* deprecated SQL_COPT_TDSODBC_IMPL_BCP_CONTROL */
181#define SQL_COPT_TDSODBC_IMPL_BCP_COLPTR (SQL_COPT_TDSODBC_IMPL_BASE+2)
182#define SQL_COPT_TDSODBC_IMPL_BCP_SENDROW (SQL_COPT_TDSODBC_IMPL_BASE+3)
183#define SQL_COPT_TDSODBC_IMPL_BCP_BATCH (SQL_COPT_TDSODBC_IMPL_BASE+4)
184#define SQL_COPT_TDSODBC_IMPL_BCP_DONE (SQL_COPT_TDSODBC_IMPL_BASE+5)
185#define SQL_COPT_TDSODBC_IMPL_BCP_BIND (SQL_COPT_TDSODBC_IMPL_BASE+6)
186#define SQL_COPT_TDSODBC_IMPL_BCP_INITW (SQL_COPT_TDSODBC_IMPL_BASE+7)
187#define SQL_COPT_TDSODBC_IMPL_BCP_CONTROL (SQL_COPT_TDSODBC_IMPL_BASE+8)
188
189#define SQL_VARLEN_DATA -10
190
191/* copied from sybdb.h which was copied from tds.h */
192/* TODO find a much better way... */
193 enum
194{
195 BCP_TYPE_SQLCHAR = 47, /* 0x2F */
196#define BCP_TYPE_SQLCHAR BCP_TYPE_SQLCHAR
197 BCP_TYPE_SQLVARCHAR = 39, /* 0x27 */
198#define BCP_TYPE_SQLVARCHAR BCP_TYPE_SQLVARCHAR
199 BCP_TYPE_SQLINTN = 38, /* 0x26 */
200#define BCP_TYPE_SQLINTN BCP_TYPE_SQLINTN
201 BCP_TYPE_SQLINT1 = 48, /* 0x30 */
202#define BCP_TYPE_SQLINT1 BCP_TYPE_SQLINT1
203 BCP_TYPE_SQLINT2 = 52, /* 0x34 */
204#define BCP_TYPE_SQLINT2 BCP_TYPE_SQLINT2
205 BCP_TYPE_SQLINT4 = 56, /* 0x38 */
206#define BCP_TYPE_SQLINT4 BCP_TYPE_SQLINT4
207 BCP_TYPE_SQLINT8 = 127, /* 0x7F */
208#define BCP_TYPE_SQLINT8 BCP_TYPE_SQLINT8
209 BCP_TYPE_SQLFLT8 = 62, /* 0x3E */
210#define BCP_TYPE_SQLFLT8 BCP_TYPE_SQLFLT8
211 BCP_TYPE_SQLDATETIME = 61, /* 0x3D */
212#define BCP_TYPE_SQLDATETIME BCP_TYPE_SQLDATETIME
213 BCP_TYPE_SQLBIT = 50, /* 0x32 */
214#define BCP_TYPE_SQLBIT BCP_TYPE_SQLBIT
215 BCP_TYPE_SQLBITN = 104, /* 0x68 */
216#define BCP_TYPE_SQLBITN BCP_TYPE_SQLBITN
217 BCP_TYPE_SQLTEXT = 35, /* 0x23 */
218#define BCP_TYPE_SQLTEXT BCP_TYPE_SQLTEXT
219 BCP_TYPE_SQLNTEXT = 99, /* 0x63 */
220#define BCP_TYPE_SQLNTEXT BCP_TYPE_SQLNTEXT
221 BCP_TYPE_SQLIMAGE = 34, /* 0x22 */
222#define BCP_TYPE_SQLIMAGE BCP_TYPE_SQLIMAGE
223 BCP_TYPE_SQLMONEY4 = 122, /* 0x7A */
224#define BCP_TYPE_SQLMONEY4 BCP_TYPE_SQLMONEY4
225 BCP_TYPE_SQLMONEY = 60, /* 0x3C */
226#define BCP_TYPE_SQLMONEY BCP_TYPE_SQLMONEY
227 BCP_TYPE_SQLDATETIME4 = 58, /* 0x3A */
228#define BCP_TYPE_SQLDATETIME4 BCP_TYPE_SQLDATETIME4
229 BCP_TYPE_SQLREAL = 59, /* 0x3B */
230 BCP_TYPE_SQLFLT4 = 59, /* 0x3B */
231#define BCP_TYPE_SQLREAL BCP_TYPE_SQLREAL
232#define BCP_TYPE_SQLFLT4 BCP_TYPE_SQLFLT4
233 BCP_TYPE_SQLBINARY = 45, /* 0x2D */
234#define BCP_TYPE_SQLBINARY BCP_TYPE_SQLBINARY
235 BCP_TYPE_SQLVOID = 31, /* 0x1F */
236#define BCP_TYPE_SQLVOID BCP_TYPE_SQLVOID
237 BCP_TYPE_SQLVARBINARY = 37, /* 0x25 */
238#define BCP_TYPE_SQLVARBINARY BCP_TYPE_SQLVARBINARY
239 BCP_TYPE_SQLNUMERIC = 108, /* 0x6C */
240#define BCP_TYPE_SQLNUMERIC BCP_TYPE_SQLNUMERIC
241 BCP_TYPE_SQLDECIMAL = 106, /* 0x6A */
242#define BCP_TYPE_SQLDECIMAL BCP_TYPE_SQLDECIMAL
243 BCP_TYPE_SQLFLTN = 109, /* 0x6D */
244#define BCP_TYPE_SQLFLTN BCP_TYPE_SQLFLTN
245 BCP_TYPE_SQLMONEYN = 110, /* 0x6E */
246#define BCP_TYPE_SQLMONEYN BCP_TYPE_SQLMONEYN
247 BCP_TYPE_SQLDATETIMN = 111, /* 0x6F */
248#define BCP_TYPE_SQLDATETIMN BCP_TYPE_SQLDATETIMN
249 BCP_TYPE_SQLNVARCHAR = 103, /* 0x67 */
250#define BCP_TYPE_SQLNVARCHAR BCP_TYPE_SQLNVARCHAR
251 BCP_TYPE_SQLUNIQUEID = 36, /* 0x24 */
252#define BCP_TYPE_SQLUNIQUEID BCP_TYPE_SQLUNIQUEID
253 BCP_TYPE_SQLDATETIME2 = 42, /* 0x2a */
254#define BCP_TYPE_SQLDATETIME2 BCP_TYPE_SQLDATETIME2
255};
256
257 typedef struct
258{
259 int dtdays;
260 int dttime;
261} DBDATETIME;
262
263#ifdef _MSC_VER
264#define TDSODBC_INLINE __inline
265#else
266#define TDSODBC_INLINE __inline__
267#endif
268
269 struct tdsodbc_impl_bcp_init_params
270{
271 const void *tblname;
272 const void *hfile;
273 const void *errfile;
274 int direction;
275};
276
277 static TDSODBC_INLINE RETCODE SQL_API
278bcp_initA(HDBC hdbc, const char *tblname, const char *hfile, const char *errfile, int direction)
279{
280 struct tdsodbc_impl_bcp_init_params params = {tblname, hfile, errfile, direction};
281 return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_INITA, &params, SQL_IS_POINTER)) ? SUCCEED : FAIL;
282}
283
284 static TDSODBC_INLINE RETCODE SQL_API
285bcp_initW(HDBC hdbc, const SQLWCHAR *tblname, const SQLWCHAR *hfile, const SQLWCHAR *errfile, int direction)
286{
287 struct tdsodbc_impl_bcp_init_params params = {tblname, hfile, errfile, direction};
288 return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_INITW, &params, SQL_IS_POINTER)) ? SUCCEED : FAIL;
289}
290
291 struct tdsodbc_impl_bcp_control_params
292{
293 int field;
294 void *value;
295};
296
297 static TDSODBC_INLINE RETCODE SQL_API
298 bcp_control(HDBC hdbc, int field, void *value)
299{
300 struct tdsodbc_impl_bcp_control_params params = {field, value};
301 return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_CONTROL, &params, SQL_IS_POINTER)) ? SUCCEED : FAIL;
302}
303
304 struct tdsodbc_impl_bcp_colptr_params
305{
306 const unsigned char * colptr;
307 int table_column;
308};
309
310 static TDSODBC_INLINE RETCODE SQL_API
311 bcp_colptr(HDBC hdbc, const unsigned char * colptr, int table_column)
312{
313 struct tdsodbc_impl_bcp_colptr_params params = {colptr, table_column};
314 return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_COLPTR, &params, SQL_IS_POINTER)) ? SUCCEED : FAIL;
315}
316
317 static TDSODBC_INLINE RETCODE SQL_API
318 bcp_sendrow(HDBC hdbc)
319{
320 return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_SENDROW, NULL, SQL_IS_POINTER)) ? SUCCEED : FAIL;
321}
322
323 struct tdsodbc_impl_bcp_batch_params
324{
325 int rows;
326};
327
328 static TDSODBC_INLINE int SQL_API
329 bcp_batch(HDBC hdbc)
330{
331 struct tdsodbc_impl_bcp_batch_params params = {-1};
332 return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_BATCH, &params, SQL_IS_POINTER)) ? params.rows : -1;
333}
334
335 struct tdsodbc_impl_bcp_done_params
336{
337 int rows;
338};
339
340 static TDSODBC_INLINE int SQL_API
341 bcp_done(HDBC hdbc)
342{
343 struct tdsodbc_impl_bcp_done_params params = {-1};
344 return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_DONE, &params, SQL_IS_POINTER)) ? params.rows : -1;
345}
346
347 struct tdsodbc_impl_bcp_bind_params
348{
349 const unsigned char * varaddr;
350 int prefixlen;
351 int varlen;
352 const unsigned char * terminator;
353 int termlen;
354 int vartype;
355 int table_column;
356};
357
358 static TDSODBC_INLINE RETCODE SQL_API
359 bcp_bind(HDBC hdbc, const unsigned char * varaddr, int prefixlen, int varlen,
360 const unsigned char * terminator, int termlen, int vartype, int table_column)
361{
362 struct tdsodbc_impl_bcp_bind_params params = {varaddr, prefixlen, varlen, terminator, termlen, vartype, table_column};
363 return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_BIND, &params, SQL_IS_POINTER)) ? SUCCEED : FAIL;
364}
365
366#ifdef UNICODE
367#define bcp_init bcp_initW
368#define BCPHINTS BCPHINTSW
369#else
370#define bcp_init bcp_initA
371#define BCPHINTS BCPHINTSA
372#endif
373
374#endif /* TDSODBC_BCP */
375
376#ifdef __cplusplus
377}
378#endif
379
380#endif /* _odbcss_h_ */
bcp_control
RETCODE bcp_control(DBPROCESS *dbproc, int field, DBINT value)
Set BCP options for uploading a datafile.
Definition bcp.c:546
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:674
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:2083
bcp_done
DBINT bcp_done(DBPROCESS *dbproc)
Conclude the transfer of data from program variables.
Definition bcp.c:2041
bcp_batch
DBINT bcp_batch(DBPROCESS *dbproc)
Commit a set of rows to the table.
Definition bcp.c:2014
bcp_sendrow
RETCODE bcp_sendrow(DBPROCESS *dbproc)
Write data in host variables to the table.
Definition bcp.c:1384
tagSS_TIME2_STRUCT
Definition odbcss.h:133
tagSS_TIMESTAMPOFFSET_STRUCT
Definition odbcss.h:140
DBDATETIME
Definition sybdb.h:296