2 // System.Data.Odbc.libodbc
5 // Brian Ritchie (brianlritchie@hotmail.com)
6 // Sureshkumar T (tsureshkumar@novell.com)
8 // Copyright (C) Brian Ritchie, 2002
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Data.Common;
34 using System.Runtime.InteropServices;
36 namespace System.Data.Odbc
38 internal enum OdbcHandleType : short
46 internal enum OdbcReturn : short
57 internal enum OdbcEnv : ushort
60 ConnectionPooling = 201,
64 internal enum OdbcConnectionAttribute : int
67 TransactionIsolation = 108,
70 CoptTransactionIsolation = 1227 /* SQL_COPT_SS_TXN_ISOLATION */
74 internal enum OdbcInfo : ushort
83 internal enum OdbcInputOutputDirection : short
92 internal enum OdbcIsolationLevel
98 Snapshot = 32 /* SQL_TXN_SS_SNAPSHOT */
101 internal enum OdbcLengthIndicator : short
108 internal enum FieldIdentifier : short
110 AutoUniqueValue = 11, /* SQL_DESC_AUTO_UNIQUE_VALUE */
111 BaseColumnName = 22, /* SQL_DESC_BASE_COLUMN_NAME */
112 BaseTableName = 23, /* SQL_DESC_BASE_TABLE_NAME */
113 CaseSensitive = 12, /* SQL_DESC_CASE_SENSITIVE */
114 CatelogName = 17, /* SQL_DESC_CATALOG_NAME */
115 ConsiseType = 2, /* SQL_DESC_CONCISE_TYPE */
116 Count = 1001, /* SQL_DESC_COUNT */
117 DisplaySize = 6, /* SQL_DESC_DISPLAY_SIZE */
118 FixedPrecScale = 9, /* SQL_DESC_FIXED_PREC_SCALE */
119 Label = 18, /* SQL_DESC_LABEL */
120 Length = 1003, /* SQL_DESC_LENGTH */
121 LiteralPrefix = 27, /* SQL_DESC_LITERAL_PREFIX */
122 LiteralSuffix = 28, /* SQL_DESC_LITERAL_SUFFIX */
123 LocalTypeName = 29, /* SQL_DESC_LOCAL_TYPE_NAME */
124 Name = 1011, /* SQL_DESC_NAME */
125 Nullable = 1008, /* SQL_DESC_NULLABLE */
126 NumPrecRadix = 32, /* SQL_DESC_NUM_PREC_RADIX */
127 OctetLength = 1013, /* SQL_DESC_OCTET_LENGTH */
128 Precision = 1005, /* SQL_DESC_PRECISION */
129 Scale = 1006, /* SQL_DESC_SCALE */
130 SchemaName = 16, /* SQL_DESC_SCHEMA_NAME */
131 Searchable = 13, /* SQL_DESC_SEARCHABLE */
132 TableName = 15, /* SQL_DESC_TABLE_NAME */
133 Type = 1002, /* SQL_DESC_TYPE */
134 TypeName = 14, /* SQL_DESC_TYPE_NAME */
135 Unnamed = 1012, /* SQL_DESC_UNNAMED */
136 Unsigned = 8, /* SQL_DESC_UNSIGNED */
137 Updatable = 10 /* SQL_DESC_UPDATABLE */
140 [StructLayout(LayoutKind.Sequential)]
141 internal struct OdbcTimestamp
144 internal ushort month;
146 internal ushort hour;
147 internal ushort minute;
148 internal ushort second;
149 internal ulong fraction;
152 internal class libodbc
154 #region global constants
155 internal const int SQL_OV_ODBC2 = 2;
156 internal const int SQL_OV_ODBC3 = 3;
158 internal const string SQLSTATE_RIGHT_TRUNC = "01004";
159 internal const char C_NULL = '\0';
160 internal const int SQL_NTS = -3;
162 internal const short SQL_TRUE = 1;
163 internal const short SQL_FALSE = 0;
166 internal const short SQL_INDEX_UNIQUE = 0;
167 internal const short SQL_INDEX_ALL = 1;
168 internal const short SQL_QUICK = 0;
169 internal const short SQL_ENSURE = 1;
171 // SQLColumnAttribute
172 internal const short SQL_NO_NULLS = 0;
173 internal const short SQL_NULLABLE = 1;
174 internal const short SQL_NULLABLE_UNKNOWN = 2;
175 internal const short SQL_ATTR_READONLY = 0;
176 internal const short SQL_ATTR_WRITE = 1;
177 internal const short SQL_ATTR_READWRITE_UNKNOWN = 2;
180 internal static OdbcInputOutputDirection ConvertParameterDirection(
181 ParameterDirection dir)
184 case ParameterDirection.Input:
185 return OdbcInputOutputDirection.Input;
186 case ParameterDirection.InputOutput:
187 return OdbcInputOutputDirection.InputOutput;
188 case ParameterDirection.Output:
189 return OdbcInputOutputDirection.Output;
190 case ParameterDirection.ReturnValue:
191 return OdbcInputOutputDirection.ReturnValue;
193 return OdbcInputOutputDirection.Input;
197 [DllImport("odbc32.dll")]
198 internal static extern OdbcReturn SQLAllocHandle (
199 OdbcHandleType HandleType,
201 ref IntPtr OutputHandlePtr);
203 [DllImport("odbc32.dll")]
204 internal static extern OdbcReturn SQLSetEnvAttr (
210 [DllImport("odbc32.dll")]
211 internal static extern OdbcReturn SQLConnect (
212 IntPtr ConnectionHandle,
217 string Authentication,
220 [DllImport("odbc32.dll")]
221 internal static extern OdbcReturn SQLDriverConnect (
222 IntPtr ConnectionHandle,
224 string InConnectionString,
226 string OutConnectionString,
228 ref short StringLength2Ptr,
229 ushort DriverCompletion);
231 [DllImport("odbc32.dll")]
232 internal static extern OdbcReturn SQLExecDirect (
233 IntPtr StatementHandle,
234 string StatementText,
237 [DllImport("odbc32.dll")]
238 internal static extern OdbcReturn SQLRowCount (
239 IntPtr StatementHandle,
242 [DllImport("odbc32.dll")]
243 internal static extern OdbcReturn SQLNumResultCols (
244 IntPtr StatementHandle,
245 ref short ColumnCount);
247 [DllImport("odbc32.dll")]
248 internal static extern OdbcReturn SQLFetch (
249 IntPtr StatementHandle);
251 [DllImport("odbc32.dll")]
252 internal static extern OdbcReturn SQLGetData (
253 IntPtr StatementHandle,
255 SQL_C_TYPE TargetType,
260 [DllImport("odbc32.dll")]
261 internal static extern OdbcReturn SQLGetData (
262 IntPtr StatementHandle,
264 SQL_C_TYPE TargetType,
265 ref double TargetPtr,
269 [DllImport("odbc32.dll")]
270 internal static extern OdbcReturn SQLGetData (
271 IntPtr StatementHandle,
273 SQL_C_TYPE TargetType,
278 [DllImport("odbc32.dll")]
279 internal static extern OdbcReturn SQLGetData (
280 IntPtr StatementHandle,
282 SQL_C_TYPE TargetType,
287 [DllImport("odbc32.dll")]
288 internal static extern OdbcReturn SQLGetData (
289 IntPtr StatementHandle,
291 SQL_C_TYPE TargetType,
296 [DllImport("odbc32.dll")]
297 internal static extern OdbcReturn SQLGetData (
298 IntPtr StatementHandle,
300 SQL_C_TYPE TargetType,
301 ref OdbcTimestamp TargetPtr,
305 [DllImport("odbc32.dll")]
306 internal static extern OdbcReturn SQLGetData (
307 IntPtr StatementHandle,
309 SQL_C_TYPE TargetType,
314 [DllImport("odbc32.dll")]
315 internal static extern OdbcReturn SQLGetData (
316 IntPtr StatementHandle,
318 SQL_C_TYPE TargetType,
323 [DllImport("odbc32.dll")]
324 internal static extern OdbcReturn SQLDescribeCol (
325 IntPtr StatementHandle,
329 ref short NameLength,
332 ref short DecimalDigits,
335 [DllImport("odbc32.dll")]
336 internal static extern OdbcReturn SQLFreeHandle (
340 [DllImport("odbc32.dll")]
341 internal static extern OdbcReturn SQLDisconnect (
342 IntPtr ConnectionHandle);
344 [DllImport("odbc32.dll")]
345 internal static extern OdbcReturn SQLPrepare (
346 IntPtr StatementHandle,
350 [DllImport("odbc32.dll")]
351 internal static extern OdbcReturn SQLExecute (
352 IntPtr StatementHandle);
354 [DllImport ("odbc32.dll")]
355 internal static extern OdbcReturn SQLGetConnectAttr (
356 IntPtr ConnectionHandle,
357 OdbcConnectionAttribute Attribute,
360 out int StringLength);
362 [DllImport("odbc32.dll")]
363 internal static extern OdbcReturn SQLSetConnectAttr (
364 IntPtr ConnectionHandle,
365 OdbcConnectionAttribute Attribute,
369 [DllImport("odbc32.dll")]
370 internal static extern OdbcReturn SQLEndTran (
373 short CompletionType);
375 [DllImport("odbc32.dll")]
376 internal static extern OdbcReturn SQLBindParameter (
377 IntPtr StatementHandle,
379 short InputOutputType,
380 SQL_C_TYPE ValueType,
388 [DllImport("odbc32.dll")]
389 internal static extern OdbcReturn SQLCancel (
390 IntPtr StatementHandle);
392 [DllImport("odbc32.dll")]
393 internal static extern OdbcReturn SQLCloseCursor (
394 IntPtr StatementHandle);
396 [DllImport("odbc32.dll")]
397 internal static extern OdbcReturn SQLError (
398 IntPtr EnvironmentHandle,
399 IntPtr ConnectionHandle,
400 IntPtr StatementHandle,
405 ref short TextLength);
407 [DllImport("odbc32.dll")]
408 internal static extern OdbcReturn SQLGetStmtAttr (
409 IntPtr StatementHandle,
415 [DllImport("odbc32.dll")]
416 internal static extern OdbcReturn SQLSetDescField (
417 IntPtr DescriptorHandle,
419 short FieldIdentifier,
423 [DllImport("odbc32.dll")]
424 internal static extern OdbcReturn SQLGetDiagRec (
425 OdbcHandleType HandleType,
432 ref short TextLength);
434 [DllImport ("odbc32.dll")]
435 internal static extern OdbcReturn SQLMoreResults (
438 internal enum SQLFreeStmtOptions : short
446 [DllImport ("odbc32.dll")]
447 internal static extern OdbcReturn SQLFreeStmt (
449 SQLFreeStmtOptions option);
451 [DllImport ("odbc32.dll")]
452 internal static extern OdbcReturn SQLGetInfo (
457 ref short remainingStrLen);
459 [DllImport ("odbc32.dll")]
460 internal static extern OdbcReturn SQLColAttribute (
463 FieldIdentifier fieldId,
464 byte [] charAttributePtr,
466 ref short strLengthPtr,
467 ref int numericAttributePtr);
469 [DllImport ("odbc32.dll")]
470 internal static extern OdbcReturn SQLPrimaryKeys (
479 [DllImport ("odbc32.dll")]
480 internal static extern OdbcReturn SQLStatistics (
491 [DllImport ("odbc32.dll")]
492 internal static extern OdbcReturn SQLBindCol (
495 SQL_C_TYPE targetType,
500 [DllImport ("odbc32.dll")]
501 internal static extern OdbcReturn SQLBindCol (
504 SQL_C_TYPE targetType,