Add licensing info
[mono.git] / mcs / class / IBM.Data.DB2 / IBM.Data.DB2 / DB2CLIWrapper.cs
1
2 //
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:
10 // 
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 // 
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.
21 //
22 using System;
23 using System.Data;
24 using System.Runtime.InteropServices;
25 using System.Text;
26
27 namespace IBM.Data.DB2
28 {
29         /// <summary>
30         /// DB2Prototypes class is a wrapper for the DB2.lib, IBM's Call Level Interface to DB2
31         /// </summary>
32         /// 
33         #region comented
34         /*internal class DB2CLIWrapper
35         {
36                 
37                 #if (OS_LINUX)
38                         private const string libname = "db2_36";
39                 #endif
40                 
41                 #if (OS_WINDOWS)
42                         private const string libname = "db2cli";
43                 #endif
44                 
45                 [DllImport("db2cli", EntryPoint = "SQLAllocHandle")]
46                         internal static extern short SQLAllocHandle(short handleType, IntPtr inputHandle,  ref IntPtr outputHandle);
47
48                 [DllImport("db2cli", EntryPoint = "SQLFreeHandle")]
49                 internal static extern short SQLFreeHandle(short handleType, IntPtr inputHandle);
50
51                 [DllImport("db2cli", EntryPoint = "SQLGetConnectAttrW")]
52                 internal static extern short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, [Out] IntPtr ValuePtr, int BufferLength, out int StringLengthPtr);
53
54                 [DllImport("db2cli", EntryPoint = "SQLGetConnectAttrW")]
55                 internal static extern short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, out int Value, int BufferLength, IntPtr Zero);
56
57                 [DllImport("db2cli", EntryPoint = "SQLFreeStmt")]
58                 internal static extern short SQLFreeStmt(IntPtr StatementHandle, short option);
59
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);
68
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);
73                 
74                         
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);
77                 
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);
80
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);
83
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);
86         
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);
121                 
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);
126                         
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);
131                                                 
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);
136         
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);
141                                 
142                 [DllImport("db2cli", EntryPoint = "SQLDescribeParam")]
143                         internal static extern short SQLDescribeParam(IntPtr stmtHandle, short ParameterNumber, IntPtr DataTypePtr, IntPtr ParameterSizePtr, IntPtr DecimalDigitsPtr, IntPtr NullablePtr); 
144                 
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); 
157                         
158
159         }*/
160         #endregion
161
162         internal class DB2CLIWrapper
163         {
164                 static bool useLibCli;
165
166                 static public short Initialize(ref IntPtr pEnvHandle)
167                 {
168                         string OSVersion = Environment.OSVersion.ToString();
169                         useLibCli = true;
170                         if(OSVersion.Substring(0,4)=="Unix"){
171                                 useLibCli = false;
172                         }
173                         return DB2CLIWrapper.SQLAllocHandle(DB2Constants.SQL_HANDLE_ENV, IntPtr.Zero, out pEnvHandle);
174                 }
175
176                 static public short SQLAllocHandle(short handleType, IntPtr inputHandle, out IntPtr outputHandle)
177                 {
178                         if(useLibCli)
179                                 return StaticWrapperCli.SQLAllocHandle(handleType, inputHandle, out outputHandle);
180                         return StaticWrapper36.SQLAllocHandle(handleType, inputHandle, out outputHandle);
181                 }
182                 static public short SQLFreeHandle(short handleType, IntPtr inputHandle)
183                 {
184                         if(useLibCli)
185                                 return StaticWrapperCli.SQLFreeHandle(handleType, inputHandle);
186                         return StaticWrapper36.SQLFreeHandle(handleType, inputHandle);
187                 }
188                 static public short SQLFreeStmt(IntPtr StatementHandle, short option)
189                 {
190                         if(useLibCli)
191                                 return StaticWrapperCli.SQLFreeStmt(StatementHandle, option);
192                         return StaticWrapper36.SQLFreeStmt(StatementHandle, option);
193                 }
194                 static public short SQLConnect(IntPtr sqlHdbc, string serverName, short serverNameLength, string userName, short userNameLength, string authentication, short authenticationLength)
195                 {
196                         if(useLibCli)
197                                 return StaticWrapperCli.SQLConnect(sqlHdbc, serverName, serverNameLength, userName, userNameLength, authentication, authenticationLength);
198                         return StaticWrapper36.SQLConnect(sqlHdbc, serverName, serverNameLength, userName, userNameLength, authentication, authenticationLength);
199                 }
200                 static public short SQLColAttribute(IntPtr StatementHandle, short ColumnNumber, short FieldIdentifier, StringBuilder CharacterAttribute, short BufferLength, out short StringLength, out int NumericAttribute)
201                 {
202                         if(useLibCli)
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);
205                 }
206                 static public short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, IntPtr ValuePtr, int BufferLength, out int StringLengthPtr)
207                 {
208                         if(useLibCli)
209                                 return StaticWrapperCli.SQLGetConnectAttr(ConnectionHandle, Attribute, ValuePtr, BufferLength, out StringLengthPtr);
210                         return StaticWrapper36.SQLGetConnectAttr(ConnectionHandle, Attribute, ValuePtr, BufferLength, out StringLengthPtr);
211                 }
212                 static public short SQLGetConnectAttr(IntPtr ConnectionHandle, int Attribute, out int Value, int BufferLength, IntPtr Zero)
213                 {
214                         if(useLibCli)
215                                 return StaticWrapperCli.SQLGetConnectAttr(ConnectionHandle, Attribute, out Value, BufferLength, Zero);
216                         return StaticWrapper36.SQLGetConnectAttr(ConnectionHandle, Attribute, out Value, BufferLength, Zero);
217                 }
218                 static public short SQLColAttribute(IntPtr StatementHandle, short ColumnNumber, short FieldIdentifier, IntPtr CharacterAttribute, short BufferLength, ref short StringLength, ref int NumericAttribute)
219                 {
220                         if(useLibCli)
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);
223                 }
224                 static public short SQLMoreResults(IntPtr StatementHandle)
225                 {
226                         if(useLibCli)
227                                 return StaticWrapperCli.SQLMoreResults(StatementHandle);
228                         return StaticWrapper36.SQLMoreResults(StatementHandle);
229                 }
230                 static public short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, StringBuilder sb, int BufferLength, out int StrLen_or_Ind)
231                 {
232                         if(useLibCli)
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);
235                 }
236                 static public short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, IntPtr TargetPtr, int BufferLength, out int StrLen_or_Ind)
237                 {
238                         if(useLibCli)
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);
241                 }
242                 static public short SQLGetData(IntPtr StatementHandle, short ColumnNumber, short TargetType, byte[] TargetPtr, int BufferLength, out int StrLen_or_Ind)
243                 {
244                         if(useLibCli)
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);
247                 }
248                 static public short SQLDisconnect(IntPtr sqlHdbc)
249                 {
250                         if(useLibCli)
251                                 return StaticWrapperCli.SQLDisconnect(sqlHdbc);
252                         return StaticWrapper36.SQLDisconnect(sqlHdbc);
253                 }
254                 static public short SQLGetDiagRec( short handleType, IntPtr handle, short recNum, StringBuilder sqlState, out int nativeError, StringBuilder errorMessage, int bufferLength, out short textLengthPtr)
255                 {
256                         if(useLibCli)
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);
259                 }
260                 static public short SQLSetConnectAttr(IntPtr sqlHdbc, int sqlAttr, IntPtr sqlValuePtr, int sqlValueLength)
261                 {
262                         if(useLibCli)
263                                 return StaticWrapperCli.SQLSetConnectAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
264                         return StaticWrapper36.SQLSetConnectAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
265                 }
266                 static public short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, IntPtr sqlValuePtr, int sqlValueLength)
267                 {
268                         if(useLibCli)
269                                 return StaticWrapperCli.SQLSetStmtAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
270                         return StaticWrapper36.SQLSetStmtAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
271                 }
272
273                 //for bulk operations
274                 static public short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, ushort[] sqlValuePtr, int sqlValueLength)
275                 {
276                         if(useLibCli)
277                                 return StaticWrapperCli.SQLSetStmtAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
278                         return StaticWrapper36.SQLSetStmtAttr(sqlHdbc, sqlAttr, sqlValuePtr, sqlValueLength);
279                 }
280
281                 static public short SQLEndTran (short handleType, IntPtr handle, short fType)
282                 {
283                         if(useLibCli)
284                                 return StaticWrapperCli.SQLEndTran (handleType, handle, fType);
285                         return StaticWrapper36.SQLEndTran (handleType, handle, fType);
286                 }
287                 static public short SQLCancel(IntPtr handle)
288                 {
289                         if(useLibCli)
290                                 return StaticWrapperCli.SQLCancel(handle);
291                         return StaticWrapper36.SQLCancel(handle);
292                 }
293                 static public short SQLNumResultCols(IntPtr handle, out short numCols)
294                 {
295                         if(useLibCli)
296                                 return StaticWrapperCli.SQLNumResultCols(handle, out numCols);
297                         return StaticWrapper36.SQLNumResultCols(handle, out numCols);
298                 }
299                 static public short SQLFetch(IntPtr handle)
300                 {
301                         if(useLibCli)
302                                 return StaticWrapperCli.SQLFetch(handle);
303                         return StaticWrapper36.SQLFetch(handle);
304                 }
305                 static public short SQLRowCount(IntPtr stmtHandle, out int numRows)
306                 {
307                         if(useLibCli)
308                                 return StaticWrapperCli.SQLRowCount(stmtHandle, out numRows);
309                         return StaticWrapper36.SQLRowCount(stmtHandle, out numRows);
310                 }
311                 static public short SQLExecute(IntPtr handle)
312                 {
313                         if(useLibCli)
314                                 return StaticWrapperCli.SQLExecute(handle);
315                         return StaticWrapper36.SQLExecute(handle);
316                 }
317                 static public short SQLExecDirect(IntPtr stmtHandle, string stmt, int length)
318                 {
319                         if(useLibCli)
320                                 return StaticWrapperCli.SQLExecDirect(stmtHandle, stmt, length);
321                         return StaticWrapper36.SQLExecDirect(stmtHandle, stmt, length);
322                 }
323                 static public short SQLDriverConnect(IntPtr hdbc, IntPtr windowHandle, string inConnectStr, short inStrLength, StringBuilder outConnectStr, short outStrCapacity, out short outStrLengthReturned, int completion)
324                 {
325                         if(useLibCli)
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);
328                 }
329                 static public short SQLPrepare(IntPtr stmtHandle, string stmt, int length)
330                 {
331                         if(useLibCli)
332                                 return StaticWrapperCli.SQLPrepare(stmtHandle, stmt, length);
333                         return StaticWrapper36.SQLPrepare(stmtHandle, stmt, length);
334                 }
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)
336                 {
337                         if(useLibCli)
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);
340                 }
341
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)
343                 {
344                         if(useLibCli)
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);
347                 }
348                 public static short SQLGetInfo(IntPtr sqlHdbc, short fInfoType, [Out] StringBuilder rgbInfoValue, short cbInfoValueMax, out short pcbInfoValue)
349                 {
350                         if(useLibCli)
351                                 return StaticWrapperCli.SQLGetInfo(sqlHdbc, fInfoType, rgbInfoValue, cbInfoValueMax, out pcbInfoValue);
352                         return StaticWrapper36.SQLGetInfo(sqlHdbc, fInfoType, rgbInfoValue, cbInfoValueMax, out pcbInfoValue);
353                 }
354
355                 /// <summary>
356                 /// db2Prototypes class is a wrapper for the db2.lib, IBM's Call Level Interface to Db2
357                 /// </summary>
358                 public class StaticWrapperCli
359                 {
360                         private const string libname = "db2cli";
361                 
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);
366
367                         [DllImport(libname, EntryPoint = "SQLFreeStmt")]
368                         public static extern short SQLFreeStmt(IntPtr StatementHandle, short option);
369
370                         [DllImport(libname, EntryPoint = "SQLConnectW", CharSet=CharSet.Unicode)]
371
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);
375
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);
378
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);
381
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);
386
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);
389
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);
392                 
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);
395
396                         [DllImport(libname,  EntryPoint = "SQLDisconnect")]
397                         public static extern short SQLDisconnect(IntPtr sqlHdbc);
398
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);
401
402                         [DllImport(libname, EntryPoint = "SQLSetConnectAttr")]
403                         public static extern short SQLSetConnectAttr(IntPtr sqlHdbc, int sqlAttr, [In] IntPtr sqlValuePtr, int sqlValueLength);
404                         
405                         [DllImport(libname, EntryPoint = "SQLSetStmtAttr")]
406                         public static extern short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, [In] IntPtr sqlValuePtr, int sqlValueLength);
407                         
408                         //For bulk operations
409                         [DllImport(libname, EntryPoint = "SQLSetStmtAttr")]
410                         public static extern short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, ushort[] sqlValuePtr, int sqlValueLength);
411
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);
430                         [DllImport(libname)]
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);
434
435                         [DllImport(libname)]
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);
439
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);
442                 }
443
444                 public class StaticWrapper36
445                 {
446                         private const string libname = "db2_36";
447                 
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);
452
453                         [DllImport(libname, EntryPoint = "SQLFreeStmt")]
454                         public static extern short SQLFreeStmt(IntPtr StatementHandle, short option);
455
456                         [DllImport(libname, EntryPoint = "SQLConnect", CharSet=CharSet.Ansi)]
457
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);
461
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);
464
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);
467
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);
472
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);
475
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);
478                 
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);
481
482                         [DllImport(libname,  EntryPoint = "SQLDisconnect")]
483                         public static extern short SQLDisconnect(IntPtr sqlHdbc);
484
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);
487
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);
492         
493                         //for bulk operations
494                         [DllImport(libname, EntryPoint = "SQLSetStmtAttr")]
495                         public static extern short SQLSetStmtAttr(IntPtr sqlHdbc, int sqlAttr, ushort[] sqlValuePtr, int sqlValueLength);
496
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);
515                         [DllImport(libname)]
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);
519
520                         [DllImport(libname)]
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);
524
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);
527
528                 }
529         }
530 }