The TdDataReader class is a forward-only result set with Base Class Library (BCL) and Provider Specific accessor methods. Data Source agnostic .NET applications utilize accessor methods in System.Data.Common.DbDataReader class which is the base class for the TdDataReader class. The DbDataReader accessor methods return BCL types, for example System.Int32, System.DateTime and System.String. The Provider Specific accessor methods return types unique to the .NET Data Provider for Teradata.
The following tables shows the Advanced SQL Engine data type and the corresponding TdDataReader accessor methods. The TdDataReader class implements the DbDataReader methods that are listed in the "TdDataReader BCL Accessor Methods" column in addition to the Provider Specific accessor methods. The first value listed in the BCL Type column corresponds to the Type returned by GetFieldType method. The first value listed in the Provider specific Type column corresponds to the Type returned by GetProviderSpecificFieldType method.
In addition, the generic method GetFieldValue<T> may be used with any BCL or Provider Specific type [T] to return the value as that type.
Note |
---|
The Data Provider returns a BCL Type if it does not have a Provider Specific Type. For example GetProviderSpecificValue method returns a boxed System.Int32 because the Data Provider does not have an Integer Provider Specific Type. |
Note |
---|
The Data Provider can convert most of the SQL types to Sytem.String data type. For example it can convert a SQL Timestamp data type to System.String. |
Note |
---|
TdDataReader class does not have accessor methods for User Defined Types (UDT), User Defined Array Types and Geospatial Types. The SQL Engine transforms the aforementioned types to and from predefined SQL types. |
Note |
---|
The data of a Number column may get rounded to 15 digits if TdDataReader.GetDouble is called to retrieve the data. The reason for this is that a System.Double has a precision of 15 digits. A Teradata Number type can have a precision of up to 38 digits. To retrieve the Number in its entirety, use TdDataReader.GetTdNumber. |
The following example shows how to retrieve the BCL and Provider Specific type declaration.
C# |
Copy Code |
---|---|
using (TdConnection cn = new TdConnection("data source=x;UserId=y;Password=z;")) { cn.Open(); TdCommand cmd = cn.CreateCommand(); cmd.CommandText = "SELECT " + "CAST('col #1' as Char(10)) as colChar, 'col #2' as colVarChar, " + "CAST('col #3' as Clob(1000)) as colClob," + "'c1c0'XBF as colByte, 'c1c1'XBV as colVarByte, CAST('c1c2'XBF as Blob(1000)) as colBlob," + "'1'XI1 as colByteInt, '2'XI2 as colSmallInt, '3'XI4 as colInteger, '4'XI8 as colBigInt," + "38.20 as colDecimal, 1E10 as colDouble," + "DATE'2011-01-01' as colDate, Time'15:30:00' as colTime, " + "TIME'10:37:12-08:00' as colTimeWithTimeZone, Timestamp'2006-11-23 15:30:23' as colTimestamp," + "TIMESTAMP '2002-01-01 10:37:12-08:00' as colTimestampWithTimeZone, " + "INTERVAL -'2' YEAR as colIntervalYear, INTERVAL '2-06' YEAR TO MONTH as colIntervalYearToMonth," + "INTERVAL '6' MONTH as colIntervalMonth, INTERVAL -'30' DAY as colIntervalDay, " + "INTERVAL '1 12' DAY TO HOUR as colIntervalDayToHour, " + "INTERVAL '30 12:30' DAY TO MINUTE as colIntervalDayToMinute, " + "INTERVAL '30 12:30:30.5' DAY TO SECOND as colIntervalDayToSecond, " + "INTERVAL '2000' HOUR as colIntervalHour, " + "INTERVAL '12:37' HOUR TO MINUTE as colIntervalHourToMinute, " + "INTERVAL '12:37:12.123456' HOUR TO SECOND as colIntervalHourToSecond," + "INTERVAL '600' MINUTE as colIntervalMinute, " + "INTERVAL '9:30' MINUTE TO SECOND as colIntervalMinuteToSecond, " + "INTERVAL '0.000001' SECOND as colIntervalSecond," + "PERIOD '(2005-02-03, 2006-02-04)' as colPeriodDate, " + "PERIOD '(08:00:00, 15:40:00)' as colPeriodTime, " + "PERIOD '(08:00:00-08:00, 15:40:00-05:00)' as colPeriodTimeWithTimeZone, " + "PERIOD'(2011-01-01 10:00:00, 2011-02-01 00:00:00)' as colPeriodTimestamp, " + "PERIOD'(2011-01-01 10:00:00-08:00, 2011-02-01 00:00:00-08:00)' as colPeriodTimestampWithTimeZone"; using (TdDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { Console.WriteLine("{0,-35} {1,-30} {2}\n\r", @"Column Name", @"BCL Type", @"Provider Specific Type"); for (Int32 ordinal = 0; ordinal < reader.FieldCount; ordinal++) { Console.WriteLine("{0,-35} {1,-30} {2}", reader.GetName(ordinal), reader.GetFieldType(ordinal), reader.GetProviderSpecificFieldType(ordinal) ); } } } } /* Column Name BCL Type Provider Specific Type colChar System.String System.String colVarChar System.String System.String colClob System.String Teradata.Client.Provider.TdClob colByte System.Byte[] System.Byte[] colVarByte System.Byte[] System.Byte[] colBlob System.Byte[] Teradata.Client.Provider.TdBlob colByteInt System.Int16 System.Int16 colSmallInt System.Int16 System.Int16 colInteger System.Int32 System.Int32 colBigInt System.Int64 System.Int64 colDecimal System.Decimal Teradata.Client.Provider.TdDecimal colDouble System.Double System.Double colDate System.DateTime Teradata.Client.Provider.TdDate colTime System.TimeSpan Teradata.Client.Provider.TdTime colTimeWithTimeZone System.String Teradata.Client.Provider.TdTimeWithTimeZone colTimestamp System.DateTime Teradata.Client.Provider.TdTimestamp colTimestampWithTimeZone System.DateTimeOffset Teradata.Client.Provider.TdTimestampWithTimeZone colIntervalYear System.String Teradata.Client.Provider.TdIntervalYear colIntervalYearToMonth System.String Teradata.Client.Provider.TdIntervalYearToMonth colIntervalMonth System.String Teradata.Client.Provider.TdIntervalMonth colIntervalDay System.TimeSpan Teradata.Client.Provider.TdIntervalDay colIntervalDayToHour System.TimeSpan Teradata.Client.Provider.TdIntervalDayToHour colIntervalDayToMinute System.TimeSpan Teradata.Client.Provider.TdIntervalDayToMinute colIntervalDayToSecond System.TimeSpan Teradata.Client.Provider.TdIntervalDayToSecond colIntervalHour System.TimeSpan Teradata.Client.Provider.TdIntervalHour colIntervalHourToMinute System.TimeSpan Teradata.Client.Provider.TdIntervalHourToMinute colIntervalHourToSecond System.TimeSpan Teradata.Client.Provider.TdIntervalHourToSecond colIntervalMinute System.TimeSpan Teradata.Client.Provider.TdIntervalMinute colIntervalMinuteToSecond System.TimeSpan Teradata.Client.Provider.TdIntervalMinuteToSecond colIntervalSecond System.TimeSpan Teradata.Client.Provider.TdIntervalSecond colPeriodDate System.String Teradata.Client.Provider.TdPeriodDate colPeriodTime System.String Teradata.Client.Provider.TdPeriodTime colPeriodTimeWithTimeZone System.String Teradata.Client.Provider.TdPeriodTimeWithTimeZone colPeriodTimestamp System.String Teradata.Client.Provider.TdPeriodTimestamp colPeriodTimestampWithTimeZone System.String Teradata.Client.Provider.TdPeriodTimestampWithTimeZone */ |