Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSureshkumar T <suresh@mono-cvs.ximian.com>2005-01-19 12:05:15 +0300
committerSureshkumar T <suresh@mono-cvs.ximian.com>2005-01-19 12:05:15 +0300
commit0d1e0487e433a825d8f046b69609c824b2af0019 (patch)
treeef89ffda32daab48d4f7acfbe5a944c03e28b460 /mcs/class/System.Data/System.Data.Odbc
parentf8e3f2e629520381f1f5d24bf3c0115789e36bbd (diff)
2005-01-19 Sureshkumar T <tsureshkumar@novell.com>
* OdbcType.cs: Change enum values for compatiability with MS.NET. * libodbc.cs: Change enum values for compatiability with MS.NET. Change calls into driver with native type. * OdbcDataReader.cs: Change enum values for compatiability with MS.NET. Change calls from/into driver with native type. svn path=/trunk/mcs/; revision=39140
Diffstat (limited to 'mcs/class/System.Data/System.Data.Odbc')
-rw-r--r--mcs/class/System.Data/System.Data.Odbc/ChangeLog8
-rw-r--r--mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs29
-rw-r--r--mcs/class/System.Data/System.Data.Odbc/OdbcType.cs62
-rw-r--r--mcs/class/System.Data/System.Data.Odbc/libodbc.cs77
4 files changed, 133 insertions, 43 deletions
diff --git a/mcs/class/System.Data/System.Data.Odbc/ChangeLog b/mcs/class/System.Data/System.Data.Odbc/ChangeLog
index f0a70fd0fc7..7b3027eeb10 100644
--- a/mcs/class/System.Data/System.Data.Odbc/ChangeLog
+++ b/mcs/class/System.Data/System.Data.Odbc/ChangeLog
@@ -1,3 +1,11 @@
+2005-01-19 Sureshkumar T <tsureshkumar@novell.com>
+
+ * OdbcType.cs: Change enum values for compatiability with MS.NET.
+ * libodbc.cs: Change enum values for compatiability with
+ MS.NET. Change calls into driver with native type.
+ * OdbcDataReader.cs: Change enum values for compatiability with
+ MS.NET. Change calls from/into driver with native type.
+
2005-01-18 Sureshkumar T <tsureshkumar@novell.com>
* OdbcDataReader.cs: GetOrdinal need not check for
diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs
index 915e764565d..9511eb15d82 100644
--- a/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs
+++ b/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs
@@ -159,7 +159,8 @@ namespace System.Data.Odbc
throw new OdbcException(new OdbcError("SQLDescribeCol",OdbcHandleType.Stmt,hstmt));
colname=System.Text.Encoding.Default.GetString(colname_buffer);
colname=colname.Replace((char) 0,' ').Trim();
- OdbcColumn c=new OdbcColumn(colname, (OdbcType) dt);
+ OdbcType t = libodbc.NativeToOdbcType ( (OdbcCType) dt);
+ OdbcColumn c=new OdbcColumn(colname, t);
c.AllowDBNull=(Nullable!=0);
c.Digits=DecDigits;
if (c.IsStringType)
@@ -211,7 +212,7 @@ namespace System.Data.Odbc
byte [] tbuff = new byte [length+1];
length = buffer == null ? 0 : length;
- ret=libodbc.SQLGetData (hstmt, (ushort) (ordinal+1), OdbcType.Binary, tbuff, length,
+ ret=libodbc.SQLGetData (hstmt, (ushort) (ordinal+1), OdbcCType.Binary, tbuff, length,
ref outsize);
if (ret == OdbcReturn.NoData)
@@ -472,7 +473,7 @@ namespace System.Data.Odbc
case OdbcType.Decimal:
bufsize=50;
buffer=new byte[bufsize]; // According to sqlext.h, use SQL_CHAR for decimal
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Char, buffer, bufsize, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Char, buffer, bufsize, ref outsize);
byte[] temp = new byte[outsize];
for (int i=0;i<outsize;i++)
temp[i]=buffer[i];
@@ -482,18 +483,18 @@ namespace System.Data.Odbc
break;
case OdbcType.TinyInt:
short short_data=0;
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.TinyInt, ref short_data, 0, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.TinyInt, ref short_data, 0, ref outsize);
DataValue=System.Convert.ToByte(short_data);
break;
case OdbcType.Int:
int int_data=0;
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Int, ref int_data, 0, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Int, ref int_data, 0, ref outsize);
DataValue=int_data;
break;
case OdbcType.SmallInt:
short sint_data=0;
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.SmallInt, ref sint_data, 0, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.SmallInt, ref sint_data, 0, ref outsize);
DataValue=sint_data;
break;
@@ -505,20 +506,20 @@ namespace System.Data.Odbc
case OdbcType.NVarChar:
bufsize=col.MaxLength*2+1; // Unicode is double byte
buffer=new byte[bufsize];
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.NVarChar, buffer, bufsize, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.NVarChar, buffer, bufsize, ref outsize);
if (outsize!=-1)
DataValue=System.Text.Encoding.Unicode.GetString(buffer,0,outsize);
break;
case OdbcType.VarChar:
bufsize=col.MaxLength+1;
buffer=new byte[bufsize]; // According to sqlext.h, use SQL_CHAR for both char and varchar
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Char, buffer, bufsize, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Char, buffer, bufsize, ref outsize);
if (outsize!=-1)
DataValue=System.Text.Encoding.Default.GetString(buffer,0,outsize);
break;
case OdbcType.Real:
float float_data=0;
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Real, ref float_data, 0, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Real, ref float_data, 0, ref outsize);
DataValue=float_data;
break;
case OdbcType.Timestamp:
@@ -527,13 +528,13 @@ namespace System.Data.Odbc
case OdbcType.Time:
OdbcTimestamp ts_data=new OdbcTimestamp();
if (col.OdbcType == OdbcType.Timestamp)
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Timestamp, ref ts_data, 0, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Timestamp, ref ts_data, 0, ref outsize);
else if (col.OdbcType == OdbcType.DateTime)
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.DateTime, ref ts_data, 0, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.DateTime, ref ts_data, 0, ref outsize);
else if (col.OdbcType == OdbcType.Date)
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Date, ref ts_data, 0, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Date, ref ts_data, 0, ref outsize);
else // FIXME: how to get TIME datatype ??
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.DateTime, ref ts_data, 0, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.DateTime, ref ts_data, 0, ref outsize);
if (outsize!=-1) // This means SQL_NULL_DATA
DataValue=new DateTime(ts_data.year,ts_data.month,ts_data.day,ts_data.hour,
ts_data.minute,ts_data.second,Convert.ToInt32(ts_data.fraction));
@@ -549,7 +550,7 @@ namespace System.Data.Odbc
default:
bufsize=255;
buffer=new byte[bufsize];
- ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Char, buffer, bufsize, ref outsize);
+ ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcCType.Char, buffer, bufsize, ref outsize);
DataValue=System.Text.Encoding.Default.GetString(buffer);
break;
}
diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs
index 90f1185eed5..1eb6b412ca1 100644
--- a/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs
+++ b/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs
@@ -36,14 +36,42 @@ using System.Data.Common;
namespace System.Data.Odbc
{
-// From the ODBC documentation:
-//
-// In ODBC 3.x, the identifiers for date, time, and timestamp SQL data types
-// have changed from SQL_DATE, SQL_TIME, and SQL_TIMESTAMP (with instances of
-// #define in the header file of 9, 10, and 11) to SQL_TYPE_DATE, SQL_TYPE_TIME,
-// and SQL_TYPE_TIMESTAMP (with instances of #define in the header file of 91, 92, and 93),
-// respectively.
+ public enum OdbcType
+ {
+ BigInt = 1,
+ Binary = 2,
+ Bit = 3,
+ Char = 4,
+ Date = 0x17,
+ DateTime = 5,
+ Decimal = 6,
+ Double = 8,
+ Image = 9,
+ Int = 10,
+ NChar = 11,
+ NText = 12,
+ Numeric = 7,
+ NVarChar = 13,
+ Real = 14,
+ SmallDateTime = 0x10,
+ SmallInt = 0x11,
+ Text = 0x12,
+ Time = 0x18,
+ Timestamp = 0x13,
+ TinyInt = 20,
+ UniqueIdentifier = 15,
+ VarBinary = 0x15,
+ VarChar = 0x16
+ }
+ // From the ODBC documentation:
+ //
+ // In ODBC 3.x, the identifiers for date, time, and timestamp SQL data types
+ // have changed from SQL_DATE, SQL_TIME, and SQL_TIMESTAMP (with instances of
+ // #define in the header file of 9, 10, and 11) to SQL_TYPE_DATE, SQL_TYPE_TIME,
+ // and SQL_TYPE_TIMESTAMP (with instances of #define in the header file of 91, 92, and 93),
+ // respectively.
+
// Unmapped SQL Types
//
//#define SQL_FLOAT 6
@@ -51,9 +79,13 @@ namespace System.Data.Odbc
//#define SQL_INTERVAL 10
// could map to SmallDateTime?
- public enum OdbcType
- {
- BigInt=-5, // SQL_BIGINT
+ // This internal enum is used as mapping types into database drivers.
+ // This is essentially a map between public OdbcType to C types for
+ // Odbc to call into driver.
+ internal enum OdbcCType // Native Types
+ {
+ SignedBigInt=-25, // SQL_C_SBIGINT
+ BigInt=-5, // SQL_BIGINT
Binary=-2, // SQL_BINARY
Bit=-7, // SQL_BIT
Char=1, // SQL_CHAR
@@ -77,15 +109,7 @@ namespace System.Data.Odbc
UniqueIdentifier=-11, // SQL_GUID
VarBinary=-3, // SQL_VARBINARY
VarChar=12 // SQL_VARCHAR
- }
-
- // This internal enum is used as mapping types into database drivers.
- // This is essentially a map between public OdbcType to C types for
- // Odbc to call into driver.
- internal enum OdbcCType
- {
- SignedBigInt=-25 // SQL_C_SBIGINT
}
-
+
}
diff --git a/mcs/class/System.Data/System.Data.Odbc/libodbc.cs b/mcs/class/System.Data/System.Data.Odbc/libodbc.cs
index e53043061d8..d9f4c5326af 100644
--- a/mcs/class/System.Data/System.Data.Odbc/libodbc.cs
+++ b/mcs/class/System.Data/System.Data.Odbc/libodbc.cs
@@ -149,31 +149,28 @@ namespace System.Data.Odbc
internal static extern OdbcReturn SQLFetch (IntPtr StatementHandle);
[DllImport("odbc32.dll")]
- internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcType TargetType, ref bool TargetPtr, int BufferLen, ref int Len);
+ internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcCType TargetType, ref bool TargetPtr, int BufferLen, ref int Len);
[DllImport("odbc32.dll")]
- internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcType TargetType, ref double TargetPtr, int BufferLen, ref int Len);
-
- [DllImport("odbc32.dll")]
- internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcType TargetType, ref long TargetPtr, int BufferLen, ref int Len);
+ internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcCType TargetType, ref double TargetPtr, int BufferLen, ref int Len);
[DllImport("odbc32.dll")]
internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcCType TargetType, ref long TargetPtr, int BufferLen, ref int Len);
[DllImport("odbc32.dll")]
- internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcType TargetType, ref short TargetPtr, int BufferLen, ref int Len);
+ internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcCType TargetType, ref short TargetPtr, int BufferLen, ref int Len);
[DllImport("odbc32.dll")]
- internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcType TargetType, ref float TargetPtr, int BufferLen, ref int Len);
+ internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcCType TargetType, ref float TargetPtr, int BufferLen, ref int Len);
[DllImport("odbc32.dll")]
- internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcType TargetType, ref OdbcTimestamp TargetPtr, int BufferLen, ref int Len);
+ internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcCType TargetType, ref OdbcTimestamp TargetPtr, int BufferLen, ref int Len);
[DllImport("odbc32.dll")]
- internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcType TargetType, ref int TargetPtr, int BufferLen, ref int Len);
+ internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcCType TargetType, ref int TargetPtr, int BufferLen, ref int Len);
[DllImport("odbc32.dll")]
- internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcType TargetType, byte[] TargetPtr, int BufferLen, ref int Len);
+ internal static extern OdbcReturn SQLGetData (IntPtr StatementHandle, ushort ColumnNumber, OdbcCType TargetType, byte[] TargetPtr, int BufferLen, ref int Len);
[DllImport("odbc32.dll")]
internal static extern OdbcReturn SQLDescribeCol(IntPtr StatementHandle, ushort ColumnNumber, byte[] ColumnName, short BufferLength, ref short NameLength, ref short DataType, ref uint ColumnSize, ref short DecimalDigits, ref short Nullable);
@@ -248,5 +245,65 @@ namespace System.Data.Odbc
[DllImport ("odbc32.dll")]
internal static extern OdbcReturn SQLFreeStmt (IntPtr Handle, SQLFreeStmtOptions option);
+ #region Type Utilities
+ internal static OdbcType NativeToOdbcType (OdbcCType native)
+ {
+ switch (native)
+ {
+ case OdbcCType.SignedBigInt: // SQL_C_SBIGINT
+ return OdbcType.BigInt;
+ case OdbcCType.BigInt: // SQL_BIGINT
+ return OdbcType.BigInt;
+ case OdbcCType.Binary: // SQL_BINARY
+ return OdbcType.Binary;
+ case OdbcCType.Bit: // SQL_BIT
+ return OdbcType.Bit;
+ case OdbcCType.Char: // SQL_CHAR
+ return OdbcType.Char;
+ case OdbcCType.Date: // SQL_TYPE_DATE
+ return OdbcType.Date;
+ case OdbcCType.DateTime: // SQL_DATETIME
+ return OdbcType.DateTime;
+ case OdbcCType.Decimal: // SQL_DECIMAL
+ return OdbcType.Decimal;
+ case OdbcCType.Double: // SQL_DOUBLE
+ return OdbcType.Double;
+ case OdbcCType.Image: // SQL_LONGVARBINARY
+ return OdbcType.Image;
+ case OdbcCType.Int: // SQL_INTEGER
+ return OdbcType.Int;
+ case OdbcCType.NChar: // SQL_UNICODE_CHAR
+ return OdbcType.NChar;
+ case OdbcCType.NText: // SQL_UNICODE_LONGVARCHAR
+ return OdbcType.NText;
+ case OdbcCType.Numeric: // SQL_NUMERIC
+ return OdbcType.Numeric;
+ case OdbcCType.NVarChar: // SQL_UNICODE_VARCHAR
+ return OdbcType.NVarChar;
+ case OdbcCType.Real: // SQL_REAL
+ return OdbcType.Real;
+ case OdbcCType.SmallDateTime: // ??????????????????????????
+ return OdbcType.SmallDateTime;
+ case OdbcCType.SmallInt: // SQL_SMALLINT
+ return OdbcType.SmallInt;
+ case OdbcCType.Time: // SQL_TYPE_TIME
+ return OdbcType.Time;
+ case OdbcCType.Text: // SQL_LONGVARCHAR
+ return OdbcType.Text;
+ case OdbcCType.Timestamp: // SQL_TYPE_TIMESTAMP
+ return OdbcType.Timestamp;
+ case OdbcCType.TinyInt: // SQL_TINYINT
+ return OdbcType.TinyInt;
+ case OdbcCType.UniqueIdentifier: // SQL_GUID
+ return OdbcType.UniqueIdentifier;
+ case OdbcCType.VarBinary: // SQL_VARBINARY
+ return OdbcType.VarBinary;
+ case OdbcCType.VarChar: // SQL_VARCHAR
+ return OdbcType.VarChar;
+ }
+ throw new ArgumentException ("Invalid Native Type");
+ }
+ #endregion // Type Utilities
+
}
}