3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 using System.Runtime.InteropServices;
27 namespace IBM.Data.DB2
30 /// DB2Prototypes class is a wrapper for the DB2.lib, IBM's Call Level Interface to DB2
34 /*internal class DB2CLIWrapper
38 private const string libname = "db2_36";
42 private const string libname = "db2cli";
45 [DllImport("db2cli", EntryPoint = "SQLAllocHandle")]
46 internal static extern short SQLAllocHandle(short handleType, IntPtr inputHandle, ref IntPtr outputHandle);
48 [DllImport("db2cli", EntryPoint = "SQLFreeHandle")]
49 internal static extern short SQLFreeHandle(short handleType, IntPtr inputHandle);
51 [DllImport("db2cli", EntryPoint = "SQLGetConnectAttrW")]
52 internal static extern short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, [Out] IntPtr ValuePtr, int BufferLength, out int StringLengthPtr);
54 [DllImport("db2cli", EntryPoint = "SQLGetConnectAttrW")]
55 internal static extern short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, out int Value, int BufferLength, IntPtr Zero);
57 [DllImport("db2cli", EntryPoint = "SQLFreeStmt")]
58 internal static extern short SQLFreeStmt(IntPtr StatementHandle, short option);
60 [DllImport("db2cli", EntryPoint = "SQLConnect")]
61 internal static extern short SQLConnect(IntPtr sqlHdbc, string serverName, short serverNameLength, string userName, short userNameLength, string authentication, short authenticationLength);
62 [DllImport("db2cli", EntryPoint = "SQLColAttribute")]
63 internal static extern short SQLColAttribute(IntPtr StatementHandle, short ColumnNumber, short FieldIdentifier, IntPtr CharacterAttribute, short BufferLength, ref short StringLength, ref int NumericAttribute);
64 //[DllImport("db2cli", EntryPoint = "SQLGetData")]
65 // internal static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, IntPtr TargetPtr, IntPtr BufferLength, ref IntPtr StrLen_or_Ind);
66 [DllImport("db2cli", EntryPoint="SQLMoreResults")]
67 internal static extern short SQLMoreResults(IntPtr StatementHandle);
69 //[DllImport("db2cli", EntryPoint = "SQLGetData")]
70 //internal static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, IntPtr TargetPtr, IntPtr BufferLength, out int StrLen_or_Ind);
71 [DllImport("db2cli", EntryPoint = "SQLGetData")]
72 internal static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, IntPtr TargetPtr, int BufferLength, out int StrLen_or_Ind);
75 //[DllImport("db2cli", EntryPoint = "SQLGetData")]
76 //internal static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, byte[] TargetPtr, IntPtr BufferLength, ref IntPtr StrLen_or_Ind);
78 [DllImport("db2cli", EntryPoint = "SQLGetData")]
79 internal static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, byte[] TargetPtr, int BufferLength, out int StrLen_or_Ind);
81 [DllImport("db2cli", EntryPoint = "SQLGetData")]
82 internal static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, [Out] StringBuilder sb, int BufferLength, out int StrLen_or_Ind);
84 [DllImport("db2cli", EntryPoint = "SQLColAttributeW")]
85 internal static extern short SQLColAttribute(IntPtr StatementHandle, short ColumnNumber, short FieldIdentifier, [Out] StringBuilder CharacterAttribute, short BufferLength, out short StringLength, out int NumericAttribute);
87 [DllImport("db2cli", CharSet = CharSet.Auto, EntryPoint = "SQLDisconnect")]
88 internal static extern short SQLDisconnect(IntPtr sqlHdbc);
89 [DllImport("db2cli", EntryPoint = "SQLGetDiagRec")]
90 internal static extern short SQLGetDiagRec( short handleType, IntPtr handle, short recNum, [Out] StringBuilder sqlState, ref IntPtr nativeErrorPtr, [Out] StringBuilder errorMessage, short bufferLength, ref IntPtr shortTextLengthPtr);
91 [DllImport("db2cli", EntryPoint = "SQLSetConnectAttr")]
92 internal static extern short SQLSetConnectAttr(IntPtr sqlHdbc, long sqlAttr, [In] IntPtr sqlValuePtr, long sqlValueLength);
93 [DllImport("db2cli", EntryPoint = "SQLSetStmtAttr")]
94 internal static extern short SQLSetStmtAttr(IntPtr sqlHstmt, long sqlAttr, [In] IntPtr sqlValuePtr, long sqlValueLength);
95 [DllImport("db2cli", EntryPoint = "SQLEndTran")]
96 internal static extern short SQLEndTran (short handleType, IntPtr handle, short fType);
97 [DllImport("db2cli", EntryPoint = "SQLCancel")]
98 internal static extern short SQLCancel(IntPtr handle);
99 [DllImport("db2cli", EntryPoint = "SQLNumResultCols")]
100 internal static extern short SQLNumResultCols(IntPtr handle, ref int numCols);
101 [DllImport("db2cli", EntryPoint = "SQLFetch")]
102 internal static extern short SQLFetch(IntPtr handle);
103 [DllImport("db2cli", EntryPoint = "SQLRowCount")]
104 internal static extern short SQLRowCount(IntPtr stmtHandle, ref int numRows);
105 [DllImport("db2cli", EntryPoint = "SQLExecute")]
106 internal static extern short SQLExecute(IntPtr handle);
107 [DllImport ("db2cli", EntryPoint = "SQLExecDirect")]
108 internal static extern short SQLExecDirect(IntPtr stmtHandle, string stmt, int length);
109 [DllImport("db2cli", EntryPoint = "SQLDescribeCol")]
110 internal static extern short SQLDescribeCol(IntPtr stmtHandle, ushort colNum, StringBuilder colName, short colNameMaxLength, IntPtr colNameLength, ref IntPtr dataType, ref IntPtr colSizePtr, ref IntPtr scalePtr, ref IntPtr nullablePtr );
111 [DllImport("db2cli", EntryPoint = "SQLBindCol")]
112 internal static extern short SQLBindCol(IntPtr StatementHandle, short ColumnNumber, short TargetType, IntPtr TargetValue, IntPtr BufferLength, ref IntPtr StrLen_or_Ind);
113 [DllImport("db2cli", EntryPoint = "SQLDriverConnect")]
114 internal static extern short SQLDriverConnect(IntPtr hdbc, int centered, [In] string inConnectStr, [In] int inStrLength, [Out] StringBuilder outConnectStr, [Out] int outStrCapacity, [Out] IntPtr outStrLengthReturned, [In] int completion);
115 [DllImport("db2cli", EntryPoint = "SQLPrepare")]
116 internal static extern short SQLPrepare(IntPtr stmtHandle, string stmt, int length);
117 [DllImport("db2cli", EntryPoint = "SQLDescribeParam")]
118 internal static extern short SQLDescribeParam(IntPtr stmtHandle, short paramNumber,ref IntPtr dataType, ref IntPtr paramSize, ref IntPtr decimalDigits, ref IntPtr nullable);
119 [DllImport("db2cli", EntryPoint = "SQLNumParams")]
120 internal static extern short SQLNumParams(IntPtr stmtHandle, ref IntPtr numParams);
122 [DllImport("db2cli")]
123 internal static extern short SQLBindParameter(IntPtr stmtHandle, ushort paramNumber,
124 short dataType, short valueType, short paramType, uint colSize, short decDigits,
125 IntPtr dataBufferPtr, int dataBufferLength, IntPtr StrLen_or_IndPtr);
127 [DllImport("db2cli")]
128 internal static extern short SQLBindParameter(IntPtr stmtHandle, ushort paramNumber,
129 short dataType, short valueType, short paramType, uint colSize, short decDigits,
130 byte[] dataBufferPtr, int dataBufferLength, IntPtr StrLen_or_IndPtr);
132 [DllImport("db2cli", EntryPoint = "SQLBindParameter")]
133 internal static extern short SQLBindParameter(IntPtr stmtHandle, ushort paramNumber,
134 short dataType, short valueType, short paramType, uint colSize, short decDigits,
135 ref int dataBufferPtr, int dataBufferLength, IntPtr StrLen_or_IndPtr);
137 [DllImport("db2cli", EntryPoint = "SQLBindParameter")]
138 internal static extern short SQLBindParameter(IntPtr stmtHandle, ushort paramNumber,
139 short dataType, short valueType, short paramType, uint colSize, short decDigits,
140 ref double dataBufferPtr, int dataBufferLength, IntPtr StrLen_or_IndPtr);
142 [DllImport("db2cli", EntryPoint = "SQLDescribeParam")]
143 internal static extern short SQLDescribeParam(IntPtr stmtHandle, short ParameterNumber, IntPtr DataTypePtr, IntPtr ParameterSizePtr, IntPtr DecimalDigitsPtr, IntPtr NullablePtr);
145 [DllImport("db2cli", EntryPoint = "SQLGetLength")]
146 internal static extern short SQLGetLength( IntPtr stmtHandle, short locatorCType, int Locator,
147 IntPtr stringLength, IntPtr indicatorValue);
148 [DllImport("db2cli", EntryPoint = "SQLGetPosition")]
149 internal static extern short SQLGetPosition(IntPtr stmtHandle, short locatorCType, int sourceLocator, int searchLocator,
150 string searchLiteral, int searchLiteralLength, uint fromPosition, IntPtr locatedAt, IntPtr indicatorValue);
151 [DllImport("db2cli", EntryPoint = "SQLGetPosition")]
152 internal static extern short SQLBindFileToCol (IntPtr stmtHandle, ushort colNum, string fileName, IntPtr fileNameLength,
153 IntPtr fileOptions, short maxFileNameLength, IntPtr stringLength, IntPtr indicatorValue);
154 [DllImport("db2cli", EntryPoint = "SQLGetPosition")]
155 internal static extern short SQLBindFileToParam (IntPtr stmtHandle, ushort targetType, short dataType, string fileName,
156 IntPtr fileNameLength, short maxFileNameLength, IntPtr indicatorValue);
162 internal class DB2CLIWrapper
164 static bool useLibCli;
166 static public short Initialize(ref IntPtr pEnvHandle)
168 string OSVersion = Environment.OSVersion.ToString();
170 if(OSVersion.Substring(0,4)=="Unix"){
173 return DB2CLIWrapper.SQLAllocHandle(DB2Constants.SQL_HANDLE_ENV, IntPtr.Zero, out pEnvHandle);
176 static public short SQLAllocHandle(short handleType, IntPtr inputHandle, out IntPtr outputHandle)
179 return StaticWrapperCli.SQLAllocHandle(handleType, inputHandle, out outputHandle);
180 return StaticWrapper36.SQLAllocHandle(handleType, inputHandle, out outputHandle);
182 static public short SQLFreeHandle(short handleType, IntPtr inputHandle)
185 return StaticWrapperCli.SQLFreeHandle(handleType, inputHandle);
186 return StaticWrapper36.SQLFreeHandle(handleType, inputHandle);
188 static public short SQLFreeStmt(IntPtr StatementHandle, short option)
191 return StaticWrapperCli.SQLFreeStmt(StatementHandle, option);
192 return StaticWrapper36.SQLFreeStmt(StatementHandle, option);
194 static public short SQLConnect(IntPtr sqlHdbc, string serverName, short serverNameLength, string userName, short userNameLength, string authentication, short authenticationLength)
197 return StaticWrapperCli.SQLConnect(sqlHdbc, serverName, serverNameLength, userName, userNameLength, authentication, authenticationLength);
198 return StaticWrapper36.SQLConnect(sqlHdbc, serverName, serverNameLength, userName, userNameLength, authentication, authenticationLength);
200 static public short SQLColAttribute(IntPtr StatementHandle, short ColumnNumber, short FieldIdentifier, StringBuilder CharacterAttribute, short BufferLength, out short StringLength, out int NumericAttribute)
203 return StaticWrapperCli.SQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, out StringLength, out NumericAttribute);
204 return StaticWrapper36.SQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, out StringLength, out NumericAttribute);
206 static public short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, IntPtr ValuePtr, int BufferLength, out int StringLengthPtr)
209 return StaticWrapperCli.SQLGetConnectAttr(ConnectionHandle, Attribute, ValuePtr, BufferLength, out StringLengthPtr);
210 return StaticWrapper36.SQLGetConnectAttr(ConnectionHandle, Attribute, ValuePtr, BufferLength, out StringLengthPtr);
212 static public short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, out int Value, int BufferLength, IntPtr Zero)
215 return StaticWrapperCli.SQLGetConnectAttr(ConnectionHandle, Attribute, out Value, BufferLength, Zero);
216 return StaticWrapper36.SQLGetConnectAttr(ConnectionHandle, Attribute, out Value, BufferLength, Zero);
218 static public short SQLColAttribute(IntPtr StatementHandle, short ColumnNumber, short FieldIdentifier, IntPtr CharacterAttribute, short BufferLength, ref short StringLength, ref int NumericAttribute)
221 return StaticWrapperCli.SQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, ref StringLength, ref NumericAttribute);
222 return StaticWrapper36.SQLColAttribute(StatementHandle, ColumnNumber, FieldIdentifier, CharacterAttribute, BufferLength, ref StringLength, ref NumericAttribute);
224 static public short SQLMoreResults(IntPtr StatementHandle)
227 return StaticWrapperCli.SQLMoreResults(StatementHandle);
228 return StaticWrapper36.SQLMoreResults(StatementHandle);
230 static public short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, StringBuilder sb, int BufferLength, out int StrLen_or_Ind)
233 return StaticWrapperCli.SQLGetData(StatementHandle, ColumnNumber, TargetType, sb, BufferLength, out StrLen_or_Ind);
234 return StaticWrapper36.SQLGetData(StatementHandle, ColumnNumber, TargetType, sb, BufferLength, out StrLen_or_Ind);
236 static public short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, IntPtr TargetPtr, int BufferLength, out int StrLen_or_Ind)
239 return StaticWrapperCli.SQLGetData(StatementHandle, ColumnNumber, TargetType, TargetPtr, BufferLength, out StrLen_or_Ind);
240 return StaticWrapper36.SQLGetData(StatementHandle, ColumnNumber, TargetType, TargetPtr, BufferLength, out StrLen_or_Ind);
242 static public short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, byte[] TargetPtr, int BufferLength, out int StrLen_or_Ind)
245 return StaticWrapperCli.SQLGetData(StatementHandle, ColumnNumber, TargetType, TargetPtr, BufferLength, out StrLen_or_Ind);
246 return StaticWrapper36.SQLGetData(StatementHandle, ColumnNumber, TargetType, TargetPtr, BufferLength, out StrLen_or_Ind);
248 static public short SQLDisconnect(IntPtr sqlHdbc)
251 return StaticWrapperCli.SQLDisconnect(sqlHdbc);
252 return StaticWrapper36.SQLDisconnect(sqlHdbc);
254 static public short SQLGetDiagRec( short handleType, IntPtr handle, short recNum, StringBuilder sqlState, out int nativeError, StringBuilder errorMessage, int bufferLength, out short textLengthPtr)
257 return StaticWrapperCli.SQLGetDiagRec( handleType, handle, recNum, sqlState, out nativeError, errorMessage, bufferLength, out textLengthPtr);
258 return StaticWrapper36.SQLGetDiagRec( handleType, handle, recNum, sqlState, out nativeError, errorMessage, bufferLength, out textLengthPtr);
260 static public short SQLSetConnectAttr(IntPtr sqlHdbc, int sqlAttr, IntPtr sqlValuePtr, int sqlValueLength)
263 return StaticWrapperCli.SQLSetConnectAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
264 return StaticWrapper36.SQLSetConnectAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
266 static public short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, IntPtr sqlValuePtr, int sqlValueLength)
269 return StaticWrapperCli.SQLSetStmtAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
270 return StaticWrapper36.SQLSetStmtAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
273 //for bulk operations
274 static public short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, ushort[] sqlValuePtr, int sqlValueLength)
277 return StaticWrapperCli.SQLSetStmtAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
278 return StaticWrapper36.SQLSetStmtAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
281 static public short SQLEndTran (short handleType, IntPtr handle, short fType)
284 return StaticWrapperCli.SQLEndTran (handleType, handle, fType);
285 return StaticWrapper36.SQLEndTran (handleType, handle, fType);
287 static public short SQLCancel(IntPtr handle)
290 return StaticWrapperCli.SQLCancel(handle);
291 return StaticWrapper36.SQLCancel(handle);
293 static public short SQLNumResultCols(IntPtr handle, out short numCols)
296 return StaticWrapperCli.SQLNumResultCols(handle, out numCols);
297 return StaticWrapper36.SQLNumResultCols(handle, out numCols);
299 static public short SQLFetch(IntPtr handle)
302 return StaticWrapperCli.SQLFetch(handle);
303 return StaticWrapper36.SQLFetch(handle);
305 static public short SQLRowCount(IntPtr stmtHandle, out int numRows)
308 return StaticWrapperCli.SQLRowCount(stmtHandle, out numRows);
309 return StaticWrapper36.SQLRowCount(stmtHandle, out numRows);
311 static public short SQLExecute(IntPtr handle)
314 return StaticWrapperCli.SQLExecute(handle);
315 return StaticWrapper36.SQLExecute(handle);
317 static public short SQLExecDirect(IntPtr stmtHandle, string stmt, int length)
320 return StaticWrapperCli.SQLExecDirect(stmtHandle, stmt, length);
321 return StaticWrapper36.SQLExecDirect(stmtHandle, stmt, length);
323 static public short SQLDriverConnect(IntPtr hdbc, IntPtr windowHandle, string inConnectStr, short inStrLength, StringBuilder outConnectStr, short outStrCapacity, out short outStrLengthReturned, int completion)
326 return StaticWrapperCli.SQLDriverConnect(hdbc, windowHandle, inConnectStr, inStrLength, outConnectStr, outStrCapacity, out outStrLengthReturned, completion);
327 return StaticWrapper36.SQLDriverConnect(hdbc, windowHandle, inConnectStr, inStrLength, outConnectStr, outStrCapacity, out outStrLengthReturned, completion);
329 static public short SQLPrepare(IntPtr stmtHandle, string stmt, int length)
332 return StaticWrapperCli.SQLPrepare(stmtHandle, stmt, length);
333 return StaticWrapper36.SQLPrepare(stmtHandle, stmt, length);
335 static public short SQLBindParameter(IntPtr stmtHandle, short paramNumber, short dataType, short valueType, short paramType, int colSize, short decDigits, IntPtr dataBufferPtr, int dataBufferLength, IntPtr StrLen_or_IndPtr)
338 return StaticWrapperCli.SQLBindParameter(stmtHandle, paramNumber, dataType, valueType, paramType, colSize, decDigits, dataBufferPtr, dataBufferLength, StrLen_or_IndPtr);
339 return StaticWrapper36.SQLBindParameter(stmtHandle, paramNumber, dataType, valueType, paramType, colSize, decDigits, dataBufferPtr, dataBufferLength, StrLen_or_IndPtr);
342 static public short SQLBindParameter(IntPtr stmtHandle, short paramNumber, short dataType, short valueType, short paramType, int colSize, short decDigits, int[] dataBufferPtr, int dataBufferLength, IntPtr StrLen_or_IndPtr)
345 return StaticWrapperCli.SQLBindParameter(stmtHandle, paramNumber, dataType, valueType, paramType, colSize, decDigits, dataBufferPtr, dataBufferLength, StrLen_or_IndPtr);
346 return StaticWrapper36.SQLBindParameter(stmtHandle, paramNumber, dataType, valueType, paramType, colSize, decDigits, dataBufferPtr, dataBufferLength, StrLen_or_IndPtr);
348 public static short SQLGetInfo(IntPtr sqlHdbc, short fInfoType, [Out] StringBuilder rgbInfoValue, short cbInfoValueMax, out short pcbInfoValue)
351 return StaticWrapperCli.SQLGetInfo(sqlHdbc, fInfoType, rgbInfoValue, cbInfoValueMax, out pcbInfoValue);
352 return StaticWrapper36.SQLGetInfo(sqlHdbc, fInfoType, rgbInfoValue, cbInfoValueMax, out pcbInfoValue);
356 /// db2Prototypes class is a wrapper for the db2.lib, IBM's Call Level Interface to Db2
358 public class StaticWrapperCli
360 private const string libname = "db2cli";
362 [DllImport(libname, EntryPoint = "SQLAllocHandle")]
363 public static extern short SQLAllocHandle(short handleType, IntPtr inputHandle, out IntPtr outputHandle);
364 [DllImport(libname, EntryPoint = "SQLFreeHandle")]
365 public static extern short SQLFreeHandle(short handleType, IntPtr inputHandle);
367 [DllImport(libname, EntryPoint = "SQLFreeStmt")]
368 public static extern short SQLFreeStmt(IntPtr StatementHandle, short option);
370 [DllImport(libname, EntryPoint = "SQLConnectW", CharSet=CharSet.Unicode)]
372 public static extern short SQLConnect(IntPtr sqlHdbc, string serverName, short serverNameLength, string userName, short userNameLength, string authentication, short authenticationLength);
373 [DllImport(libname, EntryPoint = "SQLColAttributeW", CharSet=CharSet.Unicode)]
374 public static extern short SQLColAttribute(IntPtr StatementHandle, short ColumnNumber, short FieldIdentifier, [Out] StringBuilder CharacterAttribute, short BufferLength, out short StringLength, out int NumericAttribute);
376 [DllImport(libname, EntryPoint = "SQLGetConnectAttrW", CharSet=CharSet.Unicode)]
377 public static extern short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, [Out] IntPtr ValuePtr, int BufferLength, out int StringLengthPtr);
379 [DllImport(libname, EntryPoint = "SQLGetConnectAttrW", CharSet=CharSet.Unicode)]
380 public static extern short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, out int Value, int BufferLength, IntPtr Zero);
382 [DllImport(libname, EntryPoint = "SQLColAttributeW", CharSet=CharSet.Unicode)]
383 public static extern short SQLColAttribute(IntPtr StatementHandle, short ColumnNumber, short FieldIdentifier, IntPtr CharacterAttribute, short BufferLength, ref short StringLength, ref int NumericAttribute);
384 [DllImport(libname, EntryPoint="SQLMoreResults")]
385 public static extern short SQLMoreResults(IntPtr StatementHandle);
387 [DllImport(libname, EntryPoint = "SQLGetData")]
388 public static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, [Out] StringBuilder sb, int BufferLength, out int StrLen_or_Ind);
390 [DllImport(libname, EntryPoint = "SQLGetData")]
391 public static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, IntPtr TargetPtr, int BufferLength, out int StrLen_or_Ind);
393 [DllImport(libname, EntryPoint = "SQLGetData")]
394 public static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, [Out] byte[] TargetPtr, int BufferLength, out int StrLen_or_Ind);
396 [DllImport(libname, EntryPoint = "SQLDisconnect")]
397 public static extern short SQLDisconnect(IntPtr sqlHdbc);
399 [DllImport(libname, EntryPoint = "SQLGetDiagRec")]
400 public static extern short SQLGetDiagRec( short handleType, IntPtr handle, short recNum, [Out] StringBuilder sqlState, out int nativeError, [Out] StringBuilder errorMessage, int bufferLength, out short textLengthPtr);
402 [DllImport(libname, EntryPoint = "SQLSetConnectAttr")]
403 public static extern short SQLSetConnectAttr(IntPtr sqlHdbc, int sqlAttr, [In] IntPtr sqlValuePtr, int sqlValueLength);
405 [DllImport(libname, EntryPoint = "SQLSetStmtAttr")]
406 public static extern short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, [In] IntPtr sqlValuePtr, int sqlValueLength);
408 //For bulk operations
409 [DllImport(libname, EntryPoint = "SQLSetStmtAttr")]
410 public static extern short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, ushort[] sqlValuePtr, int sqlValueLength);
412 [DllImport(libname, EntryPoint = "SQLEndTran")]
413 public static extern short SQLEndTran (short handleType, IntPtr handle, short fType);
414 [DllImport(libname, EntryPoint = "SQLCancel")]
415 public static extern short SQLCancel(IntPtr handle);
416 [DllImport(libname, EntryPoint = "SQLNumResultCols")]
417 public static extern short SQLNumResultCols(IntPtr handle, out short numCols);
418 [DllImport(libname, EntryPoint = "SQLFetch")]
419 public static extern short SQLFetch(IntPtr handle);
420 [DllImport(libname, EntryPoint = "SQLRowCount")]
421 public static extern short SQLRowCount(IntPtr stmtHandle, out int numRows);
422 [DllImport(libname, EntryPoint = "SQLExecute")]
423 public static extern short SQLExecute(IntPtr handle);
424 [DllImport (libname, EntryPoint = "SQLExecDirectW", CharSet=CharSet.Unicode)]
425 public static extern short SQLExecDirect(IntPtr stmtHandle, string stmt, int length);
426 [DllImport(libname, EntryPoint = "SQLDriverConnectW", CharSet=CharSet.Unicode)]
427 public static extern short SQLDriverConnect(IntPtr hdbc, IntPtr windowHandle, [In] string inConnectStr, [In] short inStrLength, [Out] StringBuilder outConnectStr, [Out] short outStrCapacity, out short outStrLengthReturned, [In] int completion);
428 [DllImport(libname, EntryPoint = "SQLPrepareW", CharSet=CharSet.Unicode)]
429 public static extern short SQLPrepare(IntPtr stmtHandle, string stmt, int length);
431 public static extern short SQLBindParameter(IntPtr stmtHandle, short paramNumber,
432 short dataType, short valueType, short paramType, int colSize, short decDigits,
433 IntPtr dataBufferPtr, int dataBufferLength, IntPtr StrLen_or_IndPtr);
436 public static extern short SQLBindParameter(IntPtr stmtHandle, short paramNumber,
437 short dataType, short valueType, short paramType, int colSize, short decDigits,
438 int[] dataBufferPtr, int dataBufferLength, IntPtr StrLen_or_IndPtr);
440 [DllImport(libname, EntryPoint = "SQLGetInfoW", CharSet=CharSet.Unicode)]
441 public static extern short SQLGetInfo(IntPtr sqlHdbc, short fInfoType, [Out] StringBuilder rgbInfoValue, short cbInfoValueMax, out short pcbInfoValue);
444 public class StaticWrapper36
446 private const string libname = "db2_36";
448 [DllImport(libname, EntryPoint = "SQLAllocHandle")]
449 public static extern short SQLAllocHandle(short handleType, IntPtr inputHandle, out IntPtr outputHandle);
450 [DllImport(libname, EntryPoint = "SQLFreeHandle")]
451 public static extern short SQLFreeHandle(short handleType, IntPtr inputHandle);
453 [DllImport(libname, EntryPoint = "SQLFreeStmt")]
454 public static extern short SQLFreeStmt(IntPtr StatementHandle, short option);
456 [DllImport(libname, EntryPoint = "SQLConnect", CharSet=CharSet.Ansi)]
458 public static extern short SQLConnect(IntPtr sqlHdbc, string serverName, short serverNameLength, string userName, short userNameLength, string authentication, short authenticationLength);
459 [DllImport(libname, EntryPoint = "SQLColAttributeW", CharSet=CharSet.Unicode)]
460 public static extern short SQLColAttribute(IntPtr StatementHandle, short ColumnNumber, short FieldIdentifier, [Out] StringBuilder CharacterAttribute, short BufferLength, out short StringLength, out int NumericAttribute);
462 [DllImport(libname, EntryPoint = "SQLGetConnectAttrW", CharSet=CharSet.Unicode)]
463 public static extern short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, [Out] IntPtr ValuePtr, int BufferLength, out int StringLengthPtr);
465 [DllImport(libname, EntryPoint = "SQLGetConnectAttrW", CharSet=CharSet.Unicode)]
466 public static extern short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, out int Value, int BufferLength, IntPtr Zero);
468 [DllImport(libname, EntryPoint = "SQLColAttributeW", CharSet=CharSet.Unicode)]
469 public static extern short SQLColAttribute(IntPtr StatementHandle, short ColumnNumber, short FieldIdentifier, IntPtr CharacterAttribute, short BufferLength, ref short StringLength, ref int NumericAttribute);
470 [DllImport(libname, EntryPoint="SQLMoreResults")]
471 public static extern short SQLMoreResults(IntPtr StatementHandle);
473 [DllImport(libname, EntryPoint = "SQLGetData")]
474 public static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, [Out] StringBuilder sb, int BufferLength, out int StrLen_or_Ind);
476 [DllImport(libname, EntryPoint = "SQLGetData")]
477 public static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, IntPtr TargetPtr, int BufferLength, out int StrLen_or_Ind);
479 [DllImport(libname, EntryPoint = "SQLGetData")]
480 public static extern short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, [Out] byte[] TargetPtr, int BufferLength, out int StrLen_or_Ind);
482 [DllImport(libname, EntryPoint = "SQLDisconnect")]
483 public static extern short SQLDisconnect(IntPtr sqlHdbc);
485 [DllImport(libname, EntryPoint = "SQLGetDiagRec")]
486 public static extern short SQLGetDiagRec( short handleType, IntPtr handle, short recNum, [Out] StringBuilder sqlState, out int nativeError, [Out] StringBuilder errorMessage, int bufferLength, out short textLengthPtr);
488 [DllImport(libname, EntryPoint = "SQLSetConnectAttr")]
489 public static extern short SQLSetConnectAttr(IntPtr sqlHdbc, int sqlAttr, [In] IntPtr sqlValuePtr, int sqlValueLength);
490 [DllImport(libname, EntryPoint = "SQLSetStmtAttr")]
491 public static extern short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, [In] IntPtr sqlValuePtr, int sqlValueLength);
493 //for bulk operations
494 [DllImport(libname, EntryPoint = "SQLSetStmtAttr")]
495 public static extern short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, ushort[] sqlValuePtr, int sqlValueLength);
497 [DllImport(libname, EntryPoint = "SQLEndTran")]
498 public static extern short SQLEndTran (short handleType, IntPtr handle, short fType);
499 [DllImport(libname, EntryPoint = "SQLCancel")]
500 public static extern short SQLCancel(IntPtr handle);
501 [DllImport(libname, EntryPoint = "SQLNumResultCols")]
502 public static extern short SQLNumResultCols(IntPtr handle, out short numCols);
503 [DllImport(libname, EntryPoint = "SQLFetch")]
504 public static extern short SQLFetch(IntPtr handle);
505 [DllImport(libname, EntryPoint = "SQLRowCount")]
506 public static extern short SQLRowCount(IntPtr stmtHandle, out int numRows);
507 [DllImport(libname, EntryPoint = "SQLExecute")]
508 public static extern short SQLExecute(IntPtr handle);
509 [DllImport (libname, EntryPoint = "SQLExecDirectW", CharSet=CharSet.Unicode)]
510 public static extern short SQLExecDirect(IntPtr stmtHandle, string stmt, int length);
511 [DllImport(libname, EntryPoint = "SQLDriverConnectW", CharSet=CharSet.Unicode)]
512 public static extern short SQLDriverConnect(IntPtr hdbc, IntPtr windowHandle, [In] string inConnectStr, [In] short inStrLength, [Out] StringBuilder outConnectStr, [Out] short outStrCapacity, out short outStrLengthReturned, [In] int completion);
513 [DllImport(libname, EntryPoint = "SQLPrepareW", CharSet=CharSet.Unicode)]
514 public static extern short SQLPrepare(IntPtr stmtHandle, string stmt, int length);
516 public static extern short SQLBindParameter(IntPtr stmtHandle, short paramNumber,
517 short dataType, short valueType, short paramType, int colSize, short decDigits,
518 IntPtr dataBufferPtr, int dataBufferLength, IntPtr StrLen_or_IndPtr);
521 public static extern short SQLBindParameter(IntPtr stmtHandle, short paramNumber,
522 short dataType, short valueType, short paramType, int colSize, short decDigits,
523 int[] dataBufferPtr, int dataBufferLength, IntPtr StrLen_or_IndPtr);
525 [DllImport(libname, EntryPoint = "SQLGetInfoW", CharSet=CharSet.Unicode)]
526 public static extern short SQLGetInfo(IntPtr sqlHdbc, short fInfoType, [Out] StringBuilder rgbInfoValue, short cbInfoValueMax, out short pcbInfoValue);